Ruslan Osmanov avatar Ruslan Osmanov committed 0e0240d

Comments (0)

Files changed (4)

 /* }}} */
 
 /* {{{ php_ev_add_property */
-static void php_ev_add_property(HashTable *h, const char *name, size_t name_len, php_ev_read_t read_func, php_ev_write_t write_func TSRMLS_DC) {
+static void php_ev_add_property(HashTable *h, const char *name, size_t name_len, php_ev_read_t read_func, php_ev_write_t write_func, php_ev_get_prop_ptr_ptr_t get_ptr_ptr_func TSRMLS_DC) {
 	php_ev_prop_handler p;
 
-	p.name       = (char *) name;
-	p.name_len   = name_len;
-	p.read_func  = (read_func) ? read_func : php_ev_prop_read_default;
-	p.write_func = (write_func) ? write_func: php_ev_prop_write_default;
+	p.name             = (char *) name;
+	p.name_len         = name_len;
+	p.read_func        = (read_func) ? read_func : php_ev_prop_read_default;
+	p.write_func       = (write_func) ? write_func: php_ev_prop_write_default;
+	p.get_ptr_ptr_func = get_ptr_ptr_func;
 	zend_hash_add(h, name, name_len + 1, &p, sizeof(php_ev_prop_handler), NULL);
 }
 /* }}} */
 /* {{{ php_ev_write_property */
 void php_ev_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
 {
-	zval             tmp_member;
-	php_ev_object   *obj;
+	zval                 tmp_member;
+	php_ev_object       *obj;
 	php_ev_prop_handler *hnd;
-	int              ret;
+	int                  ret;
 
 	if (member->type != IS_STRING) {
 	    tmp_member = *member;
 #endif    
 /* }}} */
 
+/* {{{ php_ev_get_property_ptr_ptr */
+static zval **php_ev_get_property_ptr_ptr(zval *object, zval *member, const zend_literal *key TSRMLS_DC)
+{
+	php_ev_object        *obj;
+	zval                  tmp_member;
+	zval                **retval     = NULL;
+	php_ev_prop_handler  *hnd;
+	int                   ret        = FAILURE;
+
+	if (member->type != IS_STRING) {
+		tmp_member = *member;
+		zval_copy_ctor(&tmp_member);
+		convert_to_string(&tmp_member);
+		member = &tmp_member;
+	}
+
+	obj = (php_ev_object *) zend_objects_get_address(object TSRMLS_CC);
+
+	if (obj->prop_handler != NULL) {
+		ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, (void **) &hnd);
+	}
+
+	if (ret == FAILURE) {
+		retval = zend_get_std_object_handlers()->get_property_ptr_ptr(object, member, key TSRMLS_CC);
+	} else if (hnd->get_ptr_ptr_func) {
+		retval = hnd->get_ptr_ptr_func(obj TSRMLS_CC);
+	}
+
+	if (member == &tmp_member) {
+		zval_dtor(member);
+	}
+
+	return retval;
+}
+/* }}} */
 
 /* {{{ php_ev_object_free_storage 
  * Common Ev object cleaner */
 	ev_object_handlers.clone_obj            = NULL; /* TODO: add __clone() handler */
 	ev_object_handlers.read_property        = php_ev_read_property;
 	ev_object_handlers.write_property       = php_ev_write_property;
-	ev_object_handlers.get_property_ptr_ptr = std_hnd->get_property_ptr_ptr;
+	ev_object_handlers.get_property_ptr_ptr = php_ev_get_property_ptr_ptr; /* std_hnd->get_property_ptr_ptr */;
 	ev_object_handlers.has_property         = php_ev_has_property;
 #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
 	ev_object_handlers.get_debug_info       = php_ev_object_get_debug_info;
     int i = 0;                                                                                 \
     while (b[i].name != NULL) {                                                                \
         php_ev_add_property((a), (b)[i].name, (b)[i].name_length,                              \
-                (php_ev_read_t)(b)[i].read_func, (php_ev_write_t)(b)[i].write_func TSRMLS_CC); \
+                (php_ev_read_t)(b)[i].read_func, (php_ev_write_t)(b)[i].write_func,            \
+                (php_ev_get_prop_ptr_ptr_t)(b)[i].get_ptr_ptr_func TSRMLS_CC);                 \
         i++;                                                                                   \
     }                                                                                          \
 }
 
 /* {{{ EvWatcher property handlers */
 
