Commits

Ruslan Osmanov committed 7af1771

Fix: segfault on var_dump for classes without props
Some memory usage fixes
Del: EventBufferEvent::ref method
Fix: samples

Comments (0)

Files changed (8)

 /* }}} */
 #endif
 
+/* {{{ proto bool EventBase::reInit(void);
+ * Re-initialize event base. Should be called after a fork.
+ * XXX pthread_atfork() in MINIT */
+PHP_METHOD(EventBase, reInit)
+{
+	zval             *zbase = getThis();
+	php_event_base_t *b;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	PHP_EVENT_FETCH_BASE(b, zbase);
+
+	if (event_reinit(b->base)) {
+		RETURN_TRUE;
+	}
+
+	RETVAL_FALSE;
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4

classes/buffer_event.c

 
 		if (bev->self) {
 			args[0] = &bev->self;
-			Z_ADDREF_P(bev->self);
+			/*Z_ADDREF_P(bev->self);*/
 		}
 		if (arg_data) {
 			Z_ADDREF_P(arg_data);
 	if (ZEND_FCI_INITIALIZED(*pfci)) {
 		/* Setup callback args */
 		args[0] = &bev->self;
-		Z_ADDREF_P(bev->self);
+		/*Z_ADDREF_P(bev->self);*/
 
 		MAKE_STD_ZVAL(arg_events);
 		ZVAL_LONG(arg_events, events);
 	}
 
 	bev->self = zself;
-}
-/* }}} */
-
-/* {{{ proto void EventBufferEvent::ref(void); */
-PHP_METHOD(EventBufferEvent, ref)
-{
-	Z_ADDREF_P(getThis());
+	Z_ADDREF_P(zself);
 }
 /* }}} */
 
 /* }}} */
 
 /* {{{ proto bool EventBufferEvent::setPriority(int priority);
- * XXX make a property?
  * Assign a priority to a bufferevent.
  * Only supported for socket bufferevents. */
 PHP_METHOD(EventBufferEvent, setPriority)
 }
 /* }}} */
 
+/* {{{ proto void Event::free(void); */
+PHP_METHOD(Event, free)
+{
+	zval        *zself = getThis();
+	php_event_t *e;
+
+	PHP_EVENT_FETCH_EVENT(e, zself);
+
+	event_del(e->event);
+	event_free(e->event);
+	e->event = NULL;
+
+	zval_ptr_dtor(&zself);
+}
+/* }}} */
+
 /* {{{ proto bool Event::set(EventBase base, mixed fd,[ int what = NULL[, callable cb = NULL[, zval arg = NULL]]]);
  *
  * Re-configures event.
 /* }}} */
 
 /* {{{ proto bool Event::pending(int flags);
- *  Detect whether event is pending or scheduled.
- *  XXX move to properties */
+ *  Detect whether event is pending or scheduled. */
 PHP_METHOD(Event, pending)
 {
 	zval        *zevent = getThis();
 }
 /* }}} */
 
-/* {{{ proto bool Event::reInit(EventBase base);
- * Re-initialize event base. Should be called after a fork.
- * XXX pthread_atfork() in MINIT */
-PHP_METHOD(Event, reInit)
-{
-	zval             *zbase;
-	php_event_base_t *b;
-
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
-				&zbase, php_event_base_ce) == FAILURE) {
-		return;
-	}
-
-	PHP_EVENT_FETCH_BASE(b, zbase);
-
-	if (event_reinit(b->base)) {
-		RETURN_TRUE;
-	}
-	RETVAL_FALSE;
-}
-/* }}} */
-
 
 /* {{{ proto Event Event::timer(EventBase base, callable cb[, zval arg = NULL]);
  * Factory method for timer event */

examples/listener.php

 
     $bev->enable(Event::READ | Event::WRITE);
 
-	$bev->ref();
+	//$bev->ref();
 }
 
 function accept_error_cb($listener, $ctx) {
 	if (b) {
 		if (b->data) {
 			zval_ptr_dtor(&b->data);
+			b->data = NULL;
 		}
 
 		PHP_EVENT_FREE_FCALL_INFO(b->fci_read,  b->fcc_read);
 			zend_list_delete(b->stream_id);
 		}
 
+#if 0
 		if (b->self) {
 			zval_ptr_dtor(&b->self);
+			b->self = NULL;
 		}
+#endif
 
 		if (b->bevent) {
 			bufferevent_free(b->bevent);
+			b->bevent = NULL;
 		}
-
-		event_generic_object_free_storage(ptr TSRMLS_CC);
 	}
+
+	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 /* }}} */
 
 		zval_ptr_dtor(&l->data);
 	}
 
+#if 0
 	if (l->self) {
 		zval_ptr_dtor(&l->self);
+		l->self = NULL;
 	}
