prepare v2.2.3 master v2.2.3
authorMichael Wallner <mike@php.net>
Mon, 5 Feb 2024 18:56:09 +0000 (19:56 +0100)
committerMichael Wallner <mike@php.net>
Mon, 5 Feb 2024 18:56:09 +0000 (19:56 +0100)
45 files changed:
.gitattributes
.github/workflows/ci.yml [new file with mode: 0644]
.gitignore
.gitmodules
.travis.yml [deleted file]
README.md
config9.m4
package.xml
php_pq.h
scripts/ci [new submodule]
scripts/gen_github_workflow_ci.php [new file with mode: 0755]
scripts/gen_travis_yml.php [deleted file]
src/php_pq_callback.h
src/php_pq_misc.c
src/php_pq_misc.h
src/php_pq_module.c
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_pqconn_event.c
src/php_pqcopy.c
src/php_pqcur.c
src/php_pqlob.c
src/php_pqres.c
src/php_pqres.h
src/php_pqstm.c
src/php_pqtxn.c
src/php_pqtypes.c
tests/_skipif.inc
tests/async001.phpt
tests/async002.phpt
tests/async010.phpt [new file with mode: 0644]
tests/basic003.phpt [new file with mode: 0644]
tests/cancel001.phpt
tests/crash_cur_reverse_dep.phpt
tests/crash_stm_reverse_dep.phpt
tests/crash_txn_reverse_dep.phpt
tests/exceptions001.phpt
tests/gh-issue047_jsonb.phpt [new file with mode: 0644]
tests/res001.phpt
tests/trans001.phpt
tests/types002.phpt
travis/pecl [deleted submodule]

index 29df74b84ddda6945d34a7c2c9ba34f2d1597124..8b608050fe20c19850b68c6b452c06b37467d493 100644 (file)
@@ -1,4 +1,3 @@
 package.xml            merge=touch
 php_pq.h               merge=touch
