Commits

Ruslan Osmanov committed 4e9addb

Refact: replaced some checks with assert'ions
Fix: build errors

Comments (0)

Files changed (4)

 PHP_METHOD(EventHttp, accept)
 {
 	php_event_http_t  *http;
-	zval              *zhttp;
+	zval              *zhttp = getThis();
 	zval             **ppzfd;
 	evutil_socket_t    fd;
 
 /* Private }}} */
 
 
-/* {{{ proto EventListener EventListener::__construct(EventBase base, callable cb, mixed data, int flags, int backlog, mixed addr);
+/* {{{ proto EventListener EventListener::__construct(EventBase base, callable cb, mixed data, int flags, int backlog, mixed target);
  *
  * Creates new connection listener associated with an event base.
  *
- * addr parameter may be string, socket resource, or a stream associated with a socket.
- * In case if addr is a string, the string will be parsed as network address.
+ * target parameter may be string, socket resource, or a stream associated with a socket.
+ * In case if target is a string, the string will be parsed as network address.
  *
  * Returns resource representing the event connection listener.
  */
 	zend_fcall_info_cache  fcc      = empty_fcall_info_cache;
 	php_event_listener_t  *l;
 	zval                  *zdata    = NULL;
-	zval                  *zaddr;
+	zval                 **ppztarget;
 	long                   flags;
 	long                   backlog;
 	struct evconnlistener *listener;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ofz!llz",
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ofz!llZ",
 				&zbase, php_event_base_ce,
-				&fci, &fcc, &zdata, &flags, &backlog, &zaddr) == FAILURE) {
+				&fci, &fcc, &zdata, &flags, &backlog, &ppztarget) == FAILURE) {
 		return;
 	}
 
 	PHP_EVENT_FETCH_BASE(base, zbase);
 
