summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-04 19:41:43 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-04 19:41:43 +0100
commit5aaeb88d8b753a3b51e81c36dba6293dd436148b (patch)
tree8632e035361775bc64b8c582f3d951d4c0693f8b
parentbb94d0612a1a5fb2e1d4be125f8c171464917590 (diff)
fixed compile issue, overwriting the default object handlers is of course not a very smart thing to do...
-rw-r--r--include/classbase.h6
-rw-r--r--src/classbase.cpp38
2 files changed, 36 insertions, 8 deletions
diff --git a/include/classbase.h b/include/classbase.h
index 8a691fa..d3f3833 100644
--- a/include/classbase.h
+++ b/include/classbase.h
@@ -214,6 +214,12 @@ private:
static struct _zend_object_value createObject(struct _zend_class_entry *entry);
/**
+ * Retrieve pointer to our own object handlers
+ * @return zend_object_handlers
+ */
+ static zend_object_handlers *objectHandlers();
+
+ /**
* Name of the class
* @var string
*/
diff --git a/src/classbase.cpp b/src/classbase.cpp
index f9b58d0..e813617 100644
--- a/src/classbase.cpp
+++ b/src/classbase.cpp
@@ -38,6 +38,34 @@ static ClassBase *cpp_class(zend_class_entry *entry)
}
/**
+ * Retrieve pointer to our own object handlers
+ * @return zend_object_handlers
+ */
+zend_object_handlers *ClassBase::objectHandlers()
+{
+ // keep static structure
+ static zend_object_handlers handlers;
+
+ // is the object already initialized?
+ static bool initialized = false;
+
+ // already initialized?
+ if (initialized) return &handlers;
+
+ // initialize the handlers
+ memcpy(&handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+
+ // install custom clone function
+ handlers.clone_obj = &ClassBase::cloneObject;
+
+ // remember that object is now initialized
+ initialized = true;
+
+ // done
+ return &handlers;
+}
+
+/**
* Function that is called to create space for a cloned object
* @param val The object to be cloned
* @return zend_obejct_value The object to be created
@@ -63,11 +91,8 @@ zend_object_value ClassBase::cloneObject(zval *val TSRMLS_DC)
zend_object_value result;
// set the handlers
- result.handlers = zend_get_std_object_handlers();
+ result.handlers = ClassBase::objectHandlers();
- // we need a special handler for cloning
- result.handlers->clone_obj = &ClassBase::cloneObject;
-
// store the object
MixedObject *new_object = cpp->store(entry);
@@ -102,11 +127,8 @@ zend_object_value ClassBase::createObject(zend_class_entry *entry TSRMLS_DC)
zend_object_value result;
// set the handlers
- result.handlers = zend_get_std_object_handlers();
+ result.handlers = ClassBase::objectHandlers();
- // we need a special handler for cloning
- result.handlers->clone_obj = ClassBase::cloneObject;
-
// store the object
cpp->store(entry);