Commits

Ruslan Osmanov committed f7ec13e

Refact: move Z_ADDREF_P(self) from callbacks to __construct and factory methods of EventBufferEvent and EventListener

Comments (0)

Files changed (2)

classes/buffer_event.c

 
 		if (bev->self) {
 			args[0] = &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);
 
 		MAKE_STD_ZVAL(arg_events);
 		ZVAL_LONG(arg_events, events);
 	}
 
 	bev->self = zself;
+	Z_ADDREF_P(zself);
+
 	bev->input = bev->output = NULL;
-	/* Don't ensure the object won't be destroyed in case if we are in a callback
-	 * User should keep variable somewhere if he/she wants to prevent auto-destruction
-	 * within a callback.
-	 * Z_ADDREF_P(zself);
-	 */
 
 	if (ZEND_FCI_INITIALIZED(fci_read)) {
 		read_cb = bevent_read_cb;
 	bev->stream_id = -1;
 
 	bev->self = return_value;
-	/* Ensure the object won't be destroyed in case if we are in a callback */
-	/* Don't ensure the object won't be destroyed in case if we are in a callback
-	 * User should keep variable somewhere if he/she wants to prevent auto-destruction
-	 * within a callback.
-	 * Z_ADDREF_P(return_value);
-	 */
+	Z_ADDREF_P(return_value);
 }
 /* }}} */
 
 	zend_list_addref(Z_LVAL_PP(ppzfd));
 
 	bev->self = return_value;
-	/* Ensure the object won't be destroyed in case if we are in a callback */
-	/* Don't ensure the object won't be destroyed in case if we are in a callback
-	 * User should keep variable somewhere if he/she wants to prevent auto-destruction
-	 * within a callback.
-	 * Z_ADDREF_P(return_value);
-	 */
+	Z_ADDREF_P(return_value);
 }
 /* }}} */
 

classes/listener.c

 
 	if (ZEND_FCI_INITIALIZED(*pfci)) {
 		args[0] = &l->self;
-		Z_ADDREF_P(l->self);
 
 		/* Convert the socket created by libevent to PHP stream
 	 	 * and save it's resource ID in l->stream_id */
 	PHP_EVENT_COPY_FCALL_INFO(l->fci, l->fcc, &fci, &fcc);
 
 	l->self = zself;
+	Z_ADDREF_P(l->self);
 
 	TSRMLS_SET_CTX(l->thread_ctx);
 }