From: Marcus Boerger <helly@php.net>
Date: Tue, 20 Dec 2005 21:38:28 +0000 (+0000)
Subject: - Apply workaround only when neccessary
X-Git-Tag: php-5.1.2RC1~25
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e43f0085b3e45f157b6d8287ac5264d39b1fc41;p=php

- Apply workaround only when neccessary
---

diff --git a/ext/spl/config.m4 b/ext/spl/config.m4
index 8f0b19084b..6f9db5819d 100755
--- a/ext/spl/config.m4
+++ b/ext/spl/config.m4
@@ -8,6 +8,23 @@ if test "$PHP_SPL" != "no"; then
   if test "$ext_shared" = "yes"; then
     AC_MSG_ERROR(Cannot build SPL as a shared module)
   fi
+  AC_MSG_CHECKING(whether zend_object_value is packed)
+  AC_TRY_RUN([
+#include "Zend/zend_types.h"
+int main(int argc, char **argv) {
+	return ((sizeof(zend_object_handle) + sizeof(zend_object_handlers*)) == sizeof(zend_object_value)) ? 0 : 1;
+}
+  ], [
+    ac_result=1
+    AC_MSG_RESULT(yes)
+  ],[
+    ac_result=0
+    AC_MSG_RESULT(no)
+  ], [
+    ac_result=0
+    AC_MSG_RESULT(no)
+  ])   
+  AC_DEFINE(HAVE_PACKED_OBJECT_VALUE, $ac_result, [Whether struct _zend_object_value is packed])
   AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support]) 
   PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_sxe.c spl_exceptions.c spl_observer.c, $ext_shared)
 fi
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index cf8cb8da57..56aa42c33a 100755
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -129,17 +129,25 @@ static zend_object_value spl_SplObjectStorage_new(zend_class_entry *class_type T
 SPL_METHOD(SplObjectStorage, attach)
 {
 	zval *obj;
-	zend_object_value zvalue;
+
 	spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
 		return;
 	}
-	memset(&zvalue, 0, sizeof(zend_object_value));
-	zvalue.handle = obj->value.obj.handle;
-	zvalue.handlers = obj->value.obj.handlers;
-			
-	zend_hash_update(&intern->storage, (char*)&zvalue, sizeof(zend_object_value), &obj, sizeof(zval*), NULL);
+
+#if HAVE_PACKED_OBJECT_VALUE
+	zend_hash_update(&intern->storage, (char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value), &obj, sizeof(zval*), NULL);	
+#else
+	{
+		zend_object_value zvalue;
+		memset(&zvalue, 0, sizeof(zend_object_value));
+		zvalue.handle = Z_OBJ_HANDLE_P(obj);
+		zvalue.handlers = Z_OBJ_HT_P(obj);
+		zend_hash_update(&intern->storage, (char*)&zvalue, sizeof(zend_object_value), &obj, sizeof(zval*), NULL);
+	}
+#endif
+
 	obj->refcount++;
 } /* }}} */
 
@@ -148,17 +156,24 @@ SPL_METHOD(SplObjectStorage, attach)
 SPL_METHOD(SplObjectStorage, detach)
 {
 	zval *obj;
-	zend_object_value zvalue;
 	spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
 		return;
 	}
-	memset(&zvalue, 0, sizeof(zend_object_value));
-	zvalue.handle = obj->value.obj.handle;
-	zvalue.handlers = obj->value.obj.handlers;
-	
-	zend_hash_del(&intern->storage, (char*)&zvalue, sizeof(zend_object_value));
+
+#if HAVE_PACKED_OBJECT_VALUE
+	zend_hash_del(&intern->storage, (char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value));
+#else
+	{
+		zend_object_value zvalue;
+		memset(&zvalue, 0, sizeof(zend_object_value));
+		zvalue.handle = Z_OBJ_HANDLE_P(obj);
+		zvalue.handlers = Z_OBJ_HT_P(obj);
+		zend_hash_del(&intern->storage, (char*)&zvalue, sizeof(zend_object_value));
+	}
+#endif
+
 	zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos);
 	intern->index = 0;
 } /* }}} */
@@ -168,17 +183,23 @@ SPL_METHOD(SplObjectStorage, detach)
 SPL_METHOD(SplObjectStorage, contains)
 {
 	zval *obj;
-	zend_object_value zvalue;
 	spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
 		return;
 	}
-	memset(&zvalue, 0, sizeof(zend_object_value));
-	zvalue.handle = obj->value.obj.handle;
-	zvalue.handlers = obj->value.obj.handlers;
-	
-	RETURN_BOOL(zend_hash_exists(&intern->storage, (char*)&zvalue, sizeof(zend_object_value)));
+
+#if HAVE_PACKED_OBJECT_VALUE
+	RETURN_BOOL(zend_hash_exists(&intern->storage, (char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value)));
+#else
+	{
+		zend_object_value zvalue;
+		memset(&zvalue, 0, sizeof(zend_object_value));
+		zvalue.handle = Z_OBJ_HANDLE_P(obj);
+		zvalue.handlers = Z_OBJ_HT_P(obj);
+		RETURN_BOOL(zend_hash_exists(&intern->storage, (char*)&zvalue, sizeof(zend_object_value)));
+	}
+#endif
 } /* }}} */
 
 /* {{{ proto int SplObjectStorage::count()