Ruslan Osmanov avatar Ruslan Osmanov committed 3d227f7

Fallback to zend_objects_destroy_object

Comments (0)

Files changed (6)

 		e->event = NULL;
 	}
 
-	zval_ptr_dtor(&zself);
+	/*zval_ptr_dtor(&zself);*/
 }
 /* }}} */
 

examples/listener.php

  */
 
 function echo_read_cb($bev, $ctx) {
-    /* This callback is invoked when there is data to read on $bev. */
-    $input  = $bev->getInput();
-    $output = $bev->getOutput();
+	/* This callback is invoked when there is data to read on $bev. */
+	$input	= $bev->getInput();
+	$output = $bev->getOutput();
 
-    /* Copy all the data from the input buffer to the output buffer. */
-    EventBuffer::addBuffer($output, $input);
+	/* Copy all the data from the input buffer to the output buffer. */
+	EventBuffer::addBuffer($output, $input);
 }
 
 function echo_event_cb($bev, $events, $ctx) {
-    if ($events & EventBufferEvent::ERROR)
-        echo "Error from bufferevent\n";
+	if ($events & EventBufferEvent::ERROR)
+		echo "Error from bufferevent\n";
 
-    if ($events & (EventBufferEvent::EOF | EventBufferEvent::ERROR)) {
-        $bev->free();
-    }
+	if ($events & (EventBufferEvent::EOF | EventBufferEvent::ERROR)) {
+		$bev->free();
+	}
 }
 
 function accept_conn_cb($listener, $fd, $address, $ctx) {
-    /* We got a new connection! Set up a bufferevent for it. */
-    $base = $ctx;
-    //$base = $listener->getBase();
+	/* We got a new connection! Set up a bufferevent for it. */
+	$base = $ctx;
+	//$base = $listener->getBase();
 
-    $bev = new EventBufferEvent($base, $fd, EventBufferEvent::OPT_CLOSE_ON_FREE);
+	$bev = new EventBufferEvent($base, $fd, EventBufferEvent::OPT_CLOSE_ON_FREE);
 
-    $bev->setCallbacks("echo_read_cb", NULL, "echo_event_cb", NULL);
+	$bev->setCallbacks("echo_read_cb", NULL, "echo_event_cb", NULL);
 
-    $bev->enable(Event::READ | Event::WRITE);
+	$bev->enable(Event::READ | Event::WRITE);
 
 	//$bev->ref();
 }
 
 function accept_error_cb($listener, $ctx) {
-    $base = $listener->getBase();
+	$base = $listener->getBase();
 
-    fprintf(STDERR, "Got an error %d (%s) on the listener. "
-        ."Shutting down.\n",
+	fprintf(STDERR, "Got an error %d (%s) on the listener. "
+		."Shutting down.\n",
 		EventUtil::getLastSocketErrno(),
 		EventUtil::getLastSocketError());
 
-    $base->exit(NULL);
+	$base->exit(NULL);
 }
 
 $port = 9808;
 
 if ($argc > 1) {
-    $port = (int) $argv[1];
+	$port = (int) $argv[1];
 }
 if ($port <= 0 || $port > 65535) {
-    puts("Invalid port");
-    return 1;
+	puts("Invalid port");
+	return 1;
 }
 
 $base = new EventBase();
 if (!$base) {
-    echo "Couldn't open event base";
+	echo "Couldn't open event base";
 	exit(1);
 }
 
 	exit(1);
 }
 $listener = new EventListener($base, "accept_conn_cb", $base,
-    EventListener::OPT_CLOSE_ON_FREE | EventListener::OPT_REUSEABLE, -1, $socket);
+	EventListener::OPT_CLOSE_ON_FREE | EventListener::OPT_REUSEABLE, -1, $socket);
 
 /* Variant #2 */
 /*
  */
 
 if (!$listener) {
-    echo "Couldn't create listener";
+	echo "Couldn't create listener";
 	exit(1);
 }
 $listener->setErrorCallback("accept_error_cb");
 
 /* {{{ Private functions */
 