-.travis.yml            merge=touch
 *.phar                 binary
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644 (file)
index 0000000..fd250c6
--- /dev/null
@@ -0,0 +1,477 @@
+# generated file; do not edit!
+
+name: ci
+on:
+  workflow_dispatch:
+  push:
+  pull_request:
+
+jobs:
+  old-matrix-0:
+    name: "old-matrix-0 (7.0)"
+    env:
+      PHP: "7.0"
+      enable_debug: "yes"
+      enable_maintainer_zts: "yes"
+      enable_json: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  old-matrix-1:
+    name: "old-matrix-1 (7.1)"
+    env:
+      PHP: "7.1"
+      enable_debug: "yes"
+      enable_maintainer_zts: "yes"
+      enable_json: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  old-matrix-2:
+    name: "old-matrix-2 (7.2)"
+    env:
+      PHP: "7.2"
+      enable_debug: "yes"
+      enable_maintainer_zts: "yes"
+      enable_json: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  old-matrix-3:
+    name: "old-matrix-3 (7.3)"
+    env:
+      PHP: "7.3"
+      enable_debug: "yes"
+      enable_maintainer_zts: "yes"
+      enable_json: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  old-matrix-4:
+    name: "old-matrix-4 (7.4)"
+    env:
+      PHP: "7.4"
+      enable_debug: "yes"
+      enable_maintainer_zts: "yes"
+      enable_json: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  old-matrix-5:
+    name: "old-matrix-5 (8.0)"
+    env:
+      PHP: "8.0"
+      enable_debug: "yes"
+      enable_maintainer_zts: "yes"
+      enable_json: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  old-matrix-6:
+    name: "old-matrix-6 (8.1)"
+    env:
+      PHP: "8.1"
+      enable_debug: "yes"
+      enable_maintainer_zts: "yes"
+      enable_json: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  next-0:
+    name: "next-0 (master)"
+    continue-on-error: true
+    env:
+      PHP: "master"
+      enable_debug: "yes"
+      enable_zts: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  cur-dbg-zts-0:
+    name: "cur-dbg-zts-0 (8.2)"
+    env:
+      PHP: "8.2"
+      enable_debug: "yes"
+      enable_zts: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  cur-dbg-zts-1:
+    name: "cur-dbg-zts-1 (8.2)"
+    env:
+      PHP: "8.2"
+      enable_debug: "no"
+      enable_zts: "yes"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  cur-dbg-zts-2:
+    name: "cur-dbg-zts-2 (8.2)"
+    env:
+      PHP: "8.2"
+      enable_debug: "yes"
+      enable_zts: "no"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  cur-dbg-zts-3:
+    name: "cur-dbg-zts-3 (8.2)"
+    env:
+      PHP: "8.2"
+      enable_debug: "no"
+      enable_zts: "no"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+
+  cur-cov-0:
+    name: "cur-cov-0 (8.2)"
+    env:
+      CFLAGS: "-O0 -g --coverage"
+      CXXFLAGS: "-O0 -g --coverage"
+      PHP: "8.2"
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+      - name: Coverage
+        if: success()
+        run: |
+          cd src/.libs
+          bash <(curl -s https://codecov.io/bash) -X xcode -X coveragepy
+
index 902c527ccc93308b404f4d1178ab046d1b3f4f5d..9f531088a4c57f1fb41a04f29a4da4c7c8ec13e9 100644 (file)
@@ -3,6 +3,8 @@
 *~
 /*.tgz
 .deps
+*.dep
+*.o
 *.lo
 *.la
 /config.[^m]*
index e53f88c8d93cfb1c4195f5dd3a14376171acb2b4..72fd52f1e1a07f3d22140bf70a526cdf31e361f9 100644 (file)
@@ -1,4 +1,3 @@
-[submodule "travis-pecl"]
-       path = travis/pecl
-       url = https://github.com/m6w6/travis-pecl.git
-       branch = master
+[submodule "scripts/ci"]
+       path = scripts/ci
+       url = https://github.com/m6w6/pecl-ci.git
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644 (file)
index 23cbd18..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-# autogenerated file; do not edit
-language: c
-sudo: false
-
-addons:
- postgresql: 9.4
- apt:
-  packages:
-   - php-cli
-   - php-pear
-   - valgrind
-
-cache:
- directories:
-  - $HOME/cache
-
-before_cache:
- - find $HOME/cache -name '*.gcda' -o -name '*.gcno' -delete
-
-env:
- global:
-  - PQ_DSN="postgres://postgres@localhost/test"
- matrix:
-  - PHP=7.0 enable_debug=yes enable_maintainer_zts=yes enable_json=yes
-  - PHP=7.1 enable_debug=yes enable_maintainer_zts=yes enable_json=yes
-  - PHP=7.2 enable_debug=yes enable_maintainer_zts=yes enable_json=yes
-  - PHP=7.3 enable_debug=yes enable_maintainer_zts=yes enable_json=yes
-  - PHP=master enable_debug=yes enable_maintainer_zts=yes enable_json=yes
-  - PHP=7.4 enable_json=no
-  - PHP=7.4 enable_json=yes enable_debug=no enable_maintainer_zts=no
-  - PHP=7.4 enable_json=yes enable_debug=yes enable_maintainer_zts=no
-  - PHP=7.4 enable_json=yes enable_debug=no enable_maintainer_zts=yes
-  - PHP=7.4 enable_json=yes enable_debug=yes enable_maintainer_zts=yes
-  - PHP=7.4 enable_json=yes CFLAGS='-O0 -g --coverage' CXXFLAGS='-O0 -g --coverage'
-
-matrix:
- fast_finish: true
- allow_failures:
-  - env: PHP=master enable_debug=yes enable_maintainer_zts=yes enable_json=yes
-
-install:
- - |
-   if test "$PHP" = master; then \
-     make -f travis/pecl/Makefile reconf; \
-     make -f travis/pecl/Makefile pecl-rm pecl-clean PECL=raphf:raphf:2.0.0; \
-   fi
- - make -f travis/pecl/Makefile php || make -f travis/pecl/Makefile clean php
- - make -f travis/pecl/Makefile pecl PECL=raphf:raphf:2.0.0
-
-before_script:
- - psql -U postgres -c "CREATE DATABASE test"
-
-script:
- - make -f travis/pecl/Makefile ext PECL=pq
- - make -f travis/pecl/Makefile test
-
-after_success:
- - test -n "$CFLAGS" && cd src/.libs && bash <(curl -s https://codecov.io/bash) -X xcode -X coveragepy
index 8aa9c32c99558054d2658192ad161d22b0909a76..c823ddd998ebf5988c50bf72a5b4b96ef689b51a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
 # pecl/pq
 
-[![Build Status](https://travis-ci.org/m6w6/ext-pq.svg?branch=master)](https://travis-ci.org/m6w6/ext-pq)
+[![Build Status](https://github.com/m6w6/ext-pq/workflows/ci/badge.svg?branch=master)](https://github.com/m6w6/ext-pq/actions?query=branch%3Amaster+workflow%3Aci)
+[![codecov](https://codecov.io/gh/m6w6/ext-pq/branch/master/graph/badge.svg?token=Nku9tz8EMj)](https://codecov.io/gh/m6w6/ext-pq)
 
 ## About:
 
@@ -8,8 +9,8 @@ This is a modern binding to the mature [libpq](http://www.postgresql.org/docs/cu
 
 ### Highlights:
 
-* Nearly 100% support for [asynchronous usage](https://mdref.m6w6.name/pq/Connection/:+Asynchronous+Usage).
-* Extended [type support by pg_type](https://mdref.m6w6.name/pq/Types/:+Overview).
+* Nearly 100% support for [asynchronous usage](https://mdref.m6w6.name/pq/Connection/:%20Asynchronous%20Usage).
+* Extended [type support by pg_type](https://mdref.m6w6.name/pq/Types/:%20Overview).
 * Fetching simple [multi-dimensional array maps](https://mdref.m6w6.name/pq/Result/map).
 * Working [Gateway implementation](https://github.com/m6w6/pq-gateway).
 
@@ -19,7 +20,7 @@ See the [online markdown reference](https://mdref.m6w6.name/pq).
 
 Known issues are listed in [BUGS](./BUGS) and future ideas can be found in [TODO](./TODO).
 
-## Installing
+## Install
 
 ### PECL
 
index 8064df9d3346562c99ff573a737de484978d5065..d845e282d4652f321c27b1bf8d637656b80058ee 100644 (file)
@@ -7,7 +7,7 @@ if test "$PHP_PQ" != "no"; then
        if test "$PHP_PQ" != "yes"; then
                SEARCH_PATH="$PHP_PQ $SEARCH_PATH"
        fi
-       
+
        AC_MSG_CHECKING(for pg_config)
        for i in $SEARCH_PATH; do
                if test -x "$i/bin/pg_config"; then
@@ -15,20 +15,20 @@ if test "$PHP_PQ" != "no"; then
                        break
                fi
        done
-       
+
        if test -z "$PG_CONFIG"; then
                AC_PATH_PROG(PG_CONFIG, pg_config, no)
        fi
-       
+
        AC_MSG_RESULT($PG_CONFIG)
-       
+
        if test "$PG_CONFIG" = "no"; then
                AC_MSG_ERROR(could not find a usable pg_config in $SEARCH_PATH)
        else
                if test "$PHP_PQ" != "yes" -a "$PHP_PQ/bin/pg_config" != "$PG_CONFIG"; then
                        AC_MSG_WARN(Found pg_config is not in $PHP_PQ)
                fi
-               
+
                AC_MSG_CHECKING(for PostgreSQL version)
                PQ_VERSION=$($PG_CONFIG --version | $SED 's/PostgreSQL //')
 
@@ -39,7 +39,7 @@ if test "$PHP_PQ" != "no"; then
                        AC_MSG_RESULT($PQ_VERSION)
                        AC_DEFINE_UNQUOTED(PHP_PQ_LIBVERSION, "$PQ_VERSION", [ ])
                fi
-               
+
                PQ_INCDIR=$($PG_CONFIG --includedir)
                PQ_LIBDIR=$($PG_CONFIG --libdir)
        fi
@@ -68,24 +68,30 @@ if test "$PHP_PQ" != "no"; then
        PQ_CHECK_CONST(PGRES_SINGLE_TUPLE)
        PQ_CHECK_CONST(PGRES_COPY_BOTH)
 
+       PQ_CHECK_CONST(CONNECTION_CHECK_WRITABLE)
+       PQ_CHECK_CONST(CONNECTION_CONSUME)
+       PQ_CHECK_CONST(CONNECTION_GSS_STARTUP)
 
        dnl
        dnl PQ_CHECK_FUNC(sym, fail-hard)
        dnl
        AC_DEFUN([PQ_CHECK_FUNC], [
+               PQ_SYM=$1
                FAIL_HARD=$2
-
+               save_LIBS="$LIBS"
+               LIBS=
                PHP_CHECK_LIBRARY(pq, $1, [
                        AC_DEFINE([HAVE_]translit($1,a-z,A-Z), 1, Have $1)
                ], [
                        if test -n "$FAIL_HARD"; then
-                               if "$FAIL_HARD"; then
-                                       AC_MSG_ERROR(could not find $PQ_SYM in -lpq)
+                               if $FAIL_HARD; then
+                                       AC_MSG_ERROR(could not find $PQ_SYM in -lpq -L$PQ_LIBDIR)
                                fi
                        fi
                ], [
                        -L$PQ_LIBDIR
                ])
+               LIBS="$save_LIBS"
        ])
 
        PQ_CHECK_FUNC(PQregisterEventProc, true)
@@ -93,6 +99,8 @@ if test "$PHP_PQ" != "no"; then
        PHP_SUBST(PQ_SHARED_LIBADD)
 
        PQ_CHECK_FUNC(PQlibVersion)
+       PQ_CHECK_FUNC(PQprotocolVersion)
+       PQ_CHECK_FUNC(PQserverVersion)
        PQ_CHECK_FUNC(PQconninfo)
        PQ_CHECK_FUNC(PQsetSingleRowMode)
 
@@ -172,26 +180,4 @@ if test "$PHP_PQ" != "no"; then
                AC_MSG_ERROR([Please install pecl/raphf and activate extension=raphf.$SHLIB_DL_SUFFIX_NAME in your php.ini])
        ])
        PHP_ADD_EXTENSION_DEP(pq, raphf, true)
-       PQ_HAVE_PHP_EXT([json], [
-               AC_MSG_CHECKING([for php_json.h])
-               PQ_EXT_JSON_INCDIR=
-               for i in `echo $INCLUDES | $SED -e's/-I//g'` $abs_srcdir ../json ../jsonc ../jsond; do
-                       if test -d $i; then
-                               if test -f $i/php_json.h; then
-                                       PQ_EXT_JSON_INCDIR=$i
-                                       break
-                               elif test -f $i/ext/json/php_json.h; then
-                                       PQ_EXT_JSON_INCDIR=$i/ext/json
-                                       break
-                               fi
-                       fi
-               done
-               if test "x$PQ_EXT_JSON_INCDIR" = "x"; then
-                       AC_MSG_ERROR([not found])
-               else
-                       AC_MSG_RESULT([$PQ_EXT_JSON_INCDIR])
-                       AC_DEFINE([PHP_PQ_HAVE_PHP_JSON_H], [1], [Have ext/json support])
-                       PHP_ADD_INCLUDE([$PQ_EXT_JSON_INCDIR])
-               fi
-       ])
 fi
index 2d2df073da5d21f2faf57446df84134348516a50..e6b668e4234908f8ccdf42539e89204d5b38bc51 100644 (file)
@@ -41,9 +41,9 @@
   <email>remi@php.net</email>
   <active>yes</active>
  </developer>
- <date>2020-01-18</date>
+ <date>2024-02-05</date>
  <version>
-  <release>2.1.6</release>
+  <release>2.2.3</release>
   <api>2.1.0</api>
  </version>
  <stability>
@@ -52,9 +52,7 @@
  </stability>
  <license uri="http://copyfree.org/content/standard/licenses/2bsd/license.txt">BSD-2-Clause</license>
  <notes><![CDATA[
-  * Fix PgSQL-12 compatibility
-  * Fix PHP-7.4 compatibility
-  * Fix empty arrays parsing (Dmitry Simushev)
+  * Fix incompatible pointer types (32-bit) (see hg issue #52)
 ]]></notes>
  <contents>
   <dir name="/">
     <file role="test" name="async007.phpt" />
     <file role="test" name="async008.phpt" />
     <file role="test" name="async009.phpt" />
+    <file role="test" name="async010.phpt" />
     <file role="test" name="basic001.phpt" />
     <file role="test" name="basic002.phpt" />
+    <file role="test" name="basic003.phpt" />
     <file role="test" name="bound002.phpt" />
     <file role="test" name="callback001.phpt" />
     <file role="test" name="callback002.phpt" />
     <file role="test" name="flush001.phpt" />
     <file role="test" name="gh-issue015_listeners.phpt" />
     <file role="test" name="gh-issue015_statements.phpt" />
+    <file role="test" name="gh-issue047_jsonb.phpt" />
     <file role="test" name="info001.phpt" />
     <file role="test" name="info002.phpt" />
     <file role="test" name="lob001.phpt" />
     <min>7.0.0</min>
    </php>
    <pearinstaller>
-    <min>1.4.0</min>
+    <min>1.10.0</min>
    </pearinstaller>
    <package>
     <name>raphf</name>
     <channel>pecl.php.net</channel>
-    <min>2.0.0dev</min>
+    <min>2.0.0</min>
     <providesextension>raphf</providesextension>
    </package>
   </required>
index a76cdddc11054a83c4679ef4851d0a65e3ca774d..022c5535adec096828322c78d3c8f7950fe1e0e1 100644 (file)
--- a/php_pq.h
+++ b/php_pq.h
@@ -14,7 +14,7 @@
 #ifndef PHP_PQ_H
 #define PHP_PQ_H
 
-#define PHP_PQ_VERSION "2.1.6"
+#define PHP_PQ_VERSION "2.2.3"
 
 #ifdef PHP_WIN32
 #      define PHP_PQ_API __declspec(dllexport)
diff --git a/scripts/ci b/scripts/ci
new file mode 160000 (submodule)
index 0000000..547c8e8
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 547c8e89e38d6e899914c05ddf6598669bd16532
diff --git a/scripts/gen_github_workflow_ci.php b/scripts/gen_github_workflow_ci.php
new file mode 100755 (executable)
index 0000000..78d770a
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/env php
+<?php echo "# generated file; do not edit!\n"; ?>
+
+name: ci
+on:
+  workflow_dispatch:
+  push:
+  pull_request:
+
+jobs:
+<?php
+
+$gen = include __DIR__ . "/ci/gen-matrix.php";
+$cur = "8.2";
+$job = $gen->github([
+"old-matrix" => [
+       "PHP" => ["7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1"],
+       "enable_debug" => "yes",
+       "enable_maintainer_zts" => "yes",
+       "enable_json" => "yes",
+],
+"next" => [
+    "PHP" => ["master"],
+    "enable_debug" => "yes",
+    "enable_zts" => "yes",
+],
+"cur-dbg-zts" => [
+    "PHP" => $cur,
+    "enable_debug",
+    "enable_zts",
+],
+"cur-cov" => [
+    "CFLAGS" => "-O0 -g --coverage",
+    "CXXFLAGS" => "-O0 -g --coverage",
+    "PHP" => $cur,
+]]);
+foreach ($job as $id => $env) {
+    printf("  %s:\n", $id);
+    printf("    name: \"%s (%s)\"\n", $id, $env["PHP"]);
+    if ($env["PHP"] == "master") {
+        printf("    continue-on-error: true\n");
+    }
+    printf("    env:\n");
+    foreach ($env as $key => $val) {
+        printf("      %s: \"%s\"\n", $key, $val);
+    }
+?>
+      PQ_DSN: "postgres:///runner"
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+      - name: Install
+        run: |
+          sudo apt-get install -y \
+            php-cli \
+            php-pear \
+            libpq-dev \
+            re2c
+      - name: Prepare
+        run: |
+          make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php
+          make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master
+      - name: Build
+        run: |
+          make -f scripts/ci/Makefile ext PECL=pq
+      - name: Prepare Test
+        run: |
+          sudo systemctl start postgresql
+          sudo -u postgres createuser --login runner
+          sudo -u postgres createdb -O runner runner
+      - name: Test
+        run: |
+          make -f scripts/ci/Makefile test
+<?php if (isset($env["CFLAGS"]) && strpos($env["CFLAGS"], "--coverage") != false) : ?>
+      - name: Coverage
+        if: success()
+        run: |
+          cd src/.libs
+          bash <(curl -s https://codecov.io/bash) -X xcode -X coveragepy
+<?php endif; ?>
+
+<?php
+}
diff --git a/scripts/gen_travis_yml.php b/scripts/gen_travis_yml.php
deleted file mode 100755 (executable)
index 7e05a54..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env php
-# autogenerated file; do not edit
-language: c
-sudo: false
-
-addons:
- postgresql: 9.4
- apt:
-  packages:
-   - php-cli
-   - php-pear
-   - valgrind
-
-cache:
- directories:
-  - $HOME/cache
-
-before_cache:
- - find $HOME/cache -name '*.gcda' -o -name '*.gcno' -delete
-
-env:
- global:
-  - PQ_DSN="postgres://postgres@localhost/test"
- matrix:
-<?php
-
-$gen = include "./travis/pecl/gen-matrix.php";
-$cur = "7.4";
-$env = $gen([
-       "PHP" => ["7.0", "7.1", "7.2", "7.3", "master"],
-       "enable_debug" => "yes",
-       "enable_maintainer_zts" => "yes",
-       "enable_json" => "yes",
-], [
-       "PHP" => $cur,
-       "enable_json" => "no",
-], [
-       "PHP" => $cur,
-       "enable_json" => "yes",
-       "enable_debug",
-       "enable_maintainer_zts"
-], [
-       "PHP" => $cur,
-       "enable_json" => "yes",
-       "CFLAGS" => "'-O0 -g --coverage'",
-       "CXXFLAGS" => "'-O0 -g --coverage'",
-]);
-
-foreach ($env as $g) {
-       foreach ($g as $e) {
-               printf("  - %s\n", $e);
-       }
-}
-?>
-
-matrix:
- fast_finish: true
- allow_failures:
-<?php
-$allow_failures = array_merge( ... array_map(function($a) {
-       return preg_grep('/^PHP=(master) /', $a);
-}, $env));
-foreach ($allow_failures as $e) {
-       printf("  - env: %s\n", $e);
-}
-?>
-
-install:
- - |
-   if test "$PHP" = master; then \
-     make -f travis/pecl/Makefile reconf; \
-     make -f travis/pecl/Makefile pecl-rm pecl-clean PECL=raphf:raphf:2.0.0; \
-   fi
- - make -f travis/pecl/Makefile php || make -f travis/pecl/Makefile clean php
- - make -f travis/pecl/Makefile pecl PECL=raphf:raphf:2.0.0
-
-before_script:
- - psql -U postgres -c "CREATE DATABASE test"
-
-script:
- - make -f travis/pecl/Makefile ext PECL=pq
- - make -f travis/pecl/Makefile test
-
-after_success:
- - test -n "$CFLAGS" && cd src/.libs && bash <(curl -s https://codecov.io/bash) -X xcode -X coveragepy
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..4d251d2b5415c1b0846a2a1dd89969a296ee416b 100644 (file)
 #undef PHP_PQ_TYPE
 #include "php_pq_type.h"
 
+/* convert version to string */
+extern void php_pq_version_to_string(int version, char *buffer, int len) {
+       if (version < 100000) {
+               slprintf(buffer, len, "%d.%d.%d", version/10000, version/100%100, version%100);
+       } else { /* since version 10 */
+               slprintf(buffer, len, "%d.%d", version/10000, version%100);
+       }
+}
 
 /* clear result object associated with a result handle */
 void php_pqres_clear(PGresult *r) {
@@ -103,11 +111,8 @@ const char *php_pq_strmode(long mode)
        }
 }
 
-int php_pq_compare_index(const void *lptr, const void *rptr)
+static inline int compare_index(zend_ulong l, zend_ulong r)
 {
-       zend_ulong l = ((const Bucket *) lptr)->h;
-       zend_ulong r = ((const Bucket *) rptr)->h;
-
        if (l < r) {
                return -1;
        }
@@ -116,6 +121,16 @@ int php_pq_compare_index(const void *lptr, const void *rptr)
        }
        return 0;
 }
+#if PHP_VERSION_ID >= 80000
+int php_pq_compare_index(Bucket *lptr, Bucket *rptr)
+{
+       return compare_index(lptr->h, rptr->h);
+}
+#else
+int php_pq_compare_index(const void *lptr, const void *rptr) {
+       return compare_index(((const Bucket *) lptr)->h, ((const Bucket *) rptr)->h);
+}
+#endif
 
 void php_pq_hash_ptr_dtor(zval *p)
 {
@@ -124,19 +139,33 @@ void php_pq_hash_ptr_dtor(zval *p)
 
 zend_class_entry *php_pqdt_class_entry;
 
+#if PHP_VERSION_ID >= 80100
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_pqdt_jsonserialize, 0, 0, IS_MIXED, 0)
+ZEND_END_ARG_INFO()
+#else
+#define ai_pqdt_jsonserialize ai_pqdt_to_string
+#endif
+
+#if PHP_VERSION_ID >= 80200
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_pqdt_to_string, 0, 0, IS_STRING, 0)
+#else
 ZEND_BEGIN_ARG_INFO_EX(ai_pqdt_to_string, 0, 0, 0)
+#endif
 ZEND_END_ARG_INFO();
 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);
 }
 
+#if PHP_VERSION_ID >= 80100
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(ai_pqdt_create_from_format, 0, 2, DateTime, MAY_BE_FALSE)
+#else
 ZEND_BEGIN_ARG_INFO_EX(ai_pqdt_create_from_format, 0, 0, 2)
+#endif
        ZEND_ARG_INFO(0, format)
        ZEND_ARG_INFO(0, datetime)
 #if PHP_VERSION_ID >= 70200
@@ -165,11 +194,11 @@ static PHP_METHOD(pqdt, createFromFormat)
 static zend_function_entry php_pqdt_methods[] = {
        PHP_ME(pqdt, createFromFormat, ai_pqdt_create_from_format, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME(pqdt, __toString, ai_pqdt_to_string, ZEND_ACC_PUBLIC)
-       PHP_MALIAS(pqdt, jsonSerialize, __toString, ai_pqdt_to_string, ZEND_ACC_PUBLIC)
+       PHP_MALIAS(pqdt, jsonSerialize, __toString, ai_pqdt_jsonserialize, ZEND_ACC_PUBLIC)
        {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 +208,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 +223,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..dab24ec7d1ee7231d34ca33778e9a1ecbc5b51d5 100644 (file)
@@ -33,6 +33,8 @@ extern PGresult *php_pq_exec_params(PGconn *conn, const char *command, int nPara
 extern PGresult *php_pq_prepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes);
 extern PGresult *php_pq_exec_prepared(PGconn *conn, const char *stmtName, int nParams, const char *const * paramValues, const int *paramLengths, const int *paramFormats, int resultFormat);
 
+/* convert version to string */
+extern void php_pq_version_to_string(int version, char *buffer, int len);
 
 /* trim LF from EOL */
 extern char *php_pq_rtrim(char *e);
@@ -40,9 +42,6 @@ extern char *php_pq_rtrim(char *e);
 /* R, W, RW */
 extern const char *php_pq_strmode(long mode);
 
-/* compare array index */
-extern int php_pq_compare_index(const void *lptr, const void *rptr);
-
 /* free zval ptr values (as hash dtor) */
 extern void php_pq_hash_ptr_dtor(zval *p);
 
@@ -50,13 +49,61 @@ 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
+extern int php_pq_compare_index(Bucket *lptr, Bucket *rptr);
+
+# 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
+
+extern int php_pq_compare_index(const void *lptr, const void *rptr);
+
+# define zend_ce_countable spl_ce_Countable
+
+# 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
+
+#if PHP_VERSION_ID < 80100
+# define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
+                ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args)
+# define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
+                ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args)
+#endif
+
+#ifndef ZEND_ACC_READONLY
+#define ZEND_ACC_READONLY 0
+#endif
 
 extern PHP_MINIT_FUNCTION(pq_misc);
 
index cd992172d9e524bc9c6ccdd15d151fcdf43c806e..7385b0b378f234f861da3c0b8cb161432c6b11c6 100644 (file)
@@ -105,7 +105,7 @@ static PHP_MINFO_FUNCTION(pq)
        php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
 #ifdef HAVE_PQLIBVERSION
        libpq_v = PQlibVersion();
-       slprintf(libpq_version, sizeof(libpq_version), "%d.%d.%d", libpq_v/10000%100, libpq_v/100%100, libpq_v%100);
+       php_pq_version_to_string(libpq_v, libpq_version, sizeof(libpq_version));
 #endif
        php_info_print_table_row(3, "libpq", PHP_PQ_LIBVERSION, libpq_version);
        php_info_print_table_end();
index b9ce32d5c9dac4bf8c2cac77eadbfc9049fe0891..5b3f217a95f7e7bb4c9561a7d954a34359787089 100644 (file)
@@ -17,6 +17,7 @@
 #include <php.h>
 
 #include "php_pq_object.h"
+#include "php_pq_misc.h"
 
 void *php_pq_object_create(zend_class_entry *ce, void *intern, size_t obj_size, zend_object_handlers *oh, HashTable *ph)
 {
@@ -78,7 +79,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;
 };
@@ -92,23 +92,32 @@ static int apply_pi_to_ht(zval *p, void *a)
                php_pq_object_prophandler_t *handler;
 
                if ((handler = zend_hash_find_ptr(arg->pq_obj->prophandler, pi->name)) && handler->gc) {
-                       zval member, return_value;
+                       zval return_value;
 
-                       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);
+               zval tmp_prop, *property;
+#if PHP_VERSION_ID < 80000
+               zval zobj;
+
+               ZVAL_OBJ(&zobj, &arg->pq_obj->zo);
+# if PHP_VERSION_ID < 70100
+               property = zend_read_property(arg->pq_obj->zo.ce, &zobj, pi->name->val, pi->name->len, 0, &tmp_prop);
+# else
+               property = zend_read_property_ex(arg->pq_obj->zo.ce, &zobj, pi->name, 0, &tmp_prop);
+# endif
+#else
+               property = zend_read_property_ex(arg->pq_obj->zo.ce, &arg->pq_obj->zo, pi->name, 0, &tmp_prop);
+#endif
                zend_hash_update(arg->ht, pi->name, property);
        }
 
        return ZEND_HASH_APPLY_KEEP;
 }
 
-HashTable *php_pq_object_debug_info(zval *object, int *temp)
+static inline HashTable *php_pq_object_debug_info_ex(zend_object *object, int *temp)
 {
        struct apply_pi_to_ht_arg arg = {NULL};
 
@@ -116,47 +125,79 @@ 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;
 }
+#if PHP_VERSION_ID >= 80000
+HashTable *php_pq_object_debug_info(zend_object *object, int *temp)
+{
+       return php_pq_object_debug_info_ex(object, temp);
+}
+#else
+HashTable *php_pq_object_debug_info(zval *object, int *temp)
+{
+       return php_pq_object_debug_info_ex(Z_OBJ_P(object), temp);
+}
+#endif
 
-HashTable *php_pq_object_properties(zval *object)
+static inline HashTable *php_pq_object_properties_ex(zend_object *object, HashTable *props)
 {
        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.ht = props;
+       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;
 }
+#if PHP_VERSION_ID >= 80000
+HashTable *php_pq_object_properties(zend_object *object)
+{
+       return php_pq_object_properties_ex(object, zend_std_get_properties(object));
+}
+#else
+HashTable *php_pq_object_properties(zval *object)
+{
+       return php_pq_object_properties_ex(Z_OBJ_P(object), zend_std_get_properties(object));
+}
+#endif
 
-HashTable *php_pq_object_get_gc(zval *object, zval **table, int *n)
+static inline HashTable *php_pq_object_get_gc_ex(zend_object *object, HashTable *props, 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;
 
-       zend_hash_clean(arg.ht);
-       zend_hash_copy(arg.ht, zend_std_get_properties(object), NULL);
-       zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg);
+       if (GC_REFCOUNT(arg.ht) == 1) {
+               zend_hash_clean(arg.ht);
+               zend_hash_copy(arg.ht, props, NULL);
+               zend_hash_apply_with_argument(&arg.pq_obj->zo.ce->properties_info, apply_pi_to_ht, &arg);
+       }
 
        *table = NULL;
        *n = 0;
 
        return arg.ht;
 }
+#if PHP_VERSION_ID >= 80000
+HashTable *php_pq_object_get_gc(zend_object *object, zval **table, int *n)
+{
+       return php_pq_object_get_gc_ex(object, zend_std_get_properties(object), table, n);
+}
+#else
+HashTable *php_pq_object_get_gc(zval *object, zval **table, int *n)
+{
+       return php_pq_object_get_gc_ex(Z_OBJ_P(object), zend_std_get_properties(object), table, n);
+}
+#endif
 
 zend_class_entry *ancestor(zend_class_entry *ce)
 {
@@ -166,67 +207,115 @@ 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)
+static inline int php_pq_object_read_prop_ex(zend_object *object, zend_string *member, int type, zval *return_value)
 {
-       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;
-
-       return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
 
        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);
-               zend_get_std_object_handlers()->write_property(object, member, tmp, cache_slot);
-               return_value = tmp;
-
-               /*
-               zval dtor;
+               handler->read(obj, return_value);
+               return SUCCESS;
+       }
 
-               ZVAL_COPY_VALUE(&dtor, return_value);
+       return FAILURE;
+}
+#if PHP_VERSION_ID >= 80000
+zval *php_pq_object_read_prop(zend_object *object, zend_string *member, int type, void **cache_slot, zval *tmp)
+{
+       if (SUCCESS != php_pq_object_read_prop_ex(object, member, type, tmp)) {
+               return zend_std_read_property(object, member, type, cache_slot, tmp);
+       }
 
-               ZVAL_ZVAL(return_value, tmp, 0, 0);
-               zval_ptr_dtor(&dtor);
+       zend_std_write_property(object, member, tmp, cache_slot);
 
-               */
+       if (cache_slot) {
+               *cache_slot = NULL;
+       }
+       return tmp;
+}
+#else
+zval *php_pq_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
+{
+       zend_string *member_str = zval_get_string(member);
 
-               if (cache_slot) {
-                       *cache_slot = NULL;
-               }
+       if (SUCCESS != php_pq_object_read_prop_ex(Z_OBJ_P(object), member_str, type, tmp)) {
+               zend_string_release(member_str);
+               return zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
        }
+       zend_string_release(member_str);
 
-       return return_value;
+       zend_std_write_property(object, member, tmp, cache_slot);
+
+       if (cache_slot) {
+               *cache_slot = NULL;
+       }
+       return tmp;
 }
