Skip to content

Instantly share code, notes, and snippets.

@m6w6
Created December 5, 2014 15:03
Show Gist options
  • Save m6w6/4c5194dbacb891b449ff to your computer and use it in GitHub Desktop.
Save m6w6/4c5194dbacb891b449ff to your computer and use it in GitHub Desktop.
Accessors for custom objects
diff --git a/Zend/zend_object_handlers.h b/Zend/zend_object_handlers.h
index ac0965a..40bb3cb 100644
--- a/Zend/zend_object_handlers.h
+++ b/Zend/zend_object_handlers.h
@@ -158,6 +158,9 @@ extern ZEND_API zend_object_handlers std_object_handlers;
#define zend_get_function_root_class(fbc) \
((fbc)->common.prototype ? (fbc)->common.prototype->common.scope : (fbc)->common.scope)
+#define zend_get_custom_obj_ptr(zobjp) \
+ (void *)((char *) (zobjp) - (zobjp)->handlers->offset)
+
BEGIN_EXTERN_C()
ZEND_API union _zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_string *function_name_strval, const zval *key TSRMLS_DC);
ZEND_API zval *zend_std_get_static_property(zend_class_entry *ce, zend_string *property_name, zend_bool silent, void **cache_slot TSRMLS_DC);
diff --git a/Zend/zend_types.h b/Zend/zend_types.h
index c444bd4..3b60639 100644
--- a/Zend/zend_types.h
+++ b/Zend/zend_types.h
@@ -410,6 +410,9 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
#define Z_OBJ(zval) (zval).value.obj
#define Z_OBJ_P(zval_p) Z_OBJ(*(zval_p))
+#define Z_OBJ_CUSTOM(zval) (void *) ((char *) (zval).value.obj - Z_OBJ_HANDLER((zval), offset))
+#define Z_OBJ_CUSTOM_P(zval_p) Z_OBJ_CUSTOM(*(zval_p))
+
#define Z_OBJ_HT(zval) Z_OBJ(zval)->handlers
#define Z_OBJ_HT_P(zval_p) Z_OBJ_HT(*(zval_p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment