Commits

Ruslan Osmanov committed 67548f0

Fix: get_properties property handler was not implemented for PHP >= 5.4.0

  • Participants
  • Parent commits eb0ded1
  • Tags 0.2.8

Comments (0)

Files changed (3)

 	    ret = zend_hash_find((HashTable *) obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
 	}
 	if (ret == SUCCESS) {
-	    Z_ADDREF_P(value);
 	    hnd->write_func(obj, value TSRMLS_CC);
-	    zval_ptr_dtor(&value);
 	} else {
 	    zend_object_handlers * std_hnd = zend_get_std_object_handlers();
 	    std_hnd->write_property(object, member, value, key TSRMLS_CC);
 #endif    
 /* }}} */
 
+#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4
+/* {{{ get_properties
+   Returns all object properties. */
+static HashTable *get_properties(zval *object TSRMLS_DC)
+{
+	php_ev_object       *obj;
+	php_ev_prop_handler *hnd;
+	HashTable           *props;
+	zval                *val;
+	char                *key;
+	uint                 key_len;
+	HashPosition         pos;
+	ulong                num_key;
+
+	obj = (php_ev_object *) zend_objects_get_address(object TSRMLS_CC);
+	props = zend_std_get_properties(object TSRMLS_CC);
+
+	if (obj->prop_handler) {
+		zend_hash_internal_pointer_reset_ex(obj->prop_handler, &pos);
+
+		while (zend_hash_get_current_data_ex(obj->prop_handler,
+					(void **) &hnd, &pos) == SUCCESS) {
+			zend_hash_get_current_key_ex(obj->prop_handler,
+					&key, &key_len, &num_key, 0, &pos);
+			if (!hnd->read_func || hnd->read_func(obj, &val TSRMLS_CC) != SUCCESS) {
+				val = EG(uninitialized_zval_ptr);
+				Z_ADDREF_P(val);
+			}
+			zend_hash_update(props, key, key_len, (void *) &val, sizeof(zval *), NULL);
+			zend_hash_move_forward_ex(obj->prop_handler, &pos);
+		}
+	}
+
+	return obj->zo.properties;
+}
+/* }}} */
+#endif
+
+
+
 /* {{{ php_ev_get_property_ptr_ptr */
 #if PHP_VERSION_ID >= 50500
 static zval **php_ev_get_property_ptr_ptr(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
 	data = php_ev_watcher_data(ptr);
 	if (data) {
 		zval_ptr_dtor(&data);
+		php_ev_watcher_data(ptr) = NULL;
 	}
 
 	zval_ptr_dtor(&php_ev_watcher_self(ptr));
 #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
 	ev_object_handlers.get_debug_info       = php_ev_object_get_debug_info;
 #endif
+#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4
+	ev_object_handlers.get_properties       = get_properties;
+#endif
 
 	zend_hash_init(&classes, 0, NULL, NULL, 1);
 	php_ev_register_classes(TSRMLS_C);
     <email>osmanov@php.net</email>
     <active>yes</active>
   </lead>
-  <date>2013-07-20</date>
+  <date>2013-07-21</date>
   <!--{{{ Current version -->
   <version>
     <release>0.2.8</release>
   <notes><![CDATA[
   Fix: segmentation fault in EvLoop/EvWatcher dtors caused by reference variables stored in 'data' property
   Fix: EvLoop/EvWatcher object dtors sometimes didn't free the 'data' member until the script shutdown phase
+  Fix: get_properties property handler was not implemented for PHP >= 5.4.0
   ]]></notes>
   <!--}}}-->
   <!--{{{ Contents -->
       <notes><![CDATA[
   Fix: segmentation fault in EvLoop/EvWatcher dtors caused by reference variables stored in 'data' property
   Fix: EvLoop/EvWatcher object dtors sometimes didn't free the 'data' member until the script shutdown phase
+  Fix: get_properties property handler was not implemented for PHP >= 5.4.0
   ]]></notes>
     </release>
     <!--}}}-->
 #include "watcher.h"
 #include <fcntl.h>
 
-static inline void php_ev_prop_write_zval(zval **ppz, const zval *value)
+static inline void php_ev_prop_write_zval(zval **ppz, zval *value)
 {
 	if (!*ppz) {
 		MAKE_STD_ZVAL(*ppz);
 	REPLACE_ZVAL_VALUE(ppz, value, PZVAL_IS_REF((zval *)value));
 }
 
-static inline void php_ev_prop_read_zval(const zval *pz, zval **retval)
+static inline void php_ev_prop_read_zval(zval *pz, zval **retval)
 {
 	if (!pz) {
 		ALLOC_INIT_ZVAL(*retval);
 	}
 
     MAKE_STD_ZVAL(*retval);
-
+#if 0
     REPLACE_ZVAL_VALUE(retval, pz, PZVAL_IS_REF((zval *)pz));
+#endif
+	ZVAL_ZVAL(*retval, pz, 1, 0);
 }