+#endif
 
-php_pq_object_write_prop_t php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
+static inline int php_pq_object_write_prop_ex(zend_object *object, zend_string *member, zval *value)
 {
-       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))) {
+               /* default handler */
+       } else {
                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);
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+#if PHP_VERSION_ID >= 80000
+zval *php_pq_object_write_prop(zend_object *object, zend_string *member, zval *value, void **cache_slot)
+{
+       if (SUCCESS != php_pq_object_write_prop_ex(object, member, value)) {
+               return zend_std_write_property(object, member, value, cache_slot);
        }
-#if PHP_VERSION_ID >= 70400
        return value;
-#endif
 }
+#elif PHP_VERSION_ID >= 70400
+zval *php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
+{
+       zend_string *member_str = zval_get_string(member);
+       if (SUCCESS != php_pq_object_write_prop_ex(Z_OBJ_P(object), member_str, value)) {
+               value = zend_std_write_property(object, member, value, cache_slot);
+       }
+       zend_string_release(member_str);
+       return value;
+}
+#else
+void php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
+{
+       zend_string *member_str = zval_get_string(member);
+       if (SUCCESS != php_pq_object_write_prop_ex(Z_OBJ_P(object), member_str, value)) {
+               zend_std_write_property(object, member, value, cache_slot);
+       }
+       zend_string_release(member_str);
+}
+#endif
 
+#if PHP_VERSION_ID >= 80000
+zval *php_pq_object_get_prop_ptr_null(zend_object *object, zend_string *member, int type, void **cache_slot)
+{
+       return NULL;
+}
+#else
 zval *php_pq_object_get_prop_ptr_null(zval *object, zval *member, int type, void **cache_slot)
 {
        return NULL;
 }
+#endif
 
 void php_pq_object_prophandler_dtor(zval *zv) {
        pefree(Z_PTR_P(zv), 1);
index a274dd4bb2556b901d2ad648f756cacf816b981f..0d86883148ddae90a354574f229a1c781cd8df4b 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,34 @@ 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);
+
+#if PHP_VERSION_ID >= 80000
+extern HashTable *php_pq_object_debug_info(zend_object *object, int *temp);
+extern HashTable *php_pq_object_properties(zend_object *object);
+extern HashTable *php_pq_object_get_gc(zend_object *object, zval **table, int *n);
+extern zval *php_pq_object_read_prop(zend_object *object, zend_string *member, int type, void **cache_slot, zval *tmp);
+extern zval *php_pq_object_write_prop(zend_object *object, zend_string *member, zval *value, void **cache_slot);
+extern zval *php_pq_object_get_prop_ptr_null(zend_object *object, zend_string *member, int type, void **cache_slot);
+#else
 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 HashTable *php_pq_object_get_gc(zval *object, zval **table, int *n);
 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;
-#else
-typedef void php_pq_object_write_prop_t;
-#endif
-extern php_pq_object_write_prop_t php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
+# if PHP_VERSION_ID >= 70400
+extern zval *php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
+# else
+extern void php_pq_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
+# endif
 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);
+#endif
 
 #endif
 
index a691eebd62464efbe897c2f91533c064b7f85961..9e92226f7b3f83b5fe07e03cb4681768bbd2fa60 100644 (file)
@@ -16,9 +16,7 @@
 
 #include <php.h>
 #include <ext/standard/php_string.h>
-#if PHP_PQ_HAVE_PHP_JSON_H
-#include <php_json.h> /* we've added the include directory to INCLUDES */
-#endif
+#include <ext/json/php_json.h>
 
 #include <Zend/zend_smart_str.h>
 #include <Zend/zend_interfaces.h>
@@ -75,12 +73,12 @@ unsigned php_pq_params_add_type_oid(php_pq_params_t *p, Oid type)
 
 static zend_string *object_param_to_string(php_pq_params_t *p, zval *zobj, Oid type)
 {
-#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON)
+#ifdef PHP_PQ_OID_JSON
        smart_str str = {0};
 #endif
 
        switch (type) {
-#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON)
+#ifdef PHP_PQ_OID_JSON
 # ifdef PHP_PQ_OID_JSONB
        case PHP_PQ_OID_JSONB:
 # endif
@@ -133,7 +131,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;
@@ -207,7 +205,7 @@ static zend_string *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid ty
        struct apply_to_param_from_array_arg arg = {NULL};
 
        switch (type) {
-#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON)
+#ifdef PHP_PQ_OID_JSON
 # ifdef PHP_PQ_OID_JSONB
        case PHP_PQ_OID_JSONB:
 # endif
@@ -243,7 +241,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);
@@ -307,7 +305,8 @@ static int apply_to_params(zval *zp, void *arg_ptr)
 {
        struct apply_to_params_arg *arg = arg_ptr;
 
-       SEPARATE_ZVAL_IF_NOT_REF(zp);
+       ZVAL_DEREF(zp);
+       SEPARATE_ZVAL(zp);
        php_pq_params_set_param(arg->params, arg->index++, zp);
        return ZEND_HASH_APPLY_KEEP;
 }
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..19ea6f05ebcaebd0abb059d475c7bad802f29128 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,71 +426,99 @@ 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;
 
        obj->intern->default_auto_convert = zval_get_long(value) & PHP_PQRES_CONV_ALL;
 }
 
+#ifdef HAVE_PQLIBVERSION
+static void php_pqconn_object_read_lib_version(void *o, zval *return_value)
+{
+       char ver[16];
+
+       php_pq_version_to_string(PQlibVersion(), ver, sizeof(ver));
+       RETVAL_STRING(ver);
+}
+#endif
+#ifdef HAVE_PQPROTOCOLVERSION
+static void php_pqconn_object_read_protocol_version(void *o, zval *return_value)
+{
+       php_pqconn_object_t *obj = o;
+
+       RETVAL_LONG(PQprotocolVersion(obj->intern->conn));
+}
+#endif
+#ifdef HAVE_PQSERVERVERSION
+static void php_pqconn_object_read_server_version(void *o, zval *return_value)
+{
+       php_pqconn_object_t *obj = o;
+       char ver[16];
+
+       php_pq_version_to_string(PQserverVersion(obj->intern->conn), ver, sizeof(ver));
+       RETVAL_STRING(ver);
+}
+#endif
+
 static ZEND_RESULT_CODE php_pqconn_update_socket(zval *zobj, php_pqconn_object_t *obj)
 {
        zval zsocket, zmember;
@@ -514,7 +542,11 @@ static ZEND_RESULT_CODE php_pqconn_update_socket(zval *zobj, php_pqconn_object_t
                ZVAL_NULL(&zsocket);
                retval = FAILURE;
        }
-       zend_get_std_object_handlers()->write_property(zobj, &zmember, &zsocket, NULL);
+#if PHP_VERSION_ID >= 80000
+       zend_std_write_property(Z_OBJ_P(zobj), Z_STR(zmember), &zsocket, NULL);
+#else
+       zend_std_write_property(zobj, &zmember, &zsocket, NULL);
+#endif
        zval_ptr_dtor(&zsocket);
        zval_ptr_dtor(&zmember);
 
@@ -586,7 +618,7 @@ static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t c
                smart_str_appends(&cmd, quoted_channel);
                smart_str_0(&cmd);
 
-               res = PQexec(conn, smart_str_v(&cmd));
+               res = php_pq_exec(conn, smart_str_v(&cmd));
 
                smart_str_free(&cmd);
                PQfreemem(quoted_channel);
@@ -870,7 +902,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 +956,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);
@@ -986,7 +1018,7 @@ static PHP_METHOD(pqconn, notify) {
                        PGresult *res;
                        char *params[2] = {channel_str, message_str};
 
-                       res = PQexecParams(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0);
+                       res = php_pq_exec_params(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0);
 
                        if (!res) {
                                throw_exce(EX_RUNTIME, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
@@ -1165,7 +1197,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;
@@ -1220,7 +1252,7 @@ static PHP_METHOD(pqconn, execParams) {
                        php_pq_params_t *params;
 
                        params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, Z_ARRVAL_P(zparams));
-                       res = PQexecParams(obj->intern->conn, query_str, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
+                       res = php_pq_exec_params(obj->intern->conn, query_str, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
                        php_pq_params_free(&params);
 
                        if (!res) {
@@ -1246,7 +1278,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 +1863,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 +1924,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 +1962,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);
 
@@ -2127,6 +2159,24 @@ PHP_MINIT_FUNCTION(pqconn)
        zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultAutoConvert", sizeof("defaultAutoConvert")-1, (void *) &ph, sizeof(ph));
        ph.write = NULL;
 
+#ifdef HAVE_PQLIBVERSION
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("libraryVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY);
+       ph.read = php_pqconn_object_read_lib_version;
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("libraryVersion"), (void *) &ph, sizeof(ph));
+#endif
+
+#ifdef HAVE_PQPROTOCOLVERSION
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("protocolVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY);
+       ph.read = php_pqconn_object_read_protocol_version;
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("protocolVersion"), (void *) &ph, sizeof(ph));
+#endif
+
+#ifdef HAVE_PQSERVERVERSION
+       zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("serverVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY);
+       ph.read = php_pqconn_object_read_server_version;
+       zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("serverVersion"), (void *) &ph, sizeof(ph));
+#endif
+
        zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK);
        zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD);
        zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("STARTED"), CONNECTION_STARTED);
@@ -2135,6 +2185,15 @@ PHP_MINIT_FUNCTION(pqconn)
        zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("AUTH_OK"), CONNECTION_AUTH_OK);
        zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("SSL_STARTUP"), CONNECTION_SSL_STARTUP);
        zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("SETENV"), CONNECTION_SETENV);
