/* lenof() */
#define lenof(S) (sizeof(S) - 1)
+#ifndef MIN
+# define MIN(a,b) (a<b?a:b)
+#endif
+#ifndef MAX
+# define MAX(a,b) (a>b?a:b)
+#endif
+
/* STR_SET() */
-#define STR_SET(target, source) \
- if(target) efree(target); \
- target = source
+#ifndef STR_SET
+# define STR_SET(STR, SET) \
+ { \
+ STR_FREE(STR); \
+ STR = SET; \
+ }
+#endif
/* return bool (v == SUCCESS) */
#define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
/* END */
-/* server vars shorthand */
-#define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
-
#define HTTP_PHP_INI_ENTRY(entry, default, scope, updater, global) \
STD_PHP_INI_ENTRY(entry, default, scope, updater, global, zend_http_globals, http_globals)
name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
name## _ce->ce_flags |= flags; \
memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
+ zend_hash_init(& name## _ce->constants_table, 0, NULL, ZVAL_INTERNAL_PTR_DTOR, 1); \
name## _declare_default_properties(); \
}
# define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC))
# define putObject(t, o) zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) t## _free, NULL TSRMLS_CC);
# define OBJ_PROP(o) (o)->zo.properties
-# define DCL_STATIC_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
-# define DCL_STATIC_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
-# define DCL_STATIC_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
-# define GET_STATIC_PROP_EX(ce, n) zend_std_get_static_property(ce, (#n), sizeof(#n), 0 TSRMLS_CC)
-#ifdef zend_update_class_constants
-# define USE_STATIC_PROP_EX(ce) zend_update_class_constants(ce TSRMLS_CC)
-#else
-# define USE_STATIC_PROP_EX(ce)
-#endif
-# define SET_STATIC_PROP_EX(ce, n, v) \
- { \
- int refcount; \
- zend_uchar is_ref; \
- zval **__static = GET_STATIC_PROP_EX(ce, n); \
- \
- refcount = (*__static)->refcount; \
- is_ref = (*__static)->is_ref; \
- switch (Z_TYPE_PP(__static)) \
- { \
- case IS_BOOL: case IS_LONG: case IS_NULL: \
- break; \
- case IS_RESOURCE: \
- zend_list_delete(Z_LVAL_PP(__static)); \
- break; \
- case IS_STRING: case IS_CONSTANT: \
- free(Z_STRVAL_PP(__static)); \
- break; \
- case IS_OBJECT: \
- Z_OBJ_HT_PP(__static)->del_ref(*__static TSRMLS_CC); \
- break; \
- case IS_ARRAY: case IS_CONSTANT_ARRAY: \
- if (Z_ARRVAL_PP(__static) && Z_ARRVAL_PP(__static) != &EG(symbol_table)) { \
- zend_hash_destroy(Z_ARRVAL_PP(__static)); \
- free(Z_ARRVAL_PP(__static)); \
- } \
- break; \
- } \
- **__static = *(v); \
- switch (Z_TYPE_PP(__static)) \
- { \
- case IS_BOOL: case IS_LONG: case IS_NULL: \
- break; \
- case IS_RESOURCE: \
- zend_list_addref(Z_LVAL_PP(__static)); \
- break; \
- case IS_STRING: case IS_CONSTANT: \
- Z_STRVAL_PP(__static) = (char *) zend_strndup(Z_STRVAL_PP(__static), Z_STRLEN_PP(__static)); \
- break; \
- case IS_OBJECT: \
- { \
- Z_OBJ_HT_PP(__static)->add_ref(*__static TSRMLS_CC); \
- } \
- break; \
- case IS_ARRAY: case IS_CONSTANT_ARRAY: \
- { \
- if (Z_ARRVAL_PP(__static) != &EG(symbol_table)) { \
- zval *tmp; \
- HashTable *old = Z_ARRVAL_PP(__static); \
- Z_ARRVAL_PP(__static) = (HashTable *) malloc(sizeof(HashTable)); \
- zend_hash_init(Z_ARRVAL_PP(__static), 0, NULL, ZVAL_PTR_DTOR, 0); \
- zend_hash_copy(Z_ARRVAL_PP(__static), old, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); \
- } \
- } \
- break; \
- } \
- (*__static)->refcount = refcount; \
- (*__static)->is_ref = is_ref; \
- }
-#define SET_STATIC_PROP_STRING_EX(ce, n, s, d) \
- { \
- zval *__tmp; \
- MAKE_STD_ZVAL(__tmp); \
- ZVAL_STRING(__tmp, (s), (d)); \
- SET_STATIC_PROP_EX(ce, n, __tmp); \
- zval_dtor(__tmp); \
- efree(__tmp); \
- }
-#define SET_STATIC_PROP_STRINGL_EX(ce, n, s, l, d) \
- { \
- zval *__tmp; \
- MAKE_STD_ZVAL(__tmp); \
- ZVAL_STRINGL(__tmp, (s), (l), (d)); \
- SET_STATIC_PROP_EX(ce, n, __tmp); \
- zval_dtor(__tmp); \
- efree(__tmp); \
- }
-# define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
-# define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
-# define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a) TSRMLS_CC)
-# define UPD_PROP(o, t, n, v) UPD_PROP_EX(o, getThis(), t, n, v)
-# define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(o->zo.ce, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC)
-# define SET_PROP(o, n, z) SET_PROP_EX(o, getThis(), n, z)
-# define SET_PROP_EX(o, this, n, z) zend_update_property(o->zo.ce, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC)
-# define GET_PROP(o, n) GET_PROP_EX(o, getThis(), n)
-# define GET_PROP_EX(o, this, n) zend_read_property(o->zo.ce, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC)
+
+# define DCL_STATIC_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
+# define DCL_STATIC_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
+# define DCL_STATIC_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
+# define GET_STATIC_PROP_EX(ce, n) zend_std_get_static_property(ce, (#n), sizeof(#n), 0 TSRMLS_CC)
+# define UPD_STATIC_PROP_EX(ce, t, n, v) zend_update_static_property_ ##t(ce, #n, sizeof(#n), (v) TSRMLS_CC)
+# define SET_STATIC_PROP_EX(ce, n, v) zend_update_static_property(ce, #n, sizeof(#n), v TSRMLS_CC)
+
+# define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
+# define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
+# define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a) TSRMLS_CC)
+# define UPD_PROP(o, t, n, v) UPD_PROP_EX(o, getThis(), t, n, v)
+# define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(o->zo.ce, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC)
+# define SET_PROP(o, n, z) SET_PROP_EX(o, getThis(), n, z)
+# define SET_PROP_EX(o, this, n, z) zend_update_property(o->zo.ce, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC)
+# define GET_PROP(o, n) GET_PROP_EX(o, getThis(), n)
+# define GET_PROP_EX(o, this, n) zend_read_property(o->zo.ce, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC)
+
+# define DCL_CONST(t, n, v) zend_declare_class_constant_ ##t(ce, (n), sizeof(n), (v) TSRMLS_CC)
# define ACC_PROP_PRIVATE(ce, flags) ((flags & ZEND_ACC_PRIVATE) && (EG(scope) && ce == EG(scope))
# define ACC_PROP_PROTECTED(ce, flags) ((flags & ZEND_ACC_PROTECTED) && (zend_check_protected(ce, EG(scope))))
#ifndef TSRMLS_SET_CTX
# ifdef ZTS
-# define TSRMLS_SET_CTX(ctx) (void ***) ctx = tsrm_ls
+# define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_ls
# else
# define TSRMLS_SET_CTX(ctx)
# endif