+#endif
 
 	PHP_EVENT_FREE_FCALL_INFO(l->fci, l->fcc);
 	PHP_EVENT_FREE_FCALL_INFO(l->fci_err, l->fcc_err);
 
 	ALLOC_HASHTABLE(retval);
 
+	if (!props) {
+		ZEND_INIT_SYMTABLE_EX(retval, 1, 0);
+		return retval;
+	}
+
 	ZEND_INIT_SYMTABLE_EX(retval, zend_hash_num_elements(props) + 1, 0);
 
 	zend_hash_internal_pointer_reset_ex(props, &pos);
 
 const zend_function_entry php_event_ce_functions[] = {/* {{{ */
 	PHP_ME(Event, __construct,         arginfo_event__construct,   ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
+	PHP_ME(Event, free,                arginfo_event__void,        ZEND_ACC_PUBLIC)
 	PHP_ME(Event, set,                 arginfo_event_set,          ZEND_ACC_PUBLIC)
 	PHP_ME(Event, getSupportedMethods, arginfo_event__void,        ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
 	PHP_ME(Event, add,                 arginfo_event_add,          ZEND_ACC_PUBLIC)
 	PHP_ME(Event, del,                 arginfo_event__void,        ZEND_ACC_PUBLIC)
 	PHP_ME(Event, setPriority,         arginfo_event_priority_set, ZEND_ACC_PUBLIC)
 	PHP_ME(Event, pending,             arginfo_event_pending,      ZEND_ACC_PUBLIC)
-	PHP_ME(Event, reInit,              arginfo_event_reinit,       ZEND_ACC_PUBLIC)
 #if LIBEVENT_VERSION_NUMBER >= 0x02010200
 	PHP_ME(Event, removeTimer, arginfo_event__void, ZEND_ACC_PUBLIC)
 #endif
 	PHP_ME(EventBase, gotStop,            arginfo_event__void,              ZEND_ACC_PUBLIC)
 	PHP_ME(EventBase, gotExit,            arginfo_event__void,              ZEND_ACC_PUBLIC)
 	PHP_ME(EventBase, getTimeOfDayCached, arginfo_event__void,              ZEND_ACC_PUBLIC)
+	PHP_ME(EventBase, reInit,             arginfo_event_reinit,             ZEND_ACC_PUBLIC)
 #if LIBEVENT_VERSION_NUMBER >= 0x02010100
 	PHP_ME(EventBase, updateCacheTime, arginfo_event__void, ZEND_ACC_PUBLIC)
 #endif
 const zend_function_entry php_event_bevent_ce_functions[] = {/* {{{ */
 	PHP_ME(EventBufferEvent, __construct,       arginfo_bufferevent__construct,              ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
 	PHP_ME(EventBufferEvent, free,              arginfo_event__void,                         ZEND_ACC_PUBLIC)
-	PHP_ME(EventBufferEvent, ref,               arginfo_event__void,                         ZEND_ACC_PUBLIC)
 	PHP_ME(EventBufferEvent, connect,           arginfo_bufferevent_connect,                 ZEND_ACC_PUBLIC)
 	PHP_ME(EventBufferEvent, connectHost,       arginfo_bufferevent_socket_connect_hostname, ZEND_ACC_PUBLIC)
 	PHP_ME(EventBufferEvent, getDnsErrorString, arginfo_event__void,                         ZEND_ACC_PUBLIC)
 #include "common.h"
 
 PHP_METHOD(Event, __construct);
+PHP_METHOD(Event, free);
 PHP_METHOD(Event, set);
 PHP_METHOD(Event, add);
 PHP_METHOD(Event, del);
 PHP_METHOD(Event, removeTimer);
 PHP_METHOD(Event, setPriority);
 PHP_METHOD(Event, pending);
-PHP_METHOD(Event, reInit);
 PHP_METHOD(Event, getSupportedMethods);
 
 PHP_METHOD(Event, timer);
 #if LIBEVENT_VERSION_NUMBER >= 0x02010100
 PHP_METHOD(EventBase, updateCacheTime);
 #endif
+PHP_METHOD(EventBase, reInit);
 
 PHP_METHOD(EventConfig, __construct);
 PHP_METHOD(EventConfig, avoidMethod);
 
 PHP_METHOD(EventBufferEvent, __construct);
 PHP_METHOD(EventBufferEvent, free);
-PHP_METHOD(EventBufferEvent, ref);
 PHP_METHOD(EventBufferEvent, createPair);
 PHP_METHOD(EventBufferEvent, connect);
 PHP_METHOD(EventBufferEvent, connectHost);

tests/04-bevent-socket.phpt

 }, "data");
 
 $base->dispatch();
+
+$bev->free();
 ?>
 --EXPECT--
 Connected