-	if (Z_TYPE_P(zaddr) == IS_STRING) {
+	if (Z_TYPE_PP(ppztarget) == IS_STRING) {
 		struct sockaddr sa;
 		socklen_t       sa_len = sizeof(struct sockaddr);
 
-		if (php_network_parse_network_address_with_port(Z_STRVAL_P(zaddr), Z_STRLEN_P(zaddr),
+		if (php_network_parse_network_address_with_port(Z_STRVAL_PP(ppztarget), Z_STRLEN_PP(ppztarget),
 					&sa, &sa_len TSRMLS_CC) != SUCCESS) {
 			RETURN_FALSE;
 		}
 			return;
 		}
 		l->listener = listener;
-	} else { /* zaddr is not string */
-		zval            **ppzfd;
+	} else { /* ppztarget is not string */
 		evutil_socket_t   fd    = -1;
 
 		/* php_event_zval_to_fd reports error
 	 	 * in case if it is not a valid socket resource */
-		fd = php_event_zval_to_fd(ppzfd TSRMLS_CC);
+		fd = php_event_zval_to_fd(ppztarget TSRMLS_CC);
 		if (fd < 0) {
 			return;
 		}
 		 * thus producing new file descriptor. The new descriptor is available
 		 * in _php_event_listener_cb() callback. */
 
-		if (Z_TYPE_PP(ppzfd) == IS_RESOURCE) {
-			/* lval of ppzfd is the resource ID */
-			l->stream_id = Z_LVAL_PP(ppzfd);
-			zend_list_addref(Z_LVAL_PP(ppzfd));
+		if (Z_TYPE_PP(ppztarget) == IS_RESOURCE) {
+			/* lval of ppztarget is the resource ID */
+			l->stream_id = Z_LVAL_PP(ppztarget);
+			zend_list_addref(Z_LVAL_PP(ppztarget));
 		} else {
 			l->stream_id = -1;
 		}
 #endif
 
 
-
 /* {{{ Private functions */
 
 /* {{{ 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 *) ptr;
-	
+	php_event_abstract_object_t *obj = (php_event_abstract_object_t *) ptr;
+
 	zend_object_std_dtor(&obj->zo TSRMLS_CC);
 
 	efree(obj);
 {
 	php_event_t *e = (php_event_t *) ptr;
 
+	PHP_EVENT_ASSERT(e && e->event);
+
 	if (e->data) {
-		zval_ptr_dtor(&e->data);
+		/*zval_ptr_dtor(&e->data);*/
+		Z_DELREF_P(e->data);
 	}
 
 	PHP_EVENT_FREE_FCALL_INFO(e->fci, e->fcc);
 {
 	php_event_base_t *b = (php_event_base_t *) ptr;
 
+	PHP_EVENT_ASSERT(b && b->base);
+
 	/* TODO: what if events bound to the event_base are not destroyed? */
-	if (b && b->base) {
-		event_base_free(b->base);
-	}
+	event_base_free(b->base);
 
 	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 {
 	php_event_config_t *cfg = (php_event_config_t *) ptr;
 
-	if (cfg && cfg->ptr) {
-		event_config_free(cfg->ptr);
-	}
+	PHP_EVENT_ASSERT(cfg && cfg->ptr);
+
+	event_config_free(cfg->ptr);
 
 	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 {
 	php_event_bevent_t *b = (php_event_bevent_t *) ptr;
 
-	if (b && b->bevent) {
-		if (b->data) {
-			/*zval_ptr_dtor(&b->data);*/
-			Z_DELREF_P(b->data);
-		}
+	PHP_EVENT_ASSERT(b && b->bevent);
 
-		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);
+	if (b->data) {
+		/*zval_ptr_dtor(&b->data);*/
+		Z_DELREF_P(b->data);
+	}
 
-		if (b->stream_id >= 0) { /* stdin fd == 0 */
-			zend_list_delete(b->stream_id);
-		}
+	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);
 
-		if (b->self) {
-			Z_DELREF_P(b->self);
-		}
+	if (b->stream_id >= 0) { /* stdin fd == 0 */
+		zend_list_delete(b->stream_id);
+	}
 
-		bufferevent_free(b->bevent);
+	if (b->self) {
+		Z_DELREF_P(b->self);
 	}
 
+	bufferevent_free(b->bevent);
+
 	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_buffer_t *b = (php_event_buffer_t *) ptr;
 
-	if (b && b->buf) {
-		evbuffer_free(b->buf);
-	}
+	PHP_EVENT_ASSERT(b && b->buf);
+
+	evbuffer_free(b->buf);
 
 	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 {
 	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);
-	}
+	PHP_EVENT_ASSERT(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);
 
 	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 {
 	php_event_listener_t *l = (php_event_listener_t *) ptr;
 
-	if (l && l->listener) {
-		if (l->stream_id >= 0) {
-			zend_list_delete(l->stream_id);
-		}
+	PHP_EVENT_ASSERT(l && l->listener);
+	if (l->stream_id >= 0) {
+		zend_list_delete(l->stream_id);
+	}
 
-		if (l->base) {
-			Z_DELREF_P(l->base);
-		}
+	if (l->base) {
+		Z_DELREF_P(l->base);
+	}
 
-		if (l->data) {
-			Z_DELREF_P(l->data);
-		}
+	if (l->data) {
+		Z_DELREF_P(l->data);
+	}
 
-		if (l->self) {
-			Z_DELREF_P(l->self);
-		}
+	if (l->self) {
+		Z_DELREF_P(l->self);
+	}
 
-		PHP_EVENT_FREE_FCALL_INFO(l->fci, l->fcc);
-		PHP_EVENT_FREE_FCALL_INFO(l->fci_err, l->fcc_err);
+	PHP_EVENT_FREE_FCALL_INFO(l->fci, l->fcc);
+	PHP_EVENT_FREE_FCALL_INFO(l->fci_err, l->fcc_err);
 
-		evconnlistener_free(l->listener);
-	}
+	evconnlistener_free(l->listener);
 
 	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 {
 	php_event_http_conn_t *evcon = (php_event_http_conn_t *) ptr;
 
-	if (evcon && evcon->conn) {
-		if (evcon->base) {
-			Z_DELREF_P(evcon->base);
-		}
+	PHP_EVENT_ASSERT(evcon && evcon->conn);
 
-		if (evcon->dns_base) {
-			Z_DELREF_P(evcon->dns_base);
-		}
+	if (evcon->base) {
+		Z_DELREF_P(evcon->base);
+	}
 
-		evhttp_connection_free(evcon->conn);
+	if (evcon->dns_base) {
+		Z_DELREF_P(evcon->dns_base);
 	}
 
+	evhttp_connection_free(evcon->conn);
+
 	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 /* }}} */
 {
 	php_event_http_t *http = (php_event_http_t *) ptr;
 
-	if (http && http->ptr) {
-		if (http->base) {
-			Z_DELREF_P(http->base);
-		}
+	PHP_EVENT_ASSERT(http && http->ptr);
 
-		evhttp_free(http->ptr);
+	if (http->base) {
+		Z_DELREF_P(http->base);
 	}
 
+	evhttp_free(http->ptr);
+
 	event_generic_object_free_storage(ptr TSRMLS_CC);
 }
 /* }}} */
 /* Private functions }}} */
 
 
-
 #define PHP_EVENT_REG_CONST_LONG(name, real_name) \
     REGISTER_LONG_CONSTANT(#name, real_name, CONST_CS | CONST_PERSISTENT);
 
 	PHP_EVENT_OBJECT_HEAD;
 } php_event_abstract_object_t; 
 
-/* Represents an event object */
+/* Represents Event object */
 typedef struct {
 	PHP_EVENT_OBJECT_HEAD;
 
 	struct event          *event;       /* Pointer returned by event_new                        */
-	int                    stream_id;   /* Resource ID of the file descriptor, or signal number */
+	int                    stream_id;   /* Resource ID of the file descriptor. -1 if none */
 	zval                  *data;        /* User custom data                                     */
 	/* fci and fcc represent userspace callback */
 	zend_fcall_info       *fci;
 	PHP_EVENT_COMMON_THREAD_CTX;
 } php_event_t;
 
-/* Represents a bufferevent */
+/* Represents EventBase object */
 typedef struct {
+	PHP_EVENT_OBJECT_HEAD;
+
+	struct event_base *base;
+} php_event_base_t;
+
+/* Represents EventConfig object */
+typedef struct {
+	PHP_EVENT_OBJECT_HEAD;
+
+	struct event_config *ptr;
+} php_event_config_t;
+
+/* Represents EventBufferEvent object */
+typedef struct {
+	PHP_EVENT_OBJECT_HEAD;
+
 	struct bufferevent    *bevent;
-	int                    stream_id;   /* Resource ID of the file descriptor */
+	int                    stream_id;   /* Resource ID of the file descriptor. -1 if none */
 	zval                  *self;        /* Object itself. For callbacks       */
 	zval                  *data;        /* User custom data                   */
 
 	PHP_EVENT_COMMON_THREAD_CTX;
 } php_event_bevent_t;
 
+/* Represents EventBuffer object */
 typedef struct {
+	PHP_EVENT_OBJECT_HEAD;
+
 	struct evbuffer *buf;
 } php_event_buffer_t;
 
 #ifdef HAVE_EVENT_EXTRA_LIB/* {{{ */
 
+/* Represents EventDnsBase object */
 typedef struct {
+	PHP_EVENT_OBJECT_HEAD;
+
 	struct evdns_base *dns_base;
 } php_event_dns_base_t;
 
+/* Represents EventListener object */
 typedef struct {
+	PHP_EVENT_OBJECT_HEAD;
+
 	struct evconnlistener *listener;
-	int                    stream_id;   /* Resource ID of the socket file descriptor */
+	int                    stream_id;   /* Resource ID of the file descriptor. -1 if none */
 	zval                  *self;        /* Object itself. For callbacks              */
 	zval                  *base;        /* Event base associated with the listener   */
 	zval                  *data;        /* User custom data passed to callback       */
+
 	/* Accept callback */
 	zend_fcall_info       *fci;
 	zend_fcall_info_cache *fcc;
+
 	/* Error callback */
 	zend_fcall_info       *fci_err;
 	zend_fcall_info_cache *fcc_err;
 	PHP_EVENT_COMMON_THREAD_CTX;
 } php_event_listener_t;
 
+/* Represents EventHttpConnection object */
 typedef struct {
+	PHP_EVENT_OBJECT_HEAD;
+
 	struct evhttp_connection *conn;
 	zval                     *base;       /* Event base associated with the listener */
 	zval                     *dns_base;   /* Associated EventDnsBase                 */
 } php_event_http_conn_t;
 
+/* Represents EventHttp object */
 typedef struct {
+	PHP_EVENT_OBJECT_HEAD;
+
 	struct evhttp *ptr;
 	zval          *base;        /* Event base associated with the listener       */
 	int            stream_id;   /* Resource ID of socket probably being listened */
 
 #endif/* HAVE_EVENT_EXTRA_LIB }}} */
 
-typedef struct {
-	struct event_base *base;
-} php_event_base_t;
-
-typedef struct {
-	struct event_config *ptr;
-} php_event_config_t;
-
 typedef double php_event_timestamp_t;
 
 typedef int (*php_event_prop_read_t)(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC);
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.