PHP 8 compatibility
authorMichael Wallner <mike@php.net>
Wed, 23 Sep 2020 18:07:32 +0000 (20:07 +0200)
committerMichael Wallner <mike@php.net>
Wed, 23 Sep 2020 18:07:32 +0000 (20:07 +0200)
16 files changed:
src/php_pq_callback.h
src/php_pq_misc.c
src/php_pq_misc.h
src/php_pq_object.c
src/php_pq_object.h
src/php_pq_params.c
src/php_pqcancel.c
src/php_pqconn.c
src/php_pqcopy.c
src/php_pqcur.c
src/php_pqlob.c
src/php_pqres.c
src/php_pqstm.c
src/php_pqtxn.c
src/php_pqtypes.c
tests/exceptions001.phpt

index efcbd96d91045b3635db0028d408c171cd61c8d0..32fe012f6e3612214c34166bd6513707d0d758ea 100644 (file)
@@ -21,6 +21,8 @@ typedef struct php_pq_callback {
        struct php_pq_callback *recursion;
 } php_pq_callback_t;
 
+#define PHP_PQ_CALLBACK_INIT {{0},{0},NULL}
+
 extern void php_pq_callback_dtor(php_pq_callback_t *cb);
 extern void php_pq_callback_addref(php_pq_callback_t *cb);
 extern zval *php_pq_callback_to_zval(php_pq_callback_t *cb, zval *tmp);
index 619559d0fe724d393d299b72b467c0b84cd5a673..dee39d6913932c6466427a565ed6eba17f7c9438 100644 (file)
@@ -103,10 +103,10 @@ const char *php_pq_strmode(long mode)
        }
 }
 
-int php_pq_compare_index(const void *lptr, const void *rptr)
+int php_pq_compare_index_80(Bucket *lptr, Bucket *rptr)
 {
-       zend_ulong l = ((const Bucket *) lptr)->h;
-       zend_ulong r = ((const Bucket *) rptr)->h;
+       zend_ulong l = lptr->h;
+       zend_ulong r = rptr->h;
 
        if (l < r) {
                return -1;
@@ -116,6 +116,9 @@ int php_pq_compare_index(const void *lptr, const void *rptr)
        }
        return 0;
 }
+int php_pq_compare_index_70(const void *lptr, const void *rptr) {
+       return php_pq_compare_index_80((Bucket *) lptr, (Bucket *) rptr);
+}
 
 void php_pq_hash_ptr_dtor(zval *p)
 {
@@ -131,8 +134,7 @@ static PHP_METHOD(pqdt, __toString)
        zval rv, tmp;
 
        ZVAL_NULL(&rv);
-       zend_call_method_with_1_params(getThis(), php_pqdt_class_entry, NULL, "format", &rv,
-                       zend_read_property(php_pqdt_class_entry, getThis(), ZEND_STRL("format"), 0, &tmp));
+       php_pq_call_method(getThis(), "format", 1, &rv, php_pq_read_property(getThis(), "format", &tmp));
        RETVAL_ZVAL(&rv, 1, 1);
 }
 
@@ -169,7 +171,7 @@ static zend_function_entry php_pqdt_methods[] = {
        {0}
 };
 
-zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_len, char *output_fmt, zval *ztimezone)
+zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_len, const char *output_fmt, zval *ztimezone)
 {
        php_date_obj *dobj;
 
@@ -179,7 +181,10 @@ zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_le
                zval_dtor(zv);
                ZVAL_NULL(zv);
        } else if (output_fmt) {
-               zend_update_property_string(php_pqdt_class_entry, zv, ZEND_STRL("format"), output_fmt);
+               zval fmt;
+               ZVAL_STRING(&fmt, output_fmt);
+               php_pq_update_property(zv, "format", &fmt);
+               zval_ptr_dtor(&fmt);
        }
 
        return zv;
@@ -191,16 +196,14 @@ zend_string *php_pqdt_to_string(zval *zdt, const char *format)
 
        ZVAL_NULL(&rv);
 
-       if (Z_OBJ_HT_P(zdt)->cast_object
-       &&      SUCCESS == Z_OBJ_HT_P(zdt)->cast_object(zdt, &rv, IS_STRING)
-       ) {
+       if (php_pq_cast_object(zdt, IS_STRING, &rv)) {
                return Z_STR(rv);
        } else if (instanceof_function(Z_OBJCE_P(zdt), php_date_get_date_ce())) {
                zval rv, zfmt;
 
                ZVAL_NULL(&rv);
                ZVAL_STRING(&zfmt, format);
-               zend_call_method_with_1_params(zdt, Z_OBJCE_P(zdt), NULL, "format", &rv, &zfmt);
+               php_pq_call_method(zdt, "format", 1, &rv, &zfmt);
                zval_ptr_dtor(&zfmt);
 
                if (Z_TYPE(rv) == IS_STRING) {
index bffa9d42d181dce3b8bb089be6134000f779bbfe..1672567d844fb9ec7f71f9e5f18cb0e4c5265df5 100644 (file)
@@ -41,7 +41,13 @@ extern char *php_pq_rtrim(char *e);
 extern const char *php_pq_strmode(long mode);
 
 /* compare array index */
-extern int php_pq_compare_index(const void *lptr, const void *rptr);
+#if PHP_VERSION_ID >= 80000
+# define php_pq_compare_index php_pq_compare_index_80
+#else
+# define php_pq_compare_index php_pq_compare_index_70
+#endif
+extern int php_pq_compare_index_80(Bucket *lptr, Bucket *rptr);
+extern int php_pq_compare_index_70(const void *lptr, const void *rptr);
 
 /* free zval ptr values (as hash dtor) */
 extern void php_pq_hash_ptr_dtor(zval *p);
@@ -50,13 +56,45 @@ extern void php_pq_hash_ptr_dtor(zval *p);
 #define PHP_PQresultErrorMessage(r) php_pq_rtrim(PQresultErrorMessage((r)))
 
 extern zend_class_entry *php_pqdt_class_entry;
-extern zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_len, char *output_fmt, zval *ztimezone);
+extern zval *php_pqdt_from_string(zval *zv, char *input_fmt, char *dt_str, size_t dt_len, const char *output_fmt, zval *ztimezone);
 extern zend_string *php_pqdt_to_string(zval *zdt, const char *format);
 
 extern zend_class_entry *php_pqconv_class_entry;
 
 extern HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_len, Oid typ);
 
+/* ZE compat */
+#if PHP_VERSION_ID >= 80000
+# define php_pq_call_method(objval_ptr, method_name, num_args, ...) \
+               zend_call_method_with_ ## num_args ## _params( \
+                               Z_OBJ_P(objval_ptr), Z_OBJCE_P(objval_ptr), NULL, \
+                               (method_name), __VA_ARGS__)
+# define php_pq_read_property(objval_ptr, prop_name, tmpval_ptr) \
+               zend_read_property(Z_OBJCE_P(objval_ptr), Z_OBJ_P(objval_ptr), \
+                               (prop_name), strlen(prop_name), 0, (tmpval_ptr))
+# define php_pq_update_property(objval_ptr, prop_name, newval_ptr) \
+               zend_update_property(Z_OBJCE_P(objval_ptr), Z_OBJ_P(objval_ptr), \
+                               (prop_name), strlen(prop_name), (newval_ptr))
+#define php_pq_cast_object(objval_ptr, cast_type, retval_ptr) \
+               (Z_OBJ_HT_P(objval_ptr)->cast_object && \
+                               SUCCESS == Z_OBJ_HT_P(objval_ptr)->cast_object(Z_OBJ_P(objval_ptr), (retval_ptr), (cast_type)))
+#else
+# define php_pq_call_method(objval_ptr, method_name, num_args, ...) \
+               zend_call_method_with_ ## num_args ## _params( \
+                               (objval_ptr), NULL, NULL, \
+                               (method_name), __VA_ARGS__)
+# define php_pq_read_property(objval_ptr, prop_name, tmpval_ptr) \
+               zend_read_property(Z_OBJCE_P(objval_ptr), (objval_ptr), \
+                               (prop_name), strlen(prop_name), 0, (tmpval_ptr))
+# define php_pq_update_property(objval_ptr, prop_name, newval_ptr) \
+               zend_update_property(Z_OBJCE_P(objval_ptr), (objval_ptr), \
+                               (prop_name), strlen(prop_name), (newval_ptr))
+#define php_pq_cast_object(objval_ptr, cast_type, retval_ptr) \
+               (Z_OBJ_HT_P(objval_ptr)->cast_object && \
+                               SUCCESS == Z_OBJ_HT_P(objval_ptr)->cast_object(objval_ptr, (retval_ptr), (cast_type)))
+#endif
+
+
 
 extern PHP_MINIT_FUNCTION(pq_misc);
 
index b9ce32d5c9dac4bf8c2cac77eadbfc9049fe0891..23e592918a3c16962e874a295abb3fb3e98bb019 100644 (file)
@@ -78,7 +78,6 @@ void php_pq_object_delref(void *o)
 
 struct apply_pi_to_ht_arg {
        HashTable *ht;
-       zval *object;
        php_pq_object_t *pq_obj;
        unsigned gc:1;
 };
@@ -96,19 +95,19 @@ static int apply_pi_to_ht(zval *p, void *a)
 
                        ZVAL_STR(&member, pi->name);
                        ZVAL_ARR(&return_value, arg->ht);
-                       handler->gc(arg->object, arg->pq_obj, &return_value);
+                       handler->gc(arg->pq_obj, &return_value);
                }
        } else {
                zval tmp_prop, *property = NULL;
 
-               property = zend_read_property(arg->pq_obj->zo.ce, arg->object, pi->name->val, pi->name->len, 0, &tmp_prop);
+               property = php_pq_object_read_prop_80(&arg->pq_obj->zo, pi->name, BP_VAR_R, NULL, &tmp_prop);
                zend_hash_update(arg->ht, pi->name, property);
        }
 
        return ZEND_HASH_APPLY_KEEP;
 }
 
-HashTable *php_pq_object_debug_info(zval *object, int *temp)
+HashTable *php_pq_object_debug_info_80(zend_object *object, int *temp)
 {
        struct apply_pi_to_ht_arg arg = {NULL};
 
@@ -116,35 +115,41 @@ HashTable *php_pq_object_debug_info(zval *object, int *temp)
        ALLOC_HASHTABLE(arg.ht);
        ZEND_INIT_SYMTABLE(arg.ht);
 
-       arg.object = object;
-       arg.pq_obj = PHP_PQ_OBJ(object, NULL);
+       arg.pq_obj = PHP_PQ_OBJ(NULL, object);
        arg.gc = 0;
 
        zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg);
 
        return arg.ht;
 }
+HashTable *php_pq_object_debug_info_70(zval *object, int *temp)
+{
+       return php_pq_object_debug_info_80(Z_OBJ_P(object), temp);
+}
 
-HashTable *php_pq_object_properties(zval *object)
+HashTable *php_pq_object_properties_80(zend_object *object)
 {
        struct apply_pi_to_ht_arg arg = {NULL};
 
        arg.ht = zend_get_std_object_handlers()->get_properties(object);
-       arg.object = object;
-       arg.pq_obj = PHP_PQ_OBJ(object, NULL);
+       arg.pq_obj = PHP_PQ_OBJ(NULL, object);
        arg.gc = 0;
 
        zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg);
 
        return arg.ht;
+
+}
+HashTable *php_pq_object_properties_70(zval *object)
+{
+       return php_pq_object_properties_80(Z_OBJ_P(object));
 }
 
-HashTable *php_pq_object_get_gc(zval *object, zval **table, int *n)
+HashTable *php_pq_object_get_gc_80(zend_object *object, zval **table, int *n)
 {
        struct apply_pi_to_ht_arg arg = {NULL};
 
-       arg.object = object;
-       arg.pq_obj = PHP_PQ_OBJ(object, NULL);
+       arg.pq_obj = PHP_PQ_OBJ(NULL, object);
        arg.ht = &arg.pq_obj->gc;
        arg.gc = 1;
 
@@ -157,6 +162,10 @@ HashTable *php_pq_object_get_gc(zval *object, zval **table, int *n)
 
        return arg.ht;
 }
+HashTable *php_pq_object_get_gc_70(zval *object, zval **table, int *n)
+{
+       return php_pq_object_get_gc_80(Z_OBJ_P(object), table, n);
+}
 
 zend_class_entry *ancestor(zend_class_entry *ce)
 {
@@ -166,9 +175,9 @@ zend_class_entry *ancestor(zend_class_entry *ce)
        return ce;
 }
 
-zval *php_pq_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
+zval *php_pq_object_read_prop_80(zend_object *object, zend_string *member, int type, void **cache_slot, zval *tmp)
 {
-       php_pq_object_t *obj = PHP_PQ_OBJ(object, NULL);
+       php_pq_object_t *obj = PHP_PQ_OBJ(NULL, object);
        php_pq_object_prophandler_t *handler;
        zval *return_value = NULL;
 
@@ -176,25 +185,15 @@ zval *php_pq_object_read_prop(zval *object, zval *member, int type, void **cache
 
        if (!obj->intern) {
                php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name->val);
-       } else if (!(handler = zend_hash_find_ptr(obj->prophandler, Z_STR_P(member))) || !handler->read) {
+       } else if (!(handler = zend_hash_find_ptr(obj->prophandler, member)) || !handler->read) {
                /* default handler */
        } else if (type != BP_VAR_R) {
                php_error(E_WARNING, "Cannot access %s properties by reference or array key/index", ancestor(obj->zo.ce)->name->val);
        } else {
-               handler->read(object, obj, tmp);
+               handler->read(obj, tmp);
                zend_get_std_object_handlers()->write_property(object, member, tmp, cache_slot);
                return_value = tmp;
 
-               /*
-               zval dtor;
-
-               ZVAL_COPY_VALUE(&dtor, return_value);
-
-               ZVAL_ZVAL(return_value, tmp, 0, 0);
-               zval_ptr_dtor(&dtor);
-
-               */
-
                if (cache_slot) {
                        *cache_slot = NULL;
                }
@@ -202,28 +201,52 @@ zval *php_pq_object_read_prop(zval *object, zval *member, int type, void **cache
 
        return return_value;
 }
+zval *php_pq_object_read_prop_74(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
+{
+       zend_string *member_str = zval_get_string(member);
+       zval *return_value = php_pq_object_read_prop_80(Z_OBJ_P(object), member_str, type, cache_slot, tmp);
+       zend_string_release(member_str);
+       return return_value;
+}
+void php_pq_object_read_prop_70(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
+{
+       (void) php_pq_object_read_prop_74(object, member, type, cache_slot, tmp);
+}
 
-php_pq_object_write_prop_t php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
+zval *php_pq_object_write_prop_80(zend_object *object, zend_string *member, zval *value, void **cache_slot)
 {
-       php_pq_object_t *obj = PHP_PQ_OBJ(object, NULL);
+       php_pq_object_t *obj = PHP_PQ_OBJ(NULL, object);
        php_pq_object_prophandler_t *handler;
 
        if (!obj->intern) {
                php_error(E_RECOVERABLE_ERROR, "%s not initialized", ancestor(obj->zo.ce)->name->val);
                zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
-       } else if ((handler = zend_hash_find_ptr(obj->prophandler, Z_STR_P(member)))) {
+       } else if ((handler = zend_hash_find_ptr(obj->prophandler, member))) {
                if (handler->write) {
-                       handler->write(object, obj, value);
+                       handler->write(obj, value);
                }
        } else {
                zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
        }
-#if PHP_VERSION_ID >= 70400
        return value;
-#endif
+}
+zval *php_pq_object_write_prop_74(zval *object, zval *member, zval *value, void **cache_slot)
+{
+       zend_string *member_str = zval_get_string(member);
+       zval *return_value = php_pq_object_write_prop_80(Z_OBJ_P(object), member_str, value, cache_slot);
+       zend_string_release(member_str);
+       return return_value;
+}
+void php_pq_object_write_prop_70(zval *object, zval *member, zval *value, void **cache_slot)
+{
+       (void) php_pq_object_write_prop_74(object, member, value, cache_slot);
 }
 
-zval *php_pq_object_get_prop_ptr_null(zval *object, zval *member, int type, void **cache_slot)
+zval *php_pq_object_get_prop_ptr_null_80(zend_object *object, zend_string *member, int type, void **cache_slot)
+{
+       return NULL;
+}
+zval *php_pq_object_get_prop_ptr_null_70(zval *object, zval *member, int type, void **cache_slot)
 {
        return NULL;
 }
index a274dd4bb2556b901d2ad648f756cacf816b981f..6f45addcf0cff304638c88b86ccab732fc9f335c 100644 (file)
@@ -30,7 +30,9 @@ static inline void *PHP_PQ_OBJ(zval *zv, zend_object *zo) {
        return (void *) (((char *) zo) - zo->handlers->offset);
 }
 
-typedef void (*php_pq_object_prophandler_func_t)(zval *object, void *o, zval *return_value);
+extern zend_class_entry *ancestor(zend_class_entry *ce);
+
+typedef void (*php_pq_object_prophandler_func_t)(void *o, zval *return_value);
 
 typedef struct php_pq_object_prophandler {
        php_pq_object_prophandler_func_t read;
@@ -38,25 +40,68 @@ typedef struct php_pq_object_prophandler {
        php_pq_object_prophandler_func_t gc;
 } php_pq_object_prophandler_t;
 
+extern void php_pq_object_prophandler_dtor(zval *zv);
+
 extern void *php_pq_object_create(zend_class_entry *ce, void *intern, size_t obj_size, zend_object_handlers *oh, HashTable *ph);
 extern void php_pq_object_dtor(zend_object *obj);
 extern void php_pq_object_to_zval(void *o, zval *zv);
 extern void php_pq_object_to_zval_no_addref(void *o, zval *zv);
 extern void php_pq_object_addref(void *o);
 extern void php_pq_object_delref(void *o);
-extern HashTable *php_pq_object_debug_info(zval *object, int *temp);
-extern HashTable *php_pq_object_properties(zval *object);
-HashTable *php_pq_object_get_gc(zval *object, zval **table, int *n);
-extern zend_class_entry *ancestor(zend_class_entry *ce);
-extern zval *php_pq_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp);
-#if PHP_VERSION_ID >= 70400
-typedef zval *php_pq_object_write_prop_t;
+
+#if PHP_VERSION_ID >= 80000
+# define php_pq_object_debug_info php_pq_object_debug_info_80
 #else
-typedef void php_pq_object_write_prop_t;
+# define php_pq_object_debug_info php_pq_object_debug_info_70
 #endif
-extern php_pq_object_write_prop_t php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
-extern zval *php_pq_object_get_prop_ptr_null(zval *object, zval *member, int type, void **cache_slot);
-extern void php_pq_object_prophandler_dtor(zval *zv);
+extern HashTable *php_pq_object_debug_info_80(zend_object *object, int *temp);
+extern HashTable *php_pq_object_debug_info_70(zval *object, int *temp);
+
+#if PHP_VERSION_ID >= 80000
+# define php_pq_object_properties php_pq_object_properties_80
+#else
+# define php_pq_object_properties php_pq_object_properties_70
+#endif
+extern HashTable *php_pq_object_properties_80(zend_object *object);
+extern HashTable *php_pq_object_properties_70(zval *object);
+
+#if PHP_VERSION_ID >= 80000
+# define php_pq_object_get_gc php_pq_object_get_gc_80
+#else
+# define php_pq_object_get_gc php_pq_object_get_gc_70
+#endif
+extern HashTable *php_pq_object_get_gc_80(zend_object *object, zval **table, int *n);
+extern HashTable *php_pq_object_get_gc_70(zval *object, zval **table, int *n);
+
+#if PHP_VERSION_ID >= 80000
+# define php_pq_object_read_prop php_pq_object_read_prop_80
+#elif PHP_VERSION_ID >= 70400
+# define php_pq_object_read_prop php_pq_object_read_prop_74
+#else
+# define php_pq_object_read_prop php_pq_object_read_prop_70
+#endif
+extern zval *php_pq_object_read_prop_80(zend_object *object, zend_string *member, int type, void **cache_slot, zval *tmp);
+extern zval *php_pq_object_read_prop_74(zval *object, zval *member, int type, void **cache_slot, zval *tmp);
+extern void php_pq_object_read_prop_70(zval *object, zval *member, int type, void **cache_slot, zval *tmp);
+
+#if PHP_VERSION_ID >= 80000
+# define php_pq_object_write_prop php_pq_object_write_prop_80
+#elif PHP_VERSION_ID >= 70400
+# define php_pq_object_write_prop php_pq_object_write_prop_74
+#else
+# define php_pq_object_write_prop php_pq_object_write_prop_70
+#endif
+extern zval *php_pq_object_write_prop_80(zend_object *object, zend_string *member, zval *value, void **cache_slot);
+extern zval *php_pq_object_write_prop_74(zval *object, zval *member, zval *value, void **cache_slot);
+extern void php_pq_object_write_prop_70(zval *object, zval *member, zval *value, void **cache_slot);
+
+#if PHP_VERSION_ID >= 80000
+# define php_pq_object_get_prop_ptr_null php_pq_object_get_prop_ptr_null_80
+#else
+# define php_pq_object_get_prop_ptr_null php_pq_object_get_prop_ptr_null_70
+#endif
+extern zval *php_pq_object_get_prop_ptr_null_80(zend_object *object, zend_string *member, int type, void **cache_slot);
+extern zval *php_pq_object_get_prop_ptr_null_70(zval *object, zval *member, int type, void **cache_slot);
 
 #endif
 
index a691eebd62464efbe897c2f91533c064b7f85961..a3ee6b880a401051008b375f1e93c20906674503 100644 (file)
@@ -133,7 +133,7 @@ static int apply_to_param_from_array(zval *zparam, void *arg_ptr)
                zval ztype, rv;
 
                ZVAL_LONG(&ztype, arg->type);
-               zend_call_method_with_2_params(arg->zconv, NULL, NULL, "converttostring", &rv, zparam, &ztype);
+               php_pq_call_method(arg->zconv, "converttostring", 2, &rv, zparam, &ztype);
                tmpstr = zval_get_string(&rv);
                zval_ptr_dtor(&rv);
                goto append_string;
@@ -243,7 +243,7 @@ static void php_pq_params_set_param(php_pq_params_t *p, unsigned index, zval *zp
 
                ZVAL_NULL(&rv);
                ZVAL_LONG(&ztype, type);
-               zend_call_method_with_2_params(zconv, NULL, NULL, "converttostring", &rv, zpp, &ztype);
+               php_pq_call_method(zconv, "converttostring", 2, &rv, zpp, &ztype);
                convert_to_string(&rv);
                p->param.strings[index] = Z_STRVAL_P(&rv);
                zend_hash_next_index_insert(&p->param.dtor, &rv);
index e3b6ed7652304e65b2890686afd6cbaefb0baa48..6b29d806c328e15df9fdaa0ababd2a228b8af653 100644 (file)
@@ -54,14 +54,14 @@ static zend_object *php_pqcancel_create_object(zend_class_entry *class_type)
        return &php_pqcancel_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqcancel_object_read_connection(zval *object, void *o, zval *return_value)
+static void php_pqcancel_object_read_connection(void *o, zval *return_value)
 {
        php_pqcancel_object_t *obj = o;
 
        php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
-static void php_pqcancel_object_gc_connection(zval *object, void *o, zval *return_value)
+static void php_pqcancel_object_gc_connection(void *o, zval *return_value)
 {
        php_pqcancel_object_t *obj = o;
        zval zconn;
index 148d2ffe324f28f4029b9b27c880335143a9bae8..da07ff339a7e1b89dfe9d9f97be983a897e2e592 100644 (file)
@@ -107,21 +107,21 @@ static zend_object *php_pqconn_create_object(zend_class_entry *class_type)
        return &php_pqconn_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqconn_object_read_status(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_status(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(PQstatus(obj->intern->conn));
 }
 
-static void php_pqconn_object_read_transaction_status(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_transaction_status(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(PQtransactionStatus(obj->intern->conn));
 }
 
-static void php_pqconn_object_read_error_message(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_error_message(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *error = PHP_PQerrorMessage(obj->intern->conn);
@@ -176,21 +176,21 @@ void php_pqconn_notify_listeners(php_pqconn_object_t *obj)
        }
 }
 
-static void php_pqconn_object_read_busy(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_busy(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(PQisBusy(obj->intern->conn));
 }
 
-static void php_pqconn_object_read_encoding(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_encoding(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_STRING(pg_encoding_to_char(PQclientEncoding(obj->intern->conn)));
 }
 
-static void php_pqconn_object_write_encoding(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_encoding(void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
        zend_string *zenc = zval_get_string(value);
@@ -202,35 +202,35 @@ static void php_pqconn_object_write_encoding(zval *object, void *o, zval *value)
        zend_string_release(zenc);
 }
 
-static void php_pqconn_object_read_unbuffered(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_unbuffered(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(obj->intern->unbuffered);
 }
 
-static void php_pqconn_object_write_unbuffered(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_unbuffered(void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
        obj->intern->unbuffered = z_is_true(value);
 }
 
-static void php_pqconn_object_read_nonblocking(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_nonblocking(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(PQisnonblocking(obj->intern->conn));
 }
 
-static void php_pqconn_object_write_nonblocking(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_nonblocking(void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
        PQsetnonblocking(obj->intern->conn, z_is_true(value));
 }
 
-static void php_pqconn_object_read_db(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_db(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *db = PQdb(obj->intern->conn);
@@ -242,7 +242,7 @@ static void php_pqconn_object_read_db(zval *object, void *o, zval *return_value)
        }
 }
 
-static void php_pqconn_object_read_user(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_user(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *user = PQuser(obj->intern->conn);
@@ -254,7 +254,7 @@ static void php_pqconn_object_read_user(zval *object, void *o, zval *return_valu
        }
 }
 
-static void php_pqconn_object_read_pass(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_pass(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *pass = PQpass(obj->intern->conn);
@@ -266,7 +266,7 @@ static void php_pqconn_object_read_pass(zval *object, void *o, zval *return_valu
        }
 }
 
-static void php_pqconn_object_read_host(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_host(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *host = PQhost(obj->intern->conn);
@@ -278,7 +278,7 @@ static void php_pqconn_object_read_host(zval *object, void *o, zval *return_valu
        }
 }
 
-static void php_pqconn_object_read_port(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_port(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *port = PQport(obj->intern->conn);
@@ -291,7 +291,7 @@ static void php_pqconn_object_read_port(zval *object, void *o, zval *return_valu
 }
 
 #if HAVE_PQCONNINFO
-static void php_pqconn_object_read_params(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_params(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        PQconninfoOption *ptr, *params = PQconninfo(obj->intern->conn);
@@ -311,7 +311,7 @@ static void php_pqconn_object_read_params(zval *object, void *o, zval *return_va
 }
 #endif
 
-static void php_pqconn_object_read_options(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_options(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        char *options = PQoptions(obj->intern->conn);
@@ -350,7 +350,7 @@ static int apply_read_callbacks(zval *p, int argc, va_list argv, zend_hash_key *
 
        return ZEND_HASH_APPLY_KEEP;
 }
-static void php_pqconn_object_read_event_handlers(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_event_handlers(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
@@ -358,7 +358,7 @@ static void php_pqconn_object_read_event_handlers(zval *object, void *o, zval *r
        zend_hash_apply_with_arguments(&obj->intern->eventhandlers, apply_read_callbacks, 1, Z_ARRVAL_P(return_value));
 }
 
-static void php_pqconn_object_gc_event_handlers(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_gc_event_handlers(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        zval *evhs;
@@ -378,7 +378,7 @@ static void php_pqconn_object_gc_event_handlers(zval *object, void *o, zval *ret
        ZEND_HASH_FOREACH_END();
 }
 
-static void php_pqconn_object_read_listeners(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_listeners(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
@@ -386,7 +386,7 @@ static void php_pqconn_object_read_listeners(zval *object, void *o, zval *return
        zend_hash_apply_with_arguments(&obj->intern->listeners, apply_read_callbacks, 1, Z_ARRVAL_P(return_value));
 }
 
-static void php_pqconn_object_gc_listeners(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_gc_listeners(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        zval *listeners;
@@ -406,7 +406,7 @@ static void php_pqconn_object_gc_listeners(zval *object, void *o, zval *return_v
        ZEND_HASH_FOREACH_END();
 }
 
-static void php_pqconn_object_read_converters(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_converters(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
@@ -414,7 +414,7 @@ static void php_pqconn_object_read_converters(zval *object, void *o, zval *retur
        zend_hash_copy(Z_ARRVAL_P(return_value), &obj->intern->converters, zval_add_ref);
 }
 
-static void php_pqconn_object_gc_converters(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_gc_converters(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
        zval *converter;
@@ -426,65 +426,65 @@ static void php_pqconn_object_gc_converters(zval *object, void *o, zval *return_
        ZEND_HASH_FOREACH_END();
 }
 
-static void php_pqconn_object_read_def_fetch_type(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_fetch_type(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->default_fetch_type);
 }
-static void php_pqconn_object_write_def_fetch_type(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_def_fetch_type(void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
        obj->intern->default_fetch_type = zval_get_long(value) & 0x3; /* two bits only */
 }
 
-static void php_pqconn_object_read_def_txn_isolation(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_txn_isolation(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->default_txn_isolation);
 }
-static void php_pqconn_object_write_def_txn_isolation(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_def_txn_isolation(void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
        obj->intern->default_txn_isolation = zval_get_long(value) & 0x3; /* two bits only */
 }
 
-static void php_pqconn_object_read_def_txn_readonly(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_txn_readonly(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(obj->intern->default_txn_readonly);
 }
-static void php_pqconn_object_write_def_txn_readonly(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_def_txn_readonly(void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
        obj->intern->default_txn_readonly = z_is_true(value);
 }
 
-static void php_pqconn_object_read_def_txn_deferrable(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_txn_deferrable(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_BOOL(obj->intern->default_txn_deferrable);
 }
-static void php_pqconn_object_write_def_txn_deferrable(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_def_txn_deferrable(void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
        obj->intern->default_txn_deferrable = zend_is_true(value);
 }
 
-static void php_pqconn_object_read_def_auto_conv(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_auto_conv(void *o, zval *return_value)
 {
        php_pqconn_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->default_auto_convert);
 }
-static void php_pqconn_object_write_def_auto_conv(zval*object, void *o, zval *value)
+static void php_pqconn_object_write_def_auto_conv(void *o, zval *value)
 {
        php_pqconn_object_t *obj = o;
 
@@ -514,7 +514,11 @@ static ZEND_RESULT_CODE php_pqconn_update_socket(zval *zobj, php_pqconn_object_t
                ZVAL_NULL(&zsocket);
                retval = FAILURE;
        }
+#if PHP_VERSION_ID >= 80000
+       zend_get_std_object_handlers()->write_property(Z_OBJ_P(zobj), Z_STR(zmember), &zsocket, NULL);
+#else
        zend_get_std_object_handlers()->write_property(zobj, &zmember, &zsocket, NULL);
+#endif
        zval_ptr_dtor(&zsocket);
        zval_ptr_dtor(&zmember);
 
@@ -870,7 +874,7 @@ static PHP_METHOD(pqconn, listen) {
        zend_error_handling zeh;
        char *channel_str = NULL;
        size_t channel_len = 0;
-       php_pq_callback_t listener = {{0}};
+       php_pq_callback_t listener = PHP_PQ_CALLBACK_INIT;
        ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
@@ -924,7 +928,7 @@ static PHP_METHOD(pqconn, listenAsync) {
        zend_error_handling zeh;
        char *channel_str = NULL;
        size_t channel_len = 0;
-       php_pq_callback_t listener = {{0}};
+       php_pq_callback_t listener = PHP_PQ_CALLBACK_INIT;
        ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
@@ -1165,7 +1169,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_exec_async, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, execAsync) {
        zend_error_handling zeh;
-       php_pq_callback_t resolver = {{0}};
+       php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT;
        char *query_str;
        size_t query_len;
        ZEND_RESULT_CODE rv;
@@ -1246,7 +1250,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_exec_params_async, 0, 0, 2)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqconn, execParamsAsync) {
        zend_error_handling zeh;
-       php_pq_callback_t resolver = {{0}};
+       php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT;
        char *query_str;
        size_t query_len;
        zval *zparams;
@@ -1831,7 +1835,7 @@ static PHP_METHOD(pqconn, on) {
        zend_error_handling zeh;
        char *type_str;
        size_t type_len;
-       php_pq_callback_t cb = {{0}};
+       php_pq_callback_t cb = PHP_PQ_CALLBACK_INIT;
        ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
@@ -1892,7 +1896,7 @@ static PHP_METHOD(pqconn, setConverter) {
                        struct apply_set_converter_arg arg = {NULL};
 
                        ZVAL_NULL(&zoids);
-                       zend_call_method_with_0_params(zcnv, NULL, NULL, "converttypes", &zoids);
+                       php_pq_call_method(zcnv, "converttypes", 0, &zoids);
                        ZVAL_DUP(&tmp, &zoids);
                        convert_to_array(&tmp);
 
@@ -1930,7 +1934,7 @@ static PHP_METHOD(pqconn, unsetConverter) {
                        struct apply_set_converter_arg arg = {NULL};
 
                        ZVAL_NULL(&zoids);
-                       zend_call_method_with_0_params(zcnv, NULL, NULL, "converttypes", &zoids);
+                       php_pq_call_method(zcnv, "converttypes", 0, &zoids);
                        ZVAL_DUP(&tmp, &zoids);
                        convert_to_array(&tmp);
 
index 1ab3ad984f561099fab0c4c928c564aace4f4e9f..e0a80297ed5d83612bc2016cfbd15994f5b8bd48 100644 (file)
@@ -58,14 +58,14 @@ static zend_object *php_pqcopy_create_object(zend_class_entry *class_type)
        return &php_pqcopy_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqcopy_object_read_connection(zval *object, void *o, zval *return_value)
+static void php_pqcopy_object_read_connection(void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
 
        php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
-static void php_pqcopy_object_gc_connection(zval *object, void *o, zval *return_value)
+static void php_pqcopy_object_gc_connection(void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
        zval zconn;
@@ -74,21 +74,21 @@ static void php_pqcopy_object_gc_connection(zval *object, void *o, zval *return_
        add_next_index_zval(return_value, &zconn);
 }
 
-static void php_pqcopy_object_read_direction(zval *object, void *o, zval *return_value)
+static void php_pqcopy_object_read_direction(void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->direction);
 }
 
-static void php_pqcopy_object_read_expression(zval *object, void *o, zval *return_value)
+static void php_pqcopy_object_read_expression(void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
 
        RETURN_STRING(obj->intern->expression);
 }
 
-static void php_pqcopy_object_read_options(zval *object, void *o, zval *return_value)
+static void php_pqcopy_object_read_options(void *o, zval *return_value)
 {
        php_pqcopy_object_t *obj = o;
 
index 6dcd83e3823222ba63678ca7bd9e3395f5da3315..1f639b65e132e26a97dc83ff22a6e76f58576671 100644 (file)
@@ -98,7 +98,7 @@ static void cur_fetch_or_move(INTERNAL_FUNCTION_PARAMETERS, const char *action,
        char *spec_str = "1";
        size_t spec_len = 1;
        ZEND_RESULT_CODE rv;
-       php_pq_callback_t resolver = {{0}};
+       php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT;
        zend_error_handling zeh;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
@@ -176,21 +176,21 @@ static zend_object *php_pqcur_create_object(zend_class_entry *class_type)
        return &php_pqcur_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqcur_object_read_name(zval *object, void *o, zval *return_value)
+static void php_pqcur_object_read_name(void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
 
        RETVAL_STRING(obj->intern->name);
 }
 
-static void php_pqcur_object_read_connection(zval *object, void *o, zval *return_value)
+static void php_pqcur_object_read_connection(void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
 
        php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
-static void php_pqcur_object_gc_connection(zval *object, void *o, zval *return_value)
+static void php_pqcur_object_gc_connection(void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
        zval zconn;
@@ -199,14 +199,14 @@ static void php_pqcur_object_gc_connection(zval *object, void *o, zval *return_v
        add_next_index_zval(return_value, &zconn);
 }
 
-static void php_pqcur_object_read_query(zval *object, void *o, zval *return_value)
+static void php_pqcur_object_read_query(void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
 
        RETVAL_STRING(obj->intern->decl + obj->intern->query_offset);
 }
 
-static void php_pqcur_object_read_flags(zval *object, void *o, zval *return_value)
+static void php_pqcur_object_read_flags(void *o, zval *return_value)
 {
        php_pqcur_object_t *obj = o;
 
@@ -409,7 +409,7 @@ static zend_function_entry php_pqcur_methods[] = {
        PHP_ME(pqcur, move, ai_pqcur_move, ZEND_ACC_PUBLIC)
        PHP_ME(pqcur, fetchAsync, ai_pqcur_fetchAsync, ZEND_ACC_PUBLIC)
        PHP_ME(pqcur, moveAsync, ai_pqcur_moveAsync, ZEND_ACC_PUBLIC)
-       {NULL, NULL, NULL}
+       {0}
 };
 
 PHP_MSHUTDOWN_FUNCTION(pqcur)
index 006eb751abde6fd2615013aa23bc12a0a84696f6..0fc04443e86db93d407b7bd513cd486010b3d44a 100644 (file)
@@ -61,14 +61,14 @@ static zend_object *php_pqlob_create_object(zend_class_entry *class_type)
        return &php_pqlob_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqlob_object_read_transaction(zval *object, void *o, zval *return_value)
+static void php_pqlob_object_read_transaction(void *o, zval *return_value)
 {
        php_pqlob_object_t *obj = o;
 
        php_pq_object_to_zval(obj->intern->txn, return_value);
 }
 
-static void php_pqlob_object_gc_transaction(zval *object, void *o, zval *return_value)
+static void php_pqlob_object_gc_transaction(void *o, zval *return_value)
 {
        php_pqlob_object_t *obj = o;
        zval ztxn;
@@ -77,22 +77,22 @@ static void php_pqlob_object_gc_transaction(zval *object, void *o, zval *return_
        add_next_index_zval(return_value, &ztxn);
 }
 
-static void php_pqlob_object_read_oid(zval *object, void *o, zval *return_value)
+static void php_pqlob_object_read_oid(void *o, zval *return_value)
 {
        php_pqlob_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->loid);
 }
 
-static void php_pqlob_object_update_stream(zval *this_ptr, php_pqlob_object_t *obj, zval *zstream);
+static void php_pqlob_object_update_stream(php_pqlob_object_t *obj, zval *zstream);
 
-static void php_pqlob_object_read_stream(zval *object, void *o, zval *return_value)
+static void php_pqlob_object_read_stream(void *o, zval *return_value)
 {
        php_pqlob_object_t *obj = o;
        zval zstream;
 
        if (!obj->intern->stream) {
-               php_pqlob_object_update_stream(object, obj, &zstream);
+               php_pqlob_object_update_stream(obj, &zstream);
        } else {
                php_stream_to_zval(obj->intern->stream, &zstream);
        }
@@ -100,10 +100,10 @@ static void php_pqlob_object_read_stream(zval *object, void *o, zval *return_val
        RETVAL_ZVAL(&zstream, 1, 0);
 }
 
-static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length)
+static ssize_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length)
 {
        php_pqlob_object_t *obj = stream->abstract;
-       int written = 0;
+       ssize_t written = 0;
 
        if (obj) {
                written = lo_write(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, buffer, length);
@@ -118,10 +118,10 @@ static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, siz
        return written;
 }
 
-static size_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t length)
+static ssize_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t length)
 {
        php_pqlob_object_t *obj = stream->abstract;
-       int read = 0;
+       ssize_t read = 0;
 
        if (obj) {
 
@@ -191,20 +191,22 @@ static php_stream_ops php_pqlob_stream_ops = {
        NULL, /* set_option */
 };
 
-static void php_pqlob_object_update_stream(zval *zpqlob, php_pqlob_object_t *obj, zval *zstream)
+static void php_pqlob_object_update_stream(php_pqlob_object_t *obj, zval *zstream)
 {
-       zval zmember;
+       zval zobj, zmember;
 
        ZVAL_STRINGL(&zmember, "stream", sizeof("stream")-1);
 
-       if (!obj) {
-               obj = PHP_PQ_OBJ(zpqlob, NULL);
-       }
        obj->intern->stream = php_stream_alloc(&php_pqlob_stream_ops, obj, NULL, "r+b");
        obj->intern->stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
        php_stream_to_zval(obj->intern->stream, zstream);
 
+#if PHP_VERSION_ID >= 80000
+       zend_get_std_object_handlers()->write_property(&obj->zo, Z_STR(zmember), zstream, NULL);
+#else
+       ZVAL_OBJ(&zobj, &obj->zo);
        zend_get_std_object_handlers()->write_property(zpqlob, &zmember, zstream, NULL);
+#endif
        zval_ptr_dtor(&zmember);
 }
 
index 3427b383414ab39d7d430adb0174850aac00229e..154cd961a39a0eb4d5f5d0ebdc83f494686b4459 100644 (file)
@@ -45,7 +45,7 @@ static inline zend_object_iterator *php_pqres_iterator_init_ex(zend_class_entry
        iter->zi.funcs = &php_pqres_iterator_funcs;
        ZVAL_COPY_VALUE(&iter->zi.data, object);
 
-       zfetch_type = zend_read_property(ce, object, ZEND_STRL("fetchType"), 0, &tmp);
+       zfetch_type = php_pq_read_property(object, "fetchType", &tmp);
        iter->fetch_type = zval_get_long(zfetch_type);
 #if DBG_GC
        fprintf(stderr, "INIT iter(#%d) %p res(#%d) %p\n", iter->zi.std.handle, iter, Z_OBJ_HANDLE_P(object), PHP_PQ_OBJ(object, NULL));
@@ -134,7 +134,7 @@ zval *php_pqres_typed_zval(php_pqres_t *res, Oid typ, zval *zv)
 
                ZVAL_NULL(&rv);
                ZVAL_LONG(&ztype, typ);
-               zend_call_method_with_2_params(zconv, NULL, NULL, "convertfromstring", &rv, zv, &ztype);
+               php_pq_call_method(zconv, "convertfromstring", 2, &rv, zv, &ztype);
 
                zval_ptr_dtor(zv);
                ZVAL_ZVAL(zv, &rv, 0, 0);
@@ -378,11 +378,19 @@ static zend_object_iterator_funcs php_pqres_iterator_funcs = {
        php_pqres_iterator_rewind,
        /* invalidate current value/key (optional, may be NULL) */
        php_pqres_iterator_invalidate
+#if PHP_VERSION_ID >= 80000
+       , NULL
+#endif
 };
 
-static ZEND_RESULT_CODE php_pqres_count_elements(zval *object, long *count)
+#if PHP_VERSION_ID >= 80000
+# define php_pqres_count_elements php_pqres_count_elements_80
+#else
+# define php_pqres_count_elements php_pqres_count_elements_70
+#endif
+static ZEND_RESULT_CODE php_pqres_count_elements_80(zend_object *object, long *count)
 {
-       php_pqres_object_t *obj = PHP_PQ_OBJ(object, NULL);
+       php_pqres_object_t *obj = PHP_PQ_OBJ(NULL, object);
 
        if (!obj->intern) {
                return FAILURE;
@@ -391,17 +399,23 @@ static ZEND_RESULT_CODE php_pqres_count_elements(zval *object, long *count)
                return SUCCESS;
        }
 }
+static ZEND_RESULT_CODE php_pqres_count_elements_70(zval *object, long *count)
+{
+       return php_pqres_count_elements_80(Z_OBJ_P(object), count);
+}
 
 ZEND_RESULT_CODE php_pqres_success(PGresult *res)
 {
-       zval zexc;
+       zval zexc, zsqlstate;
 
        switch (PQresultStatus(res)) {
        case PGRES_BAD_RESPONSE:
        case PGRES_NONFATAL_ERROR:
        case PGRES_FATAL_ERROR:
                ZVAL_OBJ(&zexc, throw_exce(EX_SQL, "%s", PHP_PQresultErrorMessage(res)));
-               zend_update_property_string(Z_OBJCE(zexc), &zexc, ZEND_STRL("sqlstate"), PQresultErrorField(res, PG_DIAG_SQLSTATE));
+               ZVAL_STRING(&zsqlstate, PQresultErrorField(res, PG_DIAG_SQLSTATE));
+               php_pq_update_property(&zexc, "sqlstate", &zsqlstate);
+               zval_ptr_dtor(&zsqlstate);
                return FAILURE;
        default:
                return SUCCESS;
@@ -465,21 +479,21 @@ static zend_object *php_pqres_create_object(zend_class_entry *class_type)
        return &php_pqres_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqres_object_read_status(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_status(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
 
        RETVAL_LONG(PQresultStatus(obj->intern->res));
 }
 
-static void php_pqres_object_read_status_message(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_status_message(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
 
        RETVAL_STRING(PQresStatus(PQresultStatus(obj->intern->res))+sizeof("PGRES"));
 }
 
-static void php_pqres_object_read_error_message(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_error_message(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
        char *error = PHP_PQresultErrorMessage(obj->intern->res);
@@ -543,7 +557,7 @@ static void php_pqres_object_read_error_message(zval *object, void *o, zval *ret
 # define PG_DIAG_SOURCE_FUNCTION 'R'
 #endif
 
-static void php_pqres_object_read_diag(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_diag(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
        int i;
@@ -582,52 +596,55 @@ static void php_pqres_object_read_diag(zval *object, void *o, zval *return_value
        }
 }
 
-static void php_pqres_object_read_num_rows(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_num_rows(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
 
        RETVAL_LONG(PQntuples(obj->intern->res));
 }
 
-static void php_pqres_object_read_num_cols(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_num_cols(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
 
        RETVAL_LONG(PQnfields(obj->intern->res));
 }
 
-static void php_pqres_object_read_affected_rows(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_affected_rows(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
 
        RETVAL_LONG(atoi(PQcmdTuples(obj->intern->res)));
 }
 
-static void php_pqres_object_read_fetch_type(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_fetch_type(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
 
        RETVAL_LONG(php_pqres_fetch_type(obj->intern));
 }
 
-static void php_pqres_object_write_fetch_type(zval *object, void *o, zval *value)
+static void php_pqres_object_write_fetch_type(void *o, zval *value)
 {
        php_pqres_object_t *obj = o;
 
        if (!obj->intern->iter) {
-               php_pqres_internal_iterator_init(object);
+               zval object;
+
+               ZVAL_OBJ(&object, &obj->zo);
+               php_pqres_internal_iterator_init(&object);
        }
        obj->intern->iter->fetch_type = zval_get_long(value);
 }
 
-static void php_pqres_object_read_auto_conv(zval *object, void *o, zval *return_value)
+static void php_pqres_object_read_auto_conv(void *o, zval *return_value)
 {
        php_pqres_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->auto_convert);
 }
 
-static void php_pqres_object_write_auto_conv(zval *object, void *o, zval *value)
+static void php_pqres_object_write_auto_conv(void *o, zval *value)
 {
        php_pqres_object_t *obj = o;
 
@@ -1140,7 +1157,7 @@ static PHP_METHOD(pqres, count) {
        if (SUCCESS == rv) {
                long count;
 
-               if (SUCCESS != php_pqres_count_elements(getThis(), &count)) {
+               if (SUCCESS != php_pqres_count_elements_70(getThis(), &count)) {
                        throw_exce(EX_UNINITIALIZED, "pq\\Result not initialized");
                } else {
                        RETVAL_LONG(count);
@@ -1174,6 +1191,14 @@ static PHP_METHOD(pqres, desc) {
        }
 }
 
+ZEND_BEGIN_ARG_INFO_EX(ai_pqres_getIterator, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqres, getIterator)
+{
+       ZEND_PARSE_PARAMETERS_NONE();
+       zend_create_internal_iterator_zval(return_value, ZEND_THIS);
+}
+
 static zend_function_entry php_pqres_methods[] = {
        PHP_ME(pqres, bind, ai_pqres_bind, ZEND_ACC_PUBLIC)
        PHP_ME(pqres, fetchBound, ai_pqres_fetch_bound, ZEND_ACC_PUBLIC)
@@ -1184,6 +1209,7 @@ static zend_function_entry php_pqres_methods[] = {
        PHP_ME(pqres, count, ai_pqres_count, ZEND_ACC_PUBLIC)
        PHP_ME(pqres, map, ai_pqres_map, ZEND_ACC_PUBLIC)
        PHP_ME(pqres, desc, ai_pqres_desc, ZEND_ACC_PUBLIC)
+       PHP_ME(pqres, getIterator, ai_pqres_getIterator, ZEND_ACC_PUBLIC)
        {0}
 };
 
@@ -1202,7 +1228,7 @@ PHP_MINIT_FUNCTION(pqres)
        php_pqres_class_entry = zend_register_internal_class_ex(&ce, NULL);
        php_pqres_class_entry->create_object = php_pqres_create_object;
        php_pqres_class_entry->get_iterator = php_pqres_iterator_init;
-       zend_class_implements(php_pqres_class_entry, 2, zend_ce_traversable, spl_ce_Countable);
+       zend_class_implements(php_pqres_class_entry, 2, zend_ce_aggregate, spl_ce_Countable);
 
        memcpy(&php_pqres_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_pqres_object_handlers.offset = XtOffsetOf(php_pqres_object_t, zo);
index 60f4bc88133d215d71a9aec100d79cd00e2654fe..f421b81b8da8e7362a3b37ff12f821b5b50c02fd 100644 (file)
@@ -102,21 +102,21 @@ static zend_object *php_pqstm_create_object(zend_class_entry *class_type)
        return &php_pqstm_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqstm_object_read_name(zval *object, void *o, zval *return_value)
+static void php_pqstm_object_read_name(void *o, zval *return_value)
 {
        php_pqstm_object_t *obj = o;
 
        RETVAL_STRING(obj->intern->name);
 }
 
-static void php_pqstm_object_read_connection(zval *object, void *o, zval *return_value)
+static void php_pqstm_object_read_connection(void *o, zval *return_value)
 {
        php_pqstm_object_t *obj = o;
 
        php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
-static void php_pqstm_object_gc_connection(zval *object, void *o, zval *return_value)
+static void php_pqstm_object_gc_connection(void *o, zval *return_value)
 {
        php_pqstm_object_t *obj = o;
        zval zconn;
@@ -125,14 +125,14 @@ static void php_pqstm_object_gc_connection(zval *object, void *o, zval *return_v
        add_next_index_zval(return_value, &zconn);
 }
 
-static void php_pqstm_object_read_query(zval *object, void *o, zval *return_value)
+static void php_pqstm_object_read_query(void *o, zval *return_value)
 {
        php_pqstm_object_t *obj = o;
 
        RETVAL_STRING(obj->intern->query);
 }
 
-static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value)
+static void php_pqstm_object_read_types(void *o, zval *return_value)
 {
        int i;
        php_pqstm_object_t *obj = o;
@@ -275,7 +275,7 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqstm, execAsync) {
        zend_error_handling zeh;
        zval *zparams = NULL;
-       php_pq_callback_t resolver = {{0}};
+       php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT;
        ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
@@ -355,7 +355,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc_async, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqstm, descAsync) {
        zend_error_handling zeh;
-       php_pq_callback_t resolver = {{0}};
+       php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT;
        ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
index ebcb44d806e7df3c25869dc0ae4d1592741a2b23..700f22a9133cf39e3f976ce554ecfa899fe6a0fc 100644 (file)
@@ -79,14 +79,14 @@ static zend_object *php_pqtxn_create_object(zend_class_entry *class_type)
        return &php_pqtxn_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqtxn_object_read_connection(zval *object, void *o, zval *return_value)
+static void php_pqtxn_object_read_connection(void *o, zval *return_value)
 {
        php_pqtxn_object_t *obj = o;
 
        php_pq_object_to_zval(obj->intern->conn, return_value);
 }
 
-static void php_pqtxn_object_gc_connection(zval *object, void *o, zval *return_value)
+static void php_pqtxn_object_gc_connection(void *o, zval *return_value)
 {
        php_pqtxn_object_t *obj = o;
        zval zconn;
@@ -95,28 +95,28 @@ static void php_pqtxn_object_gc_connection(zval *object, void *o, zval *return_v
        add_next_index_zval(return_value, &zconn);
 }
 
-static void php_pqtxn_object_read_isolation(zval *object, void *o, zval *return_value)
+static void php_pqtxn_object_read_isolation(void *o, zval *return_value)
 {
        php_pqtxn_object_t *obj = o;
 
        RETVAL_LONG(obj->intern->isolation);
 }
 
-static void php_pqtxn_object_read_readonly(zval *object, void *o, zval *return_value)
+static void php_pqtxn_object_read_readonly(void *o, zval *return_value)
 {
        php_pqtxn_object_t *obj = o;
 
        RETVAL_BOOL(obj->intern->readonly);
 }
 
-static void php_pqtxn_object_read_deferrable(zval *object, void *o, zval *return_value)
+static void php_pqtxn_object_read_deferrable(void *o, zval *return_value)
 {
        php_pqtxn_object_t *obj = o;
 
        RETVAL_BOOL(obj->intern->deferrable);
 }
 
-static void php_pqtxn_object_write_isolation(zval *object, void *o, zval *value)
+static void php_pqtxn_object_write_isolation(void *o, zval *value)
 {
        php_pqtxn_object_t *obj = o;
        php_pqtxn_isolation_t orig = obj->intern->isolation;
@@ -144,7 +144,7 @@ static void php_pqtxn_object_write_isolation(zval *object, void *o, zval *value)
        }
 }
 
-static void php_pqtxn_object_write_readonly(zval *object, void *o, zval *value)
+static void php_pqtxn_object_write_readonly(void *o, zval *value)
 {
        php_pqtxn_object_t *obj = o;
        PGresult *res;
@@ -161,7 +161,7 @@ static void php_pqtxn_object_write_readonly(zval *object, void *o, zval *value)
        }
 }
 
-static void php_pqtxn_object_write_deferrable(zval *object, void *o, zval *value)
+static void php_pqtxn_object_write_deferrable(void *o, zval *value)
 {
        php_pqtxn_object_t *obj = o;
        PGresult *res;
index 5e5ef2ca7c4a75beecc1347b135898b161160843..01e4e321b3604fec460a914bdc713511632beab0 100644 (file)
@@ -54,13 +54,13 @@ static zend_object *php_pqtypes_create_object(zend_class_entry *class_type)
        return &php_pqtypes_create_object_ex(class_type, NULL)->zo;
 }
 
-static void php_pqtypes_object_read_connection(zval *object, void *o, zval *return_value)
+static void php_pqtypes_object_read_connection(void *o, zval *return_value)
 {
        php_pqtypes_object_t *obj = o;
 
        php_pq_object_to_zval(obj->intern->conn, return_value);
 }
-static void php_pqtypes_object_gc_connection(zval *object, void *o, zval *return_value)
+static void php_pqtypes_object_gc_connection(void *o, zval *return_value)
 {
        php_pqtypes_object_t *obj = o;
        zval zconn;
@@ -94,9 +94,14 @@ static int has_dimension(HashTable *ht, zval *member, zend_string **key, zend_lo
        }
 }
 
-static int php_pqtypes_object_has_dimension(zval *object, zval *member, int check_empty)
+#if PHP_VERSION_ID >= 80000
+# define php_pqtypes_object_has_dimension php_pqtypes_object_has_dimension_80
+#else
+# define php_pqtypes_object_has_dimension php_pqtypes_object_has_dimension_70
+#endif
+static int php_pqtypes_object_has_dimension_80(zend_object *object, zval *member, int check_empty)
 {
-       php_pqtypes_object_t *obj = PHP_PQ_OBJ(object, NULL);
+       php_pqtypes_object_t *obj = PHP_PQ_OBJ(NULL, object);
        zend_string *key = NULL;
        zend_long index = 0;
 
@@ -123,10 +128,19 @@ static int php_pqtypes_object_has_dimension(zval *object, zval *member, int chec
 
        return 0;
 }
+static int php_pqtypes_object_has_dimension_70(zval *object, zval *member, int check_empty)
+{
+       return php_pqtypes_object_has_dimension_80(Z_OBJ_P(object), member, check_empty);
+}
 
-static zval *php_pqtypes_object_read_dimension(zval *object, zval *member, int type, zval *rv)
+#if PHP_VERSION_ID >= 80000
+# define php_pqtypes_object_read_dimension php_pqtypes_object_read_dimension_80
+#else
+# define php_pqtypes_object_read_dimension php_pqtypes_object_read_dimension_70
+#endif
+static zval *php_pqtypes_object_read_dimension_80(zend_object *object, zval *member, int type, zval *rv)
 {
-       php_pqtypes_object_t *obj = PHP_PQ_OBJ(object, NULL);
+       php_pqtypes_object_t *obj = PHP_PQ_OBJ(NULL, object);
        zend_string *key = NULL;
        zend_long index = 0;
        zval *data = NULL;
@@ -142,13 +156,35 @@ static zval *php_pqtypes_object_read_dimension(zval *object, zval *member, int t
 
        return data;
 }
+static zval *php_pqtypes_object_read_dimension_70(zval *object, zval *member, int type, zval *rv)
+{
+       return php_pqtypes_object_read_dimension_80(Z_OBJ_P(object), member, type, rv);
+}
 
-static void php_pqtypes_object_write_dimension(zval *object, zval *offset, zval *value)
+#if PHP_VERSION_ID >= 80000
+# define php_pqtypes_object_write_dimension php_pqtypes_object_write_dimension_80
+#else
+# define php_pqtypes_object_write_dimension php_pqtypes_object_write_dimension_70
+#endif
+static void php_pqtypes_object_write_dimension_80(zend_object *object, zval *offset, zval *value)
+{
+       throw_exce(EX_RUNTIME, "pq\\Types object must not be modified");
+}
+static void php_pqtypes_object_write_dimension_70(zval *object, zval *offset, zval *value)
 {
        throw_exce(EX_RUNTIME, "pq\\Types object must not be modified");
 }
 
-static void php_pqtypes_object_unset_dimension(zval *object, zval *offset)
+#if PHP_VERSION_ID >= 80000
+# define php_pqtypes_object_unset_dimension php_pqtypes_object_unset_dimension_80
+#else
+# define php_pqtypes_object_unset_dimension php_pqtypes_object_unset_dimension_70
+#endif
+static void php_pqtypes_object_unset_dimension_80(zend_object *object, zval *offset)
+{
+       throw_exce(EX_RUNTIME, "pq\\Types object must not be modified");
+}
+static void php_pqtypes_object_unset_dimension_70(zval *object, zval *offset)
 {
        throw_exce(EX_RUNTIME, "pq\\Types object must not be modified");
 }
@@ -180,9 +216,9 @@ static PHP_METHOD(pqtypes, __construct) {
                        zend_hash_init(&obj->intern->types, 512, NULL, ZVAL_PTR_DTOR, 0);
 
                        if (znsp) {
-                               zend_call_method_with_1_params(getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", NULL, znsp);
+                               php_pq_call_method(getThis(), "refresh", 1, NULL, znsp);
                        } else {
-                               zend_call_method_with_0_params(getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", NULL);
+                               php_pq_call_method(getThis(), "refresh", 0, NULL);
                        }
                }
        }
index ac643ffc13781de335b1e0b783f793527b279557..97e991b4643a2b8dae8239c43da7d59975cbd06d 100644 (file)
@@ -11,12 +11,8 @@ include "_setup.inc";
 try {
        new pq\Connection(1,2,3,4);
        foo();
-} catch (pq\Exception $e) {
-assert($e->getCode() == pq\Exception::INVALID_ARGUMENT, $e->getCode()."!=".pq\Exception::INVALID_ARGUMENT);
-}
-try {
-       new pq\Connection(1,2,3,4);
-       foo();
+} catch (ArgumentCountError $e) {
+       // PHP 8
 } catch (pq\Exception\InvalidArgumentException $e) {
        assert($e->getCode() == pq\Exception::INVALID_ARGUMENT, $e->getCode()."!=".pq\Exception::INVALID_ARGUMENT);
 }