]> granicus.if.org Git - php/commitdiff
MFZE1
authorZeev Suraski <zeev@php.net>
Tue, 14 Aug 2001 15:24:20 +0000 (15:24 +0000)
committerZeev Suraski <zeev@php.net>
Tue, 14 Aug 2001 15:24:20 +0000 (15:24 +0000)
Zend/zend_constants.c
Zend/zend_constants.h
Zend/zend_variables.c
Zend/zend_variables.h

index 5cee47fc4137e145da7b7264f4338bc01349672d..b4deb62f825e3058dfd3f0faffb0a8b4b6f74c1d 100644 (file)
@@ -40,6 +40,9 @@ void copy_zend_constant(zend_constant *c)
        c->name = zend_strndup(c->name, c->name_len);
        if (!(c->flags & CONST_PERSISTENT)) {
                zval_copy_ctor(&c->value);
+               if (c->flags & CONST_EFREE_PERSISTENT) { /* persist_alloc()'d data */
+                       persist_alloc(&c->value);
+               }
        }
 }
 
index d8491460c4d4effe855b986cd32671923b1c21ae..85df4c865691c4360c7707b423ffbc0d248f64fe 100644 (file)
 
 #include "zend_globals.h"
 
-#define CONST_CS 0x1                           /* Case Sensitive */
-#define CONST_PERSISTENT 0x2
+#define CONST_CS                               (1<<0)                          /* Case Sensitive */
+#define CONST_PERSISTENT               (1<<1)                          /* Persistent */
+#define CONST_EFREE_PERSISTENT (1<<2)                          /* In conjunction with CONST_PERSISTENT,
+                                                                                                        * means that the constant should be freed
+                                                                                                        * using zval_dtor() on shutdown.
+                                                                                                        */
 
 typedef struct _zend_constant {
        zval value;
index 757019860c9d115427117427c33b19bc7030364e..f919fb8c85f2d0c4184e8a544fccfe962684a647 100644 (file)
@@ -126,6 +126,40 @@ ZEND_API int _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
 }
 
 
+ZEND_API int zval_persist(zval *zvalue TSRMLS_DC)
+{
+       switch (zvalue->type) {
+               case IS_RESOURCE:
+                       return FAILURE; /* resources cannot be persisted */
+                       break;
+               case IS_BOOL:
+               case IS_LONG:
+               case IS_NULL:
+                       break;
+               case IS_CONSTANT:
+               case IS_STRING:
+                       if (zvalue->value.str.val) {
+                               if (zvalue->value.str.len==0) {
+                                       zvalue->value.str.val = empty_string;
+                                       return SUCCESS;
+                               }
+                       }
+                       persist_alloc(zvalue->value.str.val);
+                       break;
+               case IS_ARRAY:
+               case IS_CONSTANT_ARRAY:
+                       persist_alloc(zvalue->value.ht);
+                       zend_hash_apply(zvalue->value.ht, (apply_func_t) zval_persist TSRMLS_CC);
+                       break;
+               case IS_OBJECT:
+                       persist_alloc(zvalue->value.obj.properties);
+                       zend_hash_apply(zvalue->value.obj.properties, (apply_func_t) zval_persist TSRMLS_CC);
+                       break;
+       }
+       return SUCCESS;
+}
+
+
 ZEND_API int zend_print_variable(zval *var) 
 {
        return zend_print_zval(var, 0);
index 5b6a68481c0c18296b15ac3a270143d85c197d62..20a75b50e67c3fc35b27801cdde1d27933445c6e 100644 (file)
@@ -32,6 +32,8 @@ ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC);
 #define zval_dtor(zvalue) _zval_dtor((zvalue) ZEND_FILE_LINE_CC)
 #define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)
 
+ZEND_API int zval_persist(zval *zvalue TSRMLS_DC);
+
 #if ZEND_DEBUG
 ZEND_API int _zval_copy_ctor_wrapper(zval *zvalue);
 ZEND_API void _zval_dtor_wrapper(zval *zvalue);