+
 /* {{{ ev_watcher_prop_is_active_read */
 static int ev_watcher_prop_is_active_read(php_ev_object *obj, zval **retval TSRMLS_DC)
 {
 }
 /* }}} */
 
+/* {{{ ev_watcher_prop_data_get_ptr_ptr */
+static zval **ev_watcher_prop_data_get_ptr_ptr(php_ev_object *obj TSRMLS_DC)
+{
+	PHP_EV_ASSERT(obj->ptr);
+
+	return &PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj)->data;
+}
+/* }}} */
+
 /* {{{ ev_watcher_prop_data_read  */
 static int ev_watcher_prop_data_read(php_ev_object *obj, zval **retval TSRMLS_DC)
 {
 
 /* {{{ ev_watcher_property_entries[] */
 const php_ev_property_entry ev_watcher_property_entries[] = {
-	{"is_active",  sizeof("is_active")  - 1, ev_watcher_prop_is_active_read,  NULL},
-	{"data",       sizeof("data")       - 1, ev_watcher_prop_data_read,       ev_watcher_prop_data_write},
-	{"is_pending", sizeof("is_pending") - 1, ev_watcher_prop_is_pending_read, NULL},
-	{"priority",   sizeof("priority")   - 1, ev_watcher_prop_priority_read,   ev_watcher_prop_priority_write},
-	{NULL, 0, NULL, NULL}
+	{"is_active",  sizeof("is_active")  - 1, ev_watcher_prop_is_active_read,  NULL,                           NULL},
+	{"data",       sizeof("data")       - 1, ev_watcher_prop_data_read,       ev_watcher_prop_data_write,     ev_watcher_prop_data_get_ptr_ptr},
+	{"is_pending", sizeof("is_pending") - 1, ev_watcher_prop_is_pending_read, NULL,                           NULL},
+	{"priority",   sizeof("priority")   - 1, ev_watcher_prop_priority_read,   ev_watcher_prop_priority_write, NULL},
+	{NULL, 0, NULL, NULL, NULL}
 };
 /* }}} */
 
 
 /* {{{ ev_io_property_entries[] */
 const php_ev_property_entry ev_io_property_entries[] = {
-	{"fd",     sizeof("fd")     - 1, ev_io_prop_fd_read,     NULL},
-	{"events", sizeof("events") - 1, ev_io_prop_events_read, NULL},
-    {NULL, 0, NULL, NULL}
+	{"fd",     sizeof("fd")     - 1, ev_io_prop_fd_read,     NULL, NULL},
+	{"events", sizeof("events") - 1, ev_io_prop_events_read, NULL, NULL},
+    {NULL, 0, NULL, NULL, NULL}
 };
 /* }}} */
 
 
 /* {{{ ev_timer_property_entries[] */
 const php_ev_property_entry ev_timer_property_entries[] = {
-	{"repeat",    sizeof("repeat")    - 1, ev_timer_prop_repeat_read,    ev_timer_prop_repeat_write},
-	{"remaining", sizeof("remaining") - 1, ev_timer_prop_remaining_read, NULL},
-    {NULL, 0, NULL, NULL}
+	{"repeat",    sizeof("repeat")    - 1, ev_timer_prop_repeat_read,    ev_timer_prop_repeat_write, NULL},
+	{"remaining", sizeof("remaining") - 1, ev_timer_prop_remaining_read, NULL, NULL},
+    {NULL, 0, NULL, NULL, NULL}
 };
 /* }}} */
 
 #if EV_PERIODIC_ENABLE
 /* {{{ ev_periodic_property_entries[] */
 const php_ev_property_entry ev_periodic_property_entries[] = {
-	{"offset",   sizeof("offset")   - 1, ev_periodic_prop_offset_read,   ev_periodic_prop_offset_write},
-	{"interval", sizeof("interval") - 1, ev_periodic_prop_interval_read, ev_periodic_prop_interval_write},
-    {NULL, 0, NULL, NULL}
+	{"offset",   sizeof("offset")   - 1, ev_periodic_prop_offset_read,   ev_periodic_prop_offset_write, NULL},
+	{"interval", sizeof("interval") - 1, ev_periodic_prop_interval_read, ev_periodic_prop_interval_write, NULL},
+    {NULL, 0, NULL, NULL, NULL}
 };
 /* }}} */
 
 #if EV_SIGNAL_ENABLE
 /* {{{ ev_signal_property_entries[] */
 const php_ev_property_entry ev_signal_property_entries[] = {
-	{"signum", sizeof("signum") - 1, ev_signal_prop_signum_read, NULL},
-    {NULL, 0, NULL, NULL}
+	{"signum", sizeof("signum") - 1, ev_signal_prop_signum_read, NULL, NULL},
+    {NULL, 0, NULL, NULL, NULL}
 };
 /* }}} */
 
 #if EV_CHILD_ENABLE
 /* {{{ ev_child_property_entries[] */
 const php_ev_property_entry ev_child_property_entries[] = {
-	{"pid",     sizeof("pid")     - 1, ev_child_prop_pid_read,     NULL},
-	{"rpid",    sizeof("rpid")    - 1, ev_child_prop_rpid_read,    NULL},
-	{"rstatus", sizeof("rstatus") - 1, ev_child_prop_rstatus_read, NULL},
-    {NULL, 0, NULL, NULL}
+	{"pid",     sizeof("pid")     - 1, ev_child_prop_pid_read,     NULL, NULL},
+	{"rpid",    sizeof("rpid")    - 1, ev_child_prop_rpid_read,    NULL, NULL},
+	{"rstatus", sizeof("rstatus") - 1, ev_child_prop_rstatus_read, NULL, NULL},
+    {NULL, 0, NULL, NULL, NULL}
 };
 /* }}} */
 
 #if EV_STAT_ENABLE
 /* {{{ ev_stat_property_entries[] */
 const php_ev_property_entry ev_stat_property_entries[] = {
-	{"path",     sizeof("path")     - 1, ev_stat_prop_path_read,     NULL},
-	{"interval", sizeof("interval") - 1, ev_stat_prop_interval_read, NULL},
-    {NULL, 0, NULL, NULL}
+	{"path",     sizeof("path")     - 1, ev_stat_prop_path_read,     NULL, NULL},
+	{"interval", sizeof("interval") - 1, ev_stat_prop_interval_read, NULL, NULL},
+    {NULL, 0, NULL, NULL, NULL}
 };
 /* }}} */
 
 #if EV_EMBED_ENABLE
 /* {{{ ev_embed_property_entries[] */
 const php_ev_property_entry ev_embed_property_entries[] = {
-	{"other", sizeof("other") - 1, ev_embed_prop_other_read, NULL},
-    {NULL, 0, NULL, NULL}
+	{"other", sizeof("other") - 1, ev_embed_prop_other_read, NULL, NULL},
+    {NULL, 0, NULL, NULL, NULL}
 };
 /* }}} */
 
 
 typedef int (*php_ev_read_t)(php_ev_object  *obj, zval **retval TSRMLS_DC);
 typedef int (*php_ev_write_t)(php_ev_object *obj, zval *newval  TSRMLS_DC);
+#if 0
+typedef zval **(*php_ev_get_prop_ptr_ptr_t)(php_ev_object *obj, zval *object, zval *member, const struct _zend_literal *key TSRMLS_DC);
+#endif
+typedef zval **(*php_ev_get_prop_ptr_ptr_t)(php_ev_object *obj TSRMLS_DC);
 
 /* Property of an Ev* class */
 
 typedef struct php_ev_property_entry {
-	const char     *name;
-	size_t          name_length;
-	php_ev_read_t   read_func;
-	php_ev_write_t  write_func;
+	const char                *name;
+	size_t                     name_length;
+	php_ev_read_t              read_func;
+	php_ev_write_t             write_func;
+	php_ev_get_prop_ptr_ptr_t  get_ptr_ptr_func;
 } php_ev_property_entry;
 
 typedef struct {
-	char           *name;
-	size_t          name_len;
-	php_ev_read_t   read_func;
-	php_ev_write_t  write_func;
+	char                      *name;
+	size_t                     name_len;
+	php_ev_read_t              read_func;
+	php_ev_write_t             write_func;
+	php_ev_get_prop_ptr_ptr_t  get_ptr_ptr_func;
 } php_ev_prop_handler;
 
 
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.