-/* {{{ event_bevent_object_dtor
- * Required to cleanup bufferevent properly */
-static void event_bevent_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_bevent_t *b = (php_event_bevent_t *) ptr;
-
-	PHP_EVENT_ASSERT(b);
-
-	if (b->bevent) {
-		bufferevent_free(b->bevent);
-		b->bevent = NULL;
-	}
-
-	PHP_EVENT_FREE_FCALL_INFO(b->fci_read,  b->fcc_read);
-	PHP_EVENT_FREE_FCALL_INFO(b->fci_write, b->fcc_write);
-	PHP_EVENT_FREE_FCALL_INFO(b->fci_event, b->fcc_event);
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ event_object_dtor
- * Required to cleanup event properly */
-static void event_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_t *e = (php_event_t *) ptr;
-
-	if (e->event) {
-		event_del(e->event);
-		event_free(e->event);
-		e->event = NULL;
-	}
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ event_base_object_dtor
- * Required to cleanup event base properly */
-static void event_base_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_base_t *b = (php_event_base_t *) ptr;
-
-	if (!b->internal && b->base) {
-		/* TODO: what if events bound to the event_base are not destroyed? */
-		event_base_free(b->base);
-		b->base = NULL;
-	}
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ event_config_object_dtor
- * Required to cleanup event config properly */
-static void event_config_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_config_t *cfg = (php_event_config_t *) ptr;
-
-	if (cfg && cfg->ptr) {
-		event_config_free(cfg->ptr);
-		cfg->ptr = NULL;
-	}
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ event_buffer_object_dtor
- * Required to cleanup buffer properly */
-static void event_buffer_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_buffer_t *b = (php_event_buffer_t *) ptr;
-
-	/* If we got the buffer in, say, a read callback the buffer
-	 * is destroyed when the callback is done as any normal variable.
-	 * Zend MM calls destructor which eventually calls this function.
-	 * We'll definitely crash, if we call evbuffer_free() on an internal
-	 * bufferevent buffer. */
-
-	if (!b->internal && b->buf) {
-		evbuffer_free(b->buf);
-		b->buf = NULL;
-	}
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ event_dns_base_object_dtor
- * Required to cleanup buffer properly */
-static void event_dns_base_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_dns_base_t *dnsb = (php_event_dns_base_t *) ptr;
-
-	if (dnsb && dnsb->dns_base) {
-		/* Setting fail_requests to 1 makes all in-flight requests get
-	 	 * their callbacks invoked with a canceled error code before it
-	 	 * frees the base*/
-		evdns_base_free(dnsb->dns_base, 1);
-		dnsb->dns_base = NULL;
-	}
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ event_listener_object_dtor
- * Required to cleanup buffer properly */
-static void event_listener_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_listener_t *l = (php_event_listener_t *) ptr;
-
-	if (l && l->listener) {
-		evconnlistener_free(l->listener);
-		l->listener = NULL;
-	}
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ event_http_conn_object_dtor
- * Required to cleanup http conn obj properly */
-static void event_http_conn_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_http_conn_t *evcon = (php_event_http_conn_t *) ptr;
-
-	if (evcon && evcon->conn) {
-		evhttp_connection_free(evcon->conn);
-		evcon->conn = NULL;
-	}
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ event_http_object_dtor
- * Required to cleanup http obj properly */
-static void event_http_object_dtor(void *ptr, zend_object_handle handle TSRMLS_DC)
-{
-	php_event_http_t *http = (php_event_http_t *) ptr;
-
-	if (http && http->ptr) {
-		evhttp_free(http->ptr);
-	}
-
-	zend_objects_destroy_object(ptr, handle TSRMLS_CC);
-}
-/* }}} */
-
 
 /* {{{ event_generic_object_free_storage */
 static zend_always_inline void event_generic_object_free_storage(void *ptr TSRMLS_DC)
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_base_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_base_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_base_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_config_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_config_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_config_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_bevent_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_bevent_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_bevent_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_buffer_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_buffer_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_buffer_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_dns_base_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_dns_base_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_dns_base_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_listener_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_listener_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_listener_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_http_conn_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_http_conn_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_http_conn_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) object_new(ce, sizeof(php_event_http_t) TSRMLS_CC);
 
-	return register_object(ce, (void *) obj, event_http_object_dtor,
+	return register_object(ce, (void *) obj, (zend_objects_store_dtor_t) zend_objects_destroy_object,
 			event_http_object_free_storage TSRMLS_CC);
 }
 /* }}} */
 	PHP_EVENT_REGISTER_CLASS("Event", event_object_create, php_event_ce, php_event_ce_functions);
 	ce = php_event_ce;
 	ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
+	zend_hash_init(&event_properties, 0, NULL, NULL, 1);
+	PHP_EVENT_ADD_CLASS_PROPERTIES(&event_properties, event_property_entries);
+	PHP_EVENT_DECL_CLASS_PROPERTIES(ce, event_property_entry_info);
+	zend_hash_add(&classes, ce->name, ce->name_length + 1, &event_properties, sizeof(event_properties), NULL);
 
 	PHP_EVENT_REGISTER_CLASS("EventBase", event_base_object_create, php_event_base_ce,
 			php_event_base_ce_functions);
 	zend_hash_init(&event_base_properties, 0, NULL, NULL, 1);
 	PHP_EVENT_ADD_CLASS_PROPERTIES(&event_base_properties, event_base_property_entries);
 	PHP_EVENT_DECL_CLASS_PROPERTIES(ce, event_base_property_entry_info);
-	zend_hash_add(&classes, ce->name, ce->name_length + 1, &event_properties, sizeof(event_base_properties), NULL);
+	zend_hash_add(&classes, ce->name, ce->name_length + 1, &event_base_properties, sizeof(event_base_properties), NULL);
 
 	PHP_EVENT_REGISTER_CLASS("EventConfig", event_config_object_create, php_event_config_ce,
 			php_event_config_ce_functions);
 
 	PHP_ME(Event, timer,        arginfo_evtimer_new,  ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
 	PHP_ME(Event, setTimer,     arginfo_evtimer_set,  ZEND_ACC_PUBLIC)
-	PHP_ME(Event, timerPending, arginfo_event__void,  ZEND_ACC_PUBLIC)
 	PHP_ME(Event, signal,       arginfo_evsignal_new, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
 
 	PHP_MALIAS(Event, addTimer,  add, arginfo_event_add,   ZEND_ACC_PUBLIC)
 
 PHP_METHOD(Event, timer);
 PHP_METHOD(Event, setTimer);
-PHP_METHOD(Event, timerPending);
 
 PHP_METHOD(Event, signal);
 

tests/03-event-del.phpt

 $e2 = Event::timer($base, function () { echo "ok 3\n"; });
 $e2->add(0.2);
 
-$e1->timerPending() and print("ok 1\n");
-$e2->timerPending() and print("ok 2\n");
+$e1->timer_pending and print("ok 1\n");
+$e2->timer_pending and print("ok 2\n");
 
 $e1->del();
-$e1->timerPending() and print("not ok 4\n");
+$e1->timer_pending and print("not ok 4\n");
 
 $base->loop(EventBase::LOOP_ONCE);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.