diff options
author | Gu Weigang <guweigang@outlook.com> | 2013-12-13 13:29:34 +0800 |
---|---|---|
committer | Gu Weigang <guweigang@outlook.com> | 2013-12-13 13:29:34 +0800 |
commit | 7c042cfcee984e16e7024a661c95d2cd3eb0b50b (patch) | |
tree | 1ea956b13fa9108c6b29e7505b998ea2d75954db | |
parent | e84fb687091e7093f9aa72f74ce4e678ab84e5f3 (diff) |
add macros for PHP 5.3
-rw-r--r-- | Examples/simple/Makefile | 12 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/argument.cpp | 4 | ||||
-rw-r--r-- | src/boolmember.h | 4 | ||||
-rw-r--r-- | src/classinfo.cpp | 13 | ||||
-rw-r--r-- | src/doublemember.h | 4 | ||||
-rw-r--r-- | src/function.cpp | 4 | ||||
-rw-r--r-- | src/includes.h | 16 | ||||
-rw-r--r-- | src/longmember.h | 4 | ||||
-rw-r--r-- | src/nullmember.h | 4 | ||||
-rw-r--r-- | src/stringmember.h | 6 |
12 files changed, 69 insertions, 10 deletions
diff --git a/Examples/simple/Makefile b/Examples/simple/Makefile index cfea8cf..a85c7f8 100644 --- a/Examples/simple/Makefile +++ b/Examples/simple/Makefile @@ -1,14 +1,16 @@ CPP = g++ RM = rm -f -CPP_FLAGS = -Wall -c -I. -O2 -std=c++11 +CPP_FLAGS = -Wall -c -I. -I/home/work/include/ -O2 -std=c++11 + +PREFIX = /home/work/ -PREFIX = /usr #Edit these lines to correspond with your own directories -LIBRARY_DIR = ${PREFIX}/lib/php5/20121212 -PHP_CONFIG_DIR = /etc/php5/cli/conf.d +LIBRARY_DIR = ${PREFIX}/local/php/lib/php/extensions/no-debug-non-zts-20090626/ + +PHP_CONFIG_DIR = /home/work/local/php/lib/ LD = g++ -LD_FLAGS = -Wall -shared -O2 +LD_FLAGS = -Wall -Wl,-rpath,/home/work/lib -shared -O2 -L/home/work/lib RESULT = simple.so PHPINIFILE = 30-phpcpp.ini @@ -1,6 +1,6 @@ -PREFIX = /usr -INCLUDE_DIR = ${PREFIX}/include -LIBRARY_DIR = ${PREFIX}/lib +PREFIX = /home/work/ +INCLUDE_DIR = ${PREFIX}/include/ +LIBRARY_DIR = ${PREFIX}/lib/ all: cd src; $(MAKE) diff --git a/src/Makefile b/src/Makefile index 069024d..c34af85 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ CPP = g++ RM = rm -f -PHP_DIR = /usr/include/php5 +PHP_DIR = /home/work/local/php/include/php/ CPP_FLAGS = -c -I. -I${PHP_DIR} -I${PHP_DIR}/main -I${PHP_DIR}/ext -I${PHP_DIR}/Zend -I${PHP_DIR}/TSRM -O2 -std=c++11 LD = g++ diff --git a/src/argument.cpp b/src/argument.cpp index 7dbf624..e8e7c8a 100644 --- a/src/argument.cpp +++ b/src/argument.cpp @@ -28,7 +28,9 @@ Argument::Argument(const char *name, Type type, bool required, bool byref) // fill members _info->name = name; _info->name_len = strlen(name); +#if PHP_VERSION_ID >= 50400 _info->type_hint = type == arrayType || type == callableType ? type : 0; +#endif _info->class_name = NULL; _info->class_name_len = 0; _info->allow_null = false; @@ -54,7 +56,9 @@ Argument::Argument(const char *name, const char *classname, bool nullable, bool // fill members _info->name = name; _info->name_len = strlen(name); +#if PHP_VERSION_ID >= 50400 _info->type_hint = objectType; +#endif _info->class_name = classname; _info->class_name_len = strlen(classname); _info->allow_null = nullable; diff --git a/src/boolmember.h b/src/boolmember.h index fa482f3..84d7d44 100644 --- a/src/boolmember.h +++ b/src/boolmember.h @@ -51,7 +51,11 @@ public: */ virtual void declare(struct _zend_class_entry *entry, const char *name, int size, int flags) { +#if PHP_VERSION_ID >= 50400 zend_declare_property_bool(entry, name, size, _value, flags); +#else + zend_declare_property_bool(entry, (char *) name, size, _value, flags); +#endif } }; diff --git a/src/classinfo.cpp b/src/classinfo.cpp index 81edf4f..04123b3 100644 --- a/src/classinfo.cpp +++ b/src/classinfo.cpp @@ -61,7 +61,11 @@ static zend_object_value create_object(zend_class_entry *type TSRMLS_DC) while (base->parent) base = base->parent; // retrieve the classinfo object +#if PHP_VERSION_ID >= 50400 _ClassInfo *info = (_ClassInfo *)base->info.user.doc_comment; +#else + _ClassInfo *info = (_ClassInfo *)base->doc_comment; +#endif // store the class object->php.ce = type; @@ -74,7 +78,12 @@ static zend_object_value create_object(zend_class_entry *type TSRMLS_DC) zend_hash_init(object->php.properties, 0, NULL, ZVAL_PTR_DTOR, 0); // initialize the properties +#if PHP_VERSION_ID < 50399 + zend_hash_copy(object->php.properties, &(type->default_properties), + (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); +#else object_properties_init(&(object->php), type); +#endif // the thing we're going to return zend_object_value result; @@ -126,7 +135,11 @@ void _ClassInfo::initialize(TSRMLS_DC) _entry = zend_register_internal_class(&entry TSRMLS_CC); // store pointer to the class in the unused doc_comment member +#if PHP_VERSION_ID >= 50400 _entry->info.user.doc_comment = (const char *)this; +#else + _entry->doc_comment = (char *)this; +#endif // initialize the entry initialize(_entry); diff --git a/src/doublemember.h b/src/doublemember.h index f03b248..e3b75eb 100644 --- a/src/doublemember.h +++ b/src/doublemember.h @@ -51,7 +51,11 @@ public: */ virtual void declare(struct _zend_class_entry *entry, const char *name, int size, int flags) { +#if PHP_VERSION_ID >= 50400 zend_declare_property_double(entry, name, size, _value, flags); +#else + zend_declare_property_double(entry, (char *)name, size, _value, flags); +#endif } }; diff --git a/src/function.cpp b/src/function.cpp index cc4315f..a2864ac 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -106,7 +106,9 @@ void Function::fill(zend_function_entry *entry, const char *classname, bool pub) entry->flags = classname ? (pub ? ZEND_ACC_PUBLIC : ZEND_ACC_PROTECTED) : 0; // we should fill the first argument as well +#if PHP_VERSION_ID >= 50400 fill((zend_internal_function_info *)entry->arg_info, classname); +#endif } /** @@ -114,6 +116,7 @@ void Function::fill(zend_function_entry *entry, const char *classname, bool pub) * @param info Info to be filled * @param classname Optional classname */ +#if PHP_VERSION_ID >= 50400 void Function::fill(zend_internal_function_info *info, const char *classname) const { // fill in all the members, note that return reference is false by default, @@ -133,6 +136,7 @@ void Function::fill(zend_internal_function_info *info, const char *classname) co // passing by reference is not used info->pass_rest_by_reference = false; } +#endif /** * End of namespace diff --git a/src/includes.h b/src/includes.h index 18e9951..e99328c 100644 --- a/src/includes.h +++ b/src/includes.h @@ -75,3 +75,19 @@ #include "methodmember.h" #include "arithmetic.h" +#ifndef ZVAL_COPY_VALUE +#define ZVAL_COPY_VALUE(z, v) \ + do { \ + (z)->value = (v)->value; \ + Z_TYPE_P(z) = Z_TYPE_P(v); \ + } while (0) +#endif + +#ifndef INIT_PZVAL_COPY +#define INIT_PZVAL_COPY(z, v) \ + do { \ + ZVAL_COPY_VALUE(z, v); \ + Z_SET_REFCOUNT_P(z, 1); \ + Z_UNSET_ISREF_P(z); \ + } while (0) +#endif diff --git a/src/longmember.h b/src/longmember.h index 2d0be50..b35c316 100644 --- a/src/longmember.h +++ b/src/longmember.h @@ -51,7 +51,11 @@ public: */ virtual void declare(struct _zend_class_entry *entry, const char *name, int size, int flags) { +#if PHP_VERSION_ID >= 50400 zend_declare_property_long(entry, name, size, _value, flags); +#else + zend_declare_property_long(entry, (char *) name, size, _value, flags); +#endif } }; diff --git a/src/nullmember.h b/src/nullmember.h index 6312709..3fdb6b3 100644 --- a/src/nullmember.h +++ b/src/nullmember.h @@ -43,7 +43,11 @@ public: */ virtual void declare(struct _zend_class_entry *entry, const char *name, int size, int flags) { +#if PHP_VERSION_ID >= 50400 zend_declare_property_null(entry, name, size, flags); +#else + zend_declare_property_null(entry, (char *) name, size, flags); +#endif } }; diff --git a/src/stringmember.h b/src/stringmember.h index 83432e3..d5af4a5 100644 --- a/src/stringmember.h +++ b/src/stringmember.h @@ -58,7 +58,11 @@ public: */ virtual void declare(struct _zend_class_entry *entry, const char *name, int size, int flags) { - zend_declare_property_stringl(entry, name, size, _value.c_str(), _value.size(), flags); +#if PHP_VERSION_ID >= 50400 + zend_declare_property_stringl(entry, name, size, _value.c_str(), _value.size(), flags); +#else + zend_declare_property_stringl(entry, (char*) name, size, (char *) _value.c_str(), _value.size(), flags); +#endif } }; |