+#ifdef HAVE_CONNECTION_CHECK_WRITABLE
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("CHECK_WRITABLE"), CONNECTION_CHECK_WRITABLE);
+#endif
+#ifdef HAVE_CONNECTION_CONSUME
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("CONSUME"), CONNECTION_CONSUME);
+#endif
+#ifdef HAVE_CONNECTION_GSS_STARTUP
+       zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("GSS_STARTUP"), CONNECTION_GSS_STARTUP);
+#endif
 
        zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_IDLE"), PQTRANS_IDLE);
        zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_ACTIVE"), PQTRANS_ACTIVE);
index 802a9e482914235a3eeb39a081261b014871de4d..13e790a2cc3605472b11edcfde794e411d65472c 100644 (file)
@@ -55,7 +55,7 @@ static inline PGresult *relisten(PGconn *conn, const char *channel_str, size_t c
                smart_str_appends(&cmd, quoted_channel);
                smart_str_0(&cmd);
 
-               res = PQexec(conn, smart_str_v(&cmd));
+               res = php_pq_exec(conn, smart_str_v(&cmd));
 
                smart_str_free(&cmd);
                PQfreemem(quoted_channel);
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..a419390119d1f7aa23b0e63f38f305b517b54da6 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,14 @@ static void php_pqlob_object_read_stream(zval *object, void *o, zval *return_val
        RETVAL_ZVAL(&zstream, 1, 0);
 }
 
+#if PHP_VERSION_ID < 70400
 static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length)
+#else
+static ssize_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length)
+#endif
 {
        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);
@@ -115,13 +119,21 @@ static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, siz
                php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
        }
 
+#if PHP_VERSION_ID < 70400
+       return (written < 0 ? 0 : written);
+#else
        return written;
+#endif
 }
 
+#if PHP_VERSION_ID < 70400
 static size_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t length)
+#else
+static ssize_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t length)
+#endif
 {
        php_pqlob_object_t *obj = stream->abstract;
-       int read = 0;
+       ssize_t read = 0;
 
        if (obj) {
 
@@ -140,7 +152,11 @@ static size_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t len
                php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
        }
 
+#if PHP_VERSION_ID < 70400
+       return (read < 0 ? 0 : read);
+#else
        return read;
+#endif
 }
 
 static ZEND_RESULT_CODE php_pqlob_stream_close(php_stream *stream, int close_handle)
@@ -153,7 +169,7 @@ static int php_pqlob_stream_flush(php_stream *stream)
        return SUCCESS;
 }
 
-static ZEND_RESULT_CODE php_pqlob_stream_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset)
+static ZEND_RESULT_CODE php_pqlob_stream_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset)
 {
        ZEND_RESULT_CODE rv = FAILURE;
        php_pqlob_object_t *obj = stream->abstract;
@@ -191,20 +207,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);
 
-       zend_get_std_object_handlers()->write_property(zpqlob, &zmember, zstream, NULL);
+#if PHP_VERSION_ID >= 80000
+       zend_std_write_property(&obj->zo, Z_STR(zmember), zstream, NULL);
+#else
+       ZVAL_OBJ(&zobj, &obj->zo);
+       zend_std_write_property(&zobj, &zmember, zstream, NULL);
+#endif
        zval_ptr_dtor(&zmember);
 }
 
index 3427b383414ab39d7d430adb0174850aac00229e..802fcf4a85484b506ed1c87cc58126869b7704df 100644 (file)
@@ -17,9 +17,7 @@
 #include <php.h>
 
 #include <ext/spl/spl_iterators.h>
-#if PHP_PQ_HAVE_PHP_JSON_H
-#include <php_json.h> /* we've added the include directory to INCLUDES */
-#endif
+#include <ext/json/php_json.h>
 
 #include <libpq-events.h>
 
@@ -45,7 +43,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 +132,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);
@@ -215,7 +213,7 @@ zval *php_pqres_typed_zval(php_pqres_t *res, Oid typ, zval *zv)
                php_pqdt_from_string(zv, NULL, str->val, str->len, "Y-m-d H:i:s.uO", NULL);
                break;
 
-#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON)
+#ifdef PHP_PQ_OID_JSON
 # ifdef PHP_PQ_OID_JSONB
        case PHP_PQ_OID_JSONB:
 # endif
@@ -227,6 +225,23 @@ zval *php_pqres_typed_zval(php_pqres_t *res, Oid typ, zval *zv)
                break;
 #endif
 
+       case PHP_PQ_OID_BYTEA:
+               if (!(res->auto_convert & PHP_PQRES_CONV_BYTEA)) {
+                       goto noconversion;
+               } else {
+                       size_t to_len;
+                       char *to_str = (char *) PQunescapeBytea((unsigned char *) str->val, &to_len);
+
+                       if (!to_str) {
+                               ZVAL_NULL(zv);
+                               php_error_docref(NULL, E_WARNING, "Failed to unsescape BYTEA: '%s'", str->val);
+                       } else {
+                               ZVAL_STRINGL(zv, to_str, to_len);
+                               PQfreemem(to_str);
+                       }
+               }
+               break;
+
        default:
                if (!(res->auto_convert & PHP_PQRES_CONV_ARRAY)) {
                        goto noconversion;
@@ -378,30 +393,46 @@ 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)
+static inline ZEND_RESULT_CODE php_pqres_count_elements_ex(zend_object *object, zend_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;
        } else {
-               *count = (long) PQntuples(obj->intern->res);
+               *count = (zend_long) PQntuples(obj->intern->res);
                return SUCCESS;
        }
 }
+#if PHP_VERSION_ID >= 80000
+static ZEND_RESULT_CODE php_pqres_count_elements(zend_object *object, zend_long *count)
+{
+       return php_pqres_count_elements_ex(object, count);
+}
+#else
+static ZEND_RESULT_CODE php_pqres_count_elements(zval *object, zend_long *count)
+{
+       return php_pqres_count_elements_ex(Z_OBJ_P(object), count);
+}
+#endif
 
 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 +496,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 +574,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 +613,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;
 
