/** * @zobject: swoole_client object */ static int php_swoole_client_close(zval **zobject, int fd TSRMLS_DC) { zval *zcallback = NULL; zval *retval; zval **args[1]; swClient *cli; char *hash_key; int hash_key_len; hash_key_len = spprintf(&hash_key, sizeof(int)+1, "%d", fd); if (zend_hash_find(&php_sw_client_callback, hash_key, hash_key_len+1, (void **)&zobject) != SUCCESS) { zend_error(E_WARNING, "swoole_client->close: Fd[%d] is not a swoole_client object", fd); efree(hash_key); return SW_ERR; } zcallback = zend_read_property(swoole_client_class_entry_ptr, *zobject, SW_STRL("close")-1, 0 TSRMLS_CC); if (zcallback == NULL) { zend_error(E_WARNING, "swoole_client: swoole_client object have not close callback."); efree(hash_key); return SW_ERR; } SwooleG.main_reactor->del(SwooleG.main_reactor, fd); zval **zres; if (zend_hash_find(Z_OBJPROP_PP(zobject), SW_STRL("_client"), (void **) &zres) == SUCCESS) { ZEND_FETCH_RESOURCE_NO_RETURN(cli, swClient*, zres, -1, SW_RES_CLIENT_NAME, le_swoole_client); cli->close(cli); }
static inline int object_common2(UNSERIALIZE_PARAMETER, long elements) { zval *retval_ptr = NULL; zval fname; if (Z_TYPE_PP(rval) != IS_OBJECT) { return 0; } if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements, 1)) { return 0; } if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY && zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup"))) { INIT_PZVAL(&fname); ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0); UNSERIALIZE2_G(serialize_lock)++; call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); UNSERIALIZE2_G(serialize_lock)--; } if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } if (EG(exception)) { return 0; } return finish_nested_data(UNSERIALIZE_PASSTHRU); }
/* {{{ pip_zobject_to_pyobject(zval **obj) Convert a PHP (Zend) object to a Python object */ PyObject * pip_zobject_to_pyobject(zval **obj) { PyObject *dict, *item, *str; zval **entry; char *string_key; long num_key; /* * At this point, we represent a PHP object as a dictionary of * its properties. In the future, we may provide a true object * conversion (which is entirely possible, but it's more work * that I plan on doing right now). */ dict = PyDict_New(); /* Start at the beginning of the object properties hash */ zend_hash_internal_pointer_reset(Z_OBJPROP_PP(obj)); /* Iterate over the hash's elements */ while (zend_hash_get_current_data(Z_OBJPROP_PP(obj), (void **)&entry) == SUCCESS) { /* Convert the PHP value to its Python equivalent (recursion) */ item = pip_zval_to_pyobject(entry); switch (zend_hash_get_current_key(Z_OBJPROP_PP(obj), &string_key, &num_key, 0)) { case HASH_KEY_IS_STRING: PyDict_SetItemString(dict, string_key, item); break; case HASH_KEY_IS_LONG: str = PyString_FromFormat("%d", num_key); PyObject_SetItem(dict, str, item); Py_DECREF(str); break; case HASH_KEY_NON_EXISTANT: php_error(E_ERROR, "No array key"); break; } /* Advance to the next entry */ zend_hash_move_forward(Z_OBJPROP_PP(obj)); } return dict; }
/** * @zobject: swoole_client object */ static int php_swoole_client_close(zval **zobject, int fd TSRMLS_DC) { zval *zcallback = NULL; zval *retval; zval **args[1]; swClient *cli; zval **zres; if (zend_hash_find(Z_OBJPROP_PP(zobject), SW_STRL("_client"), (void **) &zres) == SUCCESS) { ZEND_FETCH_RESOURCE_NO_RETURN(cli, swClient*, zres, -1, SW_RES_CLIENT_NAME, le_swoole_client); }