Skip to content

Commit

Permalink
Port php c extension to php8 (#7793)
Browse files Browse the repository at this point in the history
* Only ported c extension to php8.
* Didn't fixed the issue of throwing warnings for missing arginfo in bundled files.
* Tests not fixed, because syntax of phpunit (<7 vs >9.3) are not compatible.
* In next release, needs to drop php5 and php7.0 support (in order to use phpunit > 7)
  • Loading branch information
TeBoring committed Aug 12, 2020
1 parent 008c721 commit d4ca929
Show file tree
Hide file tree
Showing 24 changed files with 282 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ conformance/*.class

# php test output
composer.lock
php/tests/.phpunit.result.cache
php/tests/generated/
php/tests/old_protoc
php/tests/phpunit-9.phar
php/tests/protobuf/
php/tests/core
php/tests/vgcore*
Expand Down
20 changes: 10 additions & 10 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -915,23 +915,23 @@ php_EXTRA_DIST= \
php/src/Google/Protobuf/UInt64Value.php \
php/src/Google/Protobuf/Value.php \
php/src/phpdoc.dist.xml \
php/tests/array_test.php \
php/tests/ArrayTest.php \
php/tests/autoload.php \
php/tests/bootstrap_phpunit.php \
php/tests/compatibility_test.sh \
php/tests/compile_extension.sh \
php/tests/descriptors_test.php \
php/tests/encode_decode_test.php \
php/tests/DescriptorsTest.php \
php/tests/EncodeDecodeTest.php \
php/tests/gdb_test.sh \
php/tests/generate_protos.sh \
php/tests/generated_class_test.php \
php/tests/generated_phpdoc_test.php \
php/tests/generated_service_test.php \
php/tests/map_field_test.php \
php/tests/GeneratedClassTest.php \
php/tests/GeneratedPhpdocTest.php \
php/tests/GeneratedServiceTest.php \
php/tests/MapFieldTest.php \
php/tests/memory_leak_test.php \
php/tests/multirequest.php \
php/tests/multirequest.sh \
php/tests/php_implementation_test.php \
php/tests/PhpImplementationTest.php \
php/tests/proto/empty/echo.proto \
php/tests/proto/test.proto \
php/tests/proto/test_descriptors.proto \
Expand All @@ -955,8 +955,8 @@ php_EXTRA_DIST= \
php/tests/test_util.php \
php/tests/undefined_test.php \
php/tests/valgrind.supp \
php/tests/well_known_test.php \
php/tests/wrapper_type_setters_test.php
php/tests/WellKnownTest.php \
php/tests/WrapperTypeSettersTest.php

python_EXTRA_DIST= \
python/MANIFEST.in \
Expand Down
18 changes: 18 additions & 0 deletions kokoro/linux/php80/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "pull request" project:
#
# This script selects a specific Dockerfile (for building a Docker image) and
# a script to run inside that image. Then we delegate to the general
# build_and_run_docker.sh script.

# Change to repo root
cd $(dirname $0)/../../..

export DOCKERHUB_ORGANIZATION=protobuftesting
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/php
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
export OUTPUT_DIR=testoutput
export TEST_SET="php8.0_all"
./kokoro/linux/build_and_run_docker.sh
11 changes: 11 additions & 0 deletions kokoro/linux/php80/continuous.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Config file for running tests in Kokoro

# Location of the build script in repository
build_file: "protobuf/kokoro/linux/php80/build.sh"
timeout_mins: 120

action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}
11 changes: 11 additions & 0 deletions kokoro/linux/php80/presubmit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Config file for running tests in Kokoro

# Location of the build script in repository
build_file: "protobuf/kokoro/linux/php80/build.sh"
timeout_mins: 120

action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}
18 changes: 14 additions & 4 deletions php/ext/google/protobuf/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ static void RepeatedField_destructor(zend_object* obj) {
zend_object_std_dtor(&intern->std);
}

static HashTable *RepeatedField_GetProperties(zval *object) {
static HashTable *RepeatedField_GetProperties(PROTO_VAL *object) {
return NULL; // We do not have a properties table.
}

static zval *RepeatedField_GetPropertyPtrPtr(zval *object, zval *member,
static zval *RepeatedField_GetPropertyPtrPtr(PROTO_VAL *object,
PROTO_STR *member,
int type, void **cache_slot) {
return NULL; // We don't offer direct references to our properties.
}
Expand Down Expand Up @@ -392,6 +393,15 @@ PHP_METHOD(RepeatedField, getIterator) {
RETURN_ZVAL(&ret, 0, 1);
}

ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 1)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, class)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
Expand All @@ -405,8 +415,8 @@ ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()

static zend_function_entry repeated_field_methods[] = {
PHP_ME(RepeatedField, __construct, NULL, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, append, NULL, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
Expand Down
61 changes: 48 additions & 13 deletions php/ext/google/protobuf/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,55 @@ PHP_METHOD(Util, checkRepeatedField) {
RETURN_ZVAL(val, 1, 0);
}

ZEND_BEGIN_ARG_INFO_EX(arginfo_checkPrimitive, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_checkMessage, 0, 0, 2)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, class)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_checkMapField, 0, 0, 3)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, key_type)
ZEND_ARG_INFO(0, value_type)
ZEND_ARG_INFO(0, value_class)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_checkRepeatedField, 0, 0, 2)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, class)
ZEND_END_ARG_INFO()

static zend_function_entry util_methods[] = {
PHP_ME(Util, checkInt32, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkUint32, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkInt64, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkUint64, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkEnum, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkFloat, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkDouble, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkBool, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkString, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkBytes, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkMessage, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkMapField, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkRepeatedField, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkInt32, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkUint32, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkInt64, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkUint64, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkEnum, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkFloat, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkDouble, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkBool, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkString, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkBytes, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkMessage, arginfo_checkMessage,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkMapField, arginfo_checkMapField,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkRepeatedField, arginfo_checkRepeatedField,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_FE_END
};

Expand Down
16 changes: 11 additions & 5 deletions php/ext/google/protobuf/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ static void MapField_destructor(zend_object* obj) {
zend_object_std_dtor(&intern->std);
}

static zval *Map_GetPropertyPtrPtr(zval *object, zval *member, int type,
void **cache_slot) {
static zval *Map_GetPropertyPtrPtr(PROTO_VAL *object, PROTO_STR *member,
int type, void **cache_slot) {
return NULL; // We don't offer direct references to our properties.
}

static HashTable *map_get_properties(zval *object) {
static HashTable *Map_GetProperties(PROTO_VAL *object) {
return NULL; // We do not have a properties table.
}

Expand Down Expand Up @@ -378,6 +378,12 @@ PHP_METHOD(MapField, getIterator) {
RETURN_ZVAL(&ret, 0, 1);
}

ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 2)
ZEND_ARG_INFO(0, key_type)
ZEND_ARG_INFO(0, value_type)
ZEND_ARG_INFO(0, value_class)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
Expand All @@ -391,7 +397,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()

static zend_function_entry MapField_methods[] = {
PHP_ME(MapField, __construct, NULL, ZEND_ACC_PUBLIC)
PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
Expand Down Expand Up @@ -572,7 +578,7 @@ void Map_ModuleInit() {
h = &MapField_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = MapField_destructor;
h->get_properties = map_get_properties;
h->get_properties = Map_GetProperties;
h->get_property_ptr_ptr = Map_GetPropertyPtrPtr;

INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\MapFieldIter",
Expand Down

0 comments on commit d4ca929

Please sign in to comment.