@@ -702,7 +736,7 @@ static ZEND_RESULT_CODE column_nn(php_pqres_object_t *obj, zval *zcol, php_pqres
        }
 
        if (!col->name) {
-               php_error_docref(NULL, E_WARNING, "Failed to find column at index %ld", index);
+               php_error_docref(NULL, E_WARNING, "Failed to find column at index " ZEND_LONG_FMT, index);
                return FAILURE;
        }
        if (col->num == -1) {
@@ -757,7 +791,7 @@ static int apply_bound(zval *zbound, int argc, va_list argv, zend_hash_key *key)
        ZEND_RESULT_CODE *rv = va_arg(argv, ZEND_RESULT_CODE *);
 
        if (!(zvalue = zend_hash_index_find(Z_ARRVAL_P(zrow), key->h))) {
-               php_error_docref(NULL, E_WARNING, "Failed to find column ad index %lu", key->h);
+               php_error_docref(NULL, E_WARNING, "Failed to find column ad index " ZEND_ULONG_FMT, key->h);
                *rv = FAILURE;
                return ZEND_HASH_APPLY_STOP;
        } else {
@@ -1127,7 +1161,7 @@ static PHP_METHOD(pqres, fetchAll) {
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_pqres_count, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_pqres_count, 0, 0, IS_LONG, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqres, count) {
        zend_error_handling zeh;
@@ -1138,9 +1172,9 @@ static PHP_METHOD(pqres, count) {
        zend_restore_error_handling(&zeh);
 
        if (SUCCESS == rv) {
-               long count;
+               zend_long count;
 
-               if (SUCCESS != php_pqres_count_elements(getThis(), &count)) {
+               if (SUCCESS != php_pqres_count_elements_ex(Z_OBJ_P(getThis()), &count)) {
                        throw_exce(EX_UNINITIALIZED, "pq\\Result not initialized");
                } else {
                        RETVAL_LONG(count);
@@ -1174,6 +1208,30 @@ static PHP_METHOD(pqres, desc) {
        }
 }
 
+#if PHP_VERSION_ID >= 80000
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(ai_pqres_getIterator, 0, 0, Traversable, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqres, getIterator)
+{
+       zend_error_handling zeh;
+       ZEND_RESULT_CODE rv;
+
+       zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
+       rv = zend_parse_parameters_none();
+       zend_restore_error_handling(&zeh);
+
+       if (SUCCESS == rv) {
+               php_pqres_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
+
+               if (!obj->intern) {
+                       throw_exce(EX_UNINITIALIZED, "pq\\Result not initialized");
+               } else {
+                       zend_create_internal_iterator_zval(return_value, getThis());
+               }
+       }
+}
+#endif
+
 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 +1242,9 @@ 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)
+#if PHP_VERSION_ID >= 80000
+       PHP_ME(pqres, getIterator, ai_pqres_getIterator, ZEND_ACC_PUBLIC)
+#endif
        {0}
 };
 
@@ -1202,7 +1263,11 @@ 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);
+#if PHP_VERSION_ID >= 80000
+       zend_class_implements(php_pqres_class_entry, 2, zend_ce_aggregate, zend_ce_countable);
+#else
+       zend_class_implements(php_pqres_class_entry, 2, zend_ce_traversable, zend_ce_countable);
+#endif
 
        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);
@@ -1283,9 +1348,8 @@ PHP_MINIT_FUNCTION(pqres)
        zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_SCALAR"), PHP_PQRES_CONV_SCALAR);
        zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_ARRAY"), PHP_PQRES_CONV_ARRAY);
        zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_DATETIME"), PHP_PQRES_CONV_DATETIME);
-#if PHP_PQ_HAVE_PHP_JSON_H
        zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_JSON"), PHP_PQRES_CONV_JSON);
-#endif
+       zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_BYTEA"), PHP_PQRES_CONV_BYTEA);
        zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_ALL"), PHP_PQRES_CONV_ALL);
 
        return SUCCESS;
index cc20ddbbc764e15524f71e0f494b40ac21c84611..79507fdf1fa9ca5b1aac9c77cf930e98786cedfc 100644 (file)
@@ -25,6 +25,7 @@ typedef enum php_pqres_fetch {
 #define PHP_PQRES_CONV_BOOL            0x0001
 #define PHP_PQRES_CONV_INT             0x0002
 #define PHP_PQRES_CONV_FLOAT   0x0004
+#define PHP_PQRES_CONV_BYTEA   0x0008
 #define PHP_PQRES_CONV_SCALAR  0x000f
 #define PHP_PQRES_CONV_ARRAY   0x0010
 #define PHP_PQRES_CONV_DATETIME        0x0020
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..b1f36cf27e5fb2aa4b6bb2b62c81e7455f26981a 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;
@@ -69,7 +69,7 @@ static void php_pqtypes_object_gc_connection(zval *object, void *o, zval *return
        add_next_index_zval(return_value, &zconn);
 }
 
-static int has_dimension(HashTable *ht, zval *member, zend_string **key, zend_long *index)
+static inline int has_dimension(HashTable *ht, zval *member, zend_string **key, zend_long *index)
 {
        if (Z_TYPE_P(member) == IS_LONG) {
                *index = Z_LVAL_P(member);
@@ -94,9 +94,9 @@ 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)
+static inline int php_pqtypes_object_has_dimension_ex(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 +123,21 @@ static int php_pqtypes_object_has_dimension(zval *object, zval *member, int chec
 
        return 0;
 }
+#if PHP_VERSION_ID >= 80000
+static int php_pqtypes_object_has_dimension(zend_object *object, zval *member, int check_empty)
+{
+       return php_pqtypes_object_has_dimension_ex(object, member, check_empty);
+}
+#else
+static int php_pqtypes_object_has_dimension(zval *object, zval *member, int check_empty)
+{
+       return php_pqtypes_object_has_dimension_ex(Z_OBJ_P(object), member, check_empty);
+}
+#endif
 
-static zval *php_pqtypes_object_read_dimension(zval *object, zval *member, int type, zval *rv)
+static inline zval *php_pqtypes_object_read_dimension_ex(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,16 +153,41 @@ static zval *php_pqtypes_object_read_dimension(zval *object, zval *member, int t
 
        return data;
 }
+#if PHP_VERSION_ID >= 80000
+static zval *php_pqtypes_object_read_dimension(zend_object *object, zval *member, int type, zval *rv)
+{
+       return php_pqtypes_object_read_dimension_ex(object, member, type, rv);
+}
+#else
+static zval *php_pqtypes_object_read_dimension(zval *object, zval *member, int type, zval *rv)
+{
+       return php_pqtypes_object_read_dimension_ex(Z_OBJ_P(object), member, type, rv);
+}
+#endif
 
+#if PHP_VERSION_ID >= 80000
+static void php_pqtypes_object_write_dimension(zend_object *object, zval *offset, zval *value)
+{
+       throw_exce(EX_RUNTIME, "pq\\Types object must not be modified");
+}
+#else
 static void php_pqtypes_object_write_dimension(zval *object, zval *offset, zval *value)
 {
        throw_exce(EX_RUNTIME, "pq\\Types object must not be modified");
 }
+#endif
 
+#if PHP_VERSION_ID >= 80000
+static void php_pqtypes_object_unset_dimension(zend_object *object, zval *offset)
+{
+       throw_exce(EX_RUNTIME, "pq\\Types object must not be modified");
+}
+#else
 static void php_pqtypes_object_unset_dimension(zval *object, zval *offset)
 {
        throw_exce(EX_RUNTIME, "pq\\Types object must not be modified");
 }
+#endif
 
 ZEND_BEGIN_ARG_INFO_EX(ai_pqtypes_construct, 0, 0, 1)
        ZEND_ARG_OBJ_INFO(0, connection, pq\\Connection, 0)
@@ -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 9bf235c5fa17ec595b7fcd8bd6939e8ba4a48656..0391d77e059a5fd4359defca669f6961a639a934 100644 (file)
@@ -6,7 +6,10 @@ _ext("pq");
 include "_setup.inc";
 defined("PQ_DSN") or die("skip PQ_DSN undefined");
 try {
-       new pq\Connection(PQ_DSN);
+       $c = new pq\Connection(PQ_DSN);
+       if (defined("SERVER_MIN") && version_compare(SERVER_MIN, $c->serverVersion) > 0) {
+               die("skip server {$c->serverVersion} is too old, needed " . SERVER_MIN);
+       }
 } catch (pq\Exception $e) {
        die("skip could not connect to PQ_DSN ".$e->getMessage());
 }
index 7272272ed54ab5a891a8350393b0031280d5dbc1..4b2a54b5e8c6ae1134580780dc101356ba9a0731 100644 (file)
@@ -45,5 +45,5 @@ DONE
 --EXPECTREGEX--
 Test
 (WP(RP)*)+S
-2(,\d)*,0
+[23](,\d*)*,0
 DONE
index bd098630a310075d1d58a46af09059116f517603..a1f0180274a256ea544d973338774f8f0a9f5085 100644 (file)
@@ -55,7 +55,7 @@ DONE
 --EXPECTREGEX--
 Test
 (WP(RP)*)+S
-2(,\d)*,0
+[23](,\d*)*,0
 (WP(RP)*)+S
-2(,\d)*,0
+[23](,\d*)*,0
 DONE
diff --git a/tests/async010.phpt b/tests/async010.phpt
new file mode 100644 (file)
index 0000000..a38b66d
--- /dev/null
@@ -0,0 +1,67 @@
+--TEST--
+asnyc query not cleaned before sync exec
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+
+var_dump([
+       "async" => $c->execAsync("select clock_timestamp(), pg_sleep(0.1), clock_timestamp()", function($r) {
+               var_dump([
+                       "cb" => $r->fetchRow()
+               ]);
+       })
+]);
+
+var_dump([
+       "execParams" => $c->execParams("select \$1::int4", [123])->fetchRow()
+]);
+?>
+DONE
+--EXPECTF--
+Test
+array(1) {
+  ["async"]=>
+  NULL
+}
+array(1) {
+  ["cb"]=>
+  array(3) {
+    [0]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(14) "Y-m-d H:i:s.uO"
+      ["date"]=>
+      string(26) "%s"
+      ["timezone_type"]=>
+      int(1)
+      ["timezone"]=>
+      string(6) "%s"
+    }
+    [1]=>
+    string(0) ""
+    [2]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(14) "Y-m-d H:i:s.uO"
+      ["date"]=>
+      string(26) "%s"
+      ["timezone_type"]=>
+      int(1)
+      ["timezone"]=>
+      string(6) "%s"
+    }
+  }
+}
+array(1) {
+  ["execParams"]=>
+  array(1) {
+    [0]=>
+    int(123)
+  }
+}
+DONE
diff --git a/tests/basic003.phpt b/tests/basic003.phpt
new file mode 100644 (file)
index 0000000..4645e8c
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+basic functionality
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+
+var_dump($c->libraryVersion);
+var_dump($c->protocolVersion);
+var_dump($c->serverVersion);
+?>
+DONE
+--EXPECTF--
+Test
+string(%d) "%s"
+int(%d)
+string(%d) "%s"
+DONE
index 2cc5896996ea34f494b3771db97511f119377c2a..4ca9664aa8a390a7592982b27f35a9a323f23d46 100644 (file)
@@ -9,6 +9,11 @@ echo "Test\n";
 include "_setup.inc";
 
 $c = new pq\Connection(PQ_DSN);
+try {
+       $c->exec("SET lc_messages TO 'C'");
+} catch (pq\Exception $e) {
+       // no not fail if we are not superuser
+}
 
 $x = new pq\Cancel($c);
 
index a9f4d1909ba4ff1bf4f7b3e4cbcec4212fe7faea..c97d73aa34b2102128a2d6e006061bd3b1a9a9a8 100644 (file)
@@ -3,6 +3,8 @@ crash txn reverse dependency from connection
 --SKIPIF--
 <?php
 include "_skipif.inc";
+if (version_compare(PHP_VERSION, "8.2", ">="))
+       echo "skip PHP_VERSION>=8.2 (dynamic properties deprecated)\n";
 ?>
 --FILE--
 <?php
index 4110f59d6d4392b840d8dd6476cb780bc104db18..3f5fa08a594959841700a41a276c947960038b2e 100644 (file)
@@ -1,11 +1,13 @@
 --TEST--
 crash stm reverse dependency from connection
 --SKIPIF--
-<?php 
+<?php
 include "_skipif.inc";
+if (version_compare(PHP_VERSION, "8.2", ">="))
+       echo "skip PHP_VERSION>=8.2 (dynamic properties deprecated)\n";
 ?>
 --FILE--
-<?php 
+<?php
 echo "Test\n";
 
 include "_setup.inc";
index d1a5cf181527d1e6dd570720f7b15aafd9babbc4..cddb5dfc161628357f055a7bb210a13323cc3cdf 100644 (file)
@@ -3,6 +3,8 @@ crash txn reverse dependency from connection
 --SKIPIF--
 <?php
 include "_skipif.inc";
+if (version_compare(PHP_VERSION, "8.2", ">="))
+       echo "skip PHP_VERSION>=8.2 (dynamic properties deprecated)\n";
 ?>
 --FILE--
 <?php
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);
 }
diff --git a/tests/gh-issue047_jsonb.phpt b/tests/gh-issue047_jsonb.phpt
new file mode 100644 (file)
index 0000000..5e145fb
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+json conv broken since 2.2.1
+--SKIPIF--
+<?php
+define("SERVER_MIN", "9.4");
+include "_skipif.inc";
+?>
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+echo "Test\n";
+
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+$c->defaultFetchType = \pq\Result::FETCH_ASSOC;
+
+$q = <<<EOF
+    SELECT '0'::jsonb UNION SELECT '"text"'::jsonb;
+EOF;
+$r = $c->exec($q);
+
+var_dump($r->fetchAll());
+?>
+===DONE===
+--EXPECT--
+Test
+array(2) {
+  [0]=>
+  array(1) {
+    ["jsonb"]=>
+    string(4) "text"
+  }
+  [1]=>
+  array(1) {
+    ["jsonb"]=>
+    int(0)
+  }
+}
+===DONE===
index b2a36670a8830dded2914385b40c78e0f4dac90e..a3252475839ade683a1db91662cc24f87a9f31f5 100644 (file)
@@ -19,7 +19,13 @@ class r extends pq\Result {
        public $dummy = 2;
 }
 
-var_dump(new pq\Result, get_object_vars(new r));
+var_dump(new pq\Result);
+
+echo "Test\n";
+$v = get_object_vars(new r);
+ksort($v);
+var_dump($v);
+
 ?>
 Done
 --EXPECTF--
@@ -42,6 +48,27 @@ Warning: pq\Result not initialized in %s on line %d
 Warning: pq\Result not initialized in %s on line %d
 
 Warning: pq\Result not initialized in %s on line %d
+object(pq\Result)#%d (9) {
+  ["status"]=>
+  NULL
+  ["statusMessage"]=>
+  NULL
+  ["errorMessage"]=>
+  NULL
+  ["diag"]=>
+  NULL
+  ["numRows"]=>
+  int(0)
+  ["numCols"]=>
+  int(0)
+  ["affectedRows"]=>
+  int(0)
+  ["fetchType"]=>
+  int(0)
+  ["autoConvert"]=>
+  int(65535)
+}
+Test
 
 Warning: pq\Result not initialized in %s on line %d
 
@@ -62,46 +89,26 @@ Warning: pq\Result not initialized in %s on line %d
 Warning: pq\Result not initialized in %s on line %d
 
 Warning: pq\Result not initialized in %s on line %d
-object(pq\Result)#%d (9) {
-  ["status"]=>
-  NULL
-  ["statusMessage"]=>
-  NULL
-  ["errorMessage"]=>
-  NULL
-  ["diag"]=>
-  NULL
-  ["numRows"]=>
-  int(0)
-  ["numCols"]=>
-  int(0)
+array(10) {
   ["affectedRows"]=>
   int(0)
-  ["fetchType"]=>
-  int(0)
   ["autoConvert"]=>
   int(65535)
-}
-array(10) {
+  ["diag"]=>
+  NULL
   ["dummy"]=>
   int(2)
-  ["status"]=>
-  NULL
-  ["statusMessage"]=>
-  NULL
   ["errorMessage"]=>
   NULL
-  ["diag"]=>
-  NULL
-  ["numRows"]=>
+  ["fetchType"]=>
   int(0)
   ["numCols"]=>
   int(0)
-  ["affectedRows"]=>
-  int(0)
-  ["fetchType"]=>
+  ["numRows"]=>
   int(0)
-  ["autoConvert"]=>
-  int(65535)
+  ["status"]=>
+  NULL
+  ["statusMessage"]=>
+  NULL
 }
 Done
index 1dc97baff9d1fa1bbe8eb0be2c3758be8cb59e0d..001dec0ed14dbf070bc2b7841ed63d24cde3f4fb 100644 (file)
@@ -11,6 +11,11 @@ include "_setup.inc";
 $c = new pq\Connection(PQ_DSN);
 $c->exec("DROP TABLE IF EXISTS test CASCADE");
 $c->exec("SET client_min_messages TO NOTICE");
+try {
+       $c->exec("SET lc_messages TO 'C'");
+} catch (pq\Exception $e) {
+       // do not die if we are not superuser
+}
 $c->on(pq\Connection::EVENT_NOTICE, function($c, $notice) {
        echo "Got notice: $notice\n";
 });
index 9d36788706311b8a414e5d3f8de8b2fca0288071..c288ec15869ab71cb82227d0ec22b73f11f4705b 100644 (file)
@@ -26,14 +26,16 @@ true as bool,
 '2013-01-01 01:01:01 UTC'::timestamptz as timestamptz,
 array[array[1,2,3],array[4,5,6],array[NULL::int,NULL::int,NULL::int]] as intarray,
 array[box(point(1,2),point(2,3)),box(point(4,5),point(5,6))] as boxarray,
-array[]::text[] as emptyarray
+array[]::text[] as emptyarray,
+'foo\n'::bytea as bytea,
+'foo\n'::bytea::text as bytea_text
 ");
 var_dump($r->fetchRow(pq\Result::FETCH_ASSOC));
 ?>
 DONE
 --EXPECTF--
 Test
-array(13) {
+array(15) {
   ["null"]=>
   NULL
   ["bool"]=>
@@ -121,5 +123,10 @@ array(13) {
   ["emptyarray"]=>
   array(0) {
   }
+  ["bytea"]=>
+  string(4) "foo
+"
+  ["bytea_text"]=>
+  string(10) "\x666f6f0a"
 }
-DONE
\ No newline at end of file
+DONE
diff --git a/travis/pecl b/travis/pecl
deleted file mode 160000 (submodule)
index 309d295..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 309d295271f95d9267c64535de8c2e638f6614cc