Skip to content

Commit

Permalink
Add terminating character to zend_lookup_class call (#5871)
Browse files Browse the repository at this point in the history
* add terminating character

* adjust name length input

* add test cases

* correct script name

* Misc fixes

* add new script to EXTRA_DIST list
  • Loading branch information
dwsupplee authored and TeBoring committed Mar 13, 2019
1 parent 791b863 commit 93533f7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ php_EXTRA_DIST= \
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/gdb_test.sh \
Expand Down
3 changes: 2 additions & 1 deletion php/ext/google/protobuf/def.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,10 @@ static zend_class_entry *register_class(const upb_filedef *file,

fill_namespace(package, php_namespace, &namesink);
fill_classname(fullname, package, prefix, &namesink, use_nested_submsg);
stringsink_string(&namesink, NULL, "\0", 1, NULL);

PHP_PROTO_CE_DECLARE pce;
if (php_proto_zend_lookup_class(namesink.ptr, namesink.len, &pce) ==
if (php_proto_zend_lookup_class(namesink.ptr, namesink.len - 1, &pce) ==
FAILURE) {
zend_error(
E_ERROR,
Expand Down
10 changes: 10 additions & 0 deletions php/tests/compile_extension.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

EXTENSION_PATH=$1

pushd $EXTENSION_PATH
make clean || true
set -e
# Add following in configure for debug: --enable-debug CFLAGS='-g -O0'
phpize && ./configure CFLAGS='-g -O0' && make
popd
11 changes: 11 additions & 0 deletions php/tests/php_implementation_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\CodedOutputStream;

/**
* Please note, this test is only intended to be run without the protobuf C
* extension.
*/
class ImplementationTest extends TestBase
{
public function setUp()
{
if (extension_loaded('protobuf')) {
$this->markTestSkipped();
}
}

public function testReadInt32()
{
$value = null;
Expand Down
7 changes: 1 addition & 6 deletions php/tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ export C_INCLUDE_PATH=/usr/local/php-$VERSION/include/php/main:/usr/local/php-$V
export CPLUS_INCLUDE_PATH=/usr/local/php-$VERSION/include/php/main:/usr/local/php-$VERSION/include/php:$CPLUS_INCLUDE_PATH

# Compile c extension
pushd ../ext/google/protobuf/
make clean || true
set -e
# Add following in configure for debug: --enable-debug CFLAGS='-g -O0'
phpize && ./configure CFLAGS='-g -O0' && make
popd
/bin/bash ./compile_extension.sh ../ext/google/protobuf

tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php well_known_test.php descriptors_test.php wrapper_type_setters_test.php)

Expand Down
44 changes: 44 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,16 @@ build_php5.5_c() {
# popd
}

build_php5.5_mixed() {
use_php 5.5
pushd php
rm -rf vendor
composer update
/bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
popd
}

build_php5.5_zts_c() {
use_php_zts 5.5
cd php/tests && /bin/bash ./test.sh 5.5-zts && cd ../..
Expand Down Expand Up @@ -497,6 +507,16 @@ build_php5.6_c() {
# popd
}

build_php5.6_mixed() {
use_php 5.6
pushd php
rm -rf vendor
composer update
/bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
popd
}

build_php5.6_zts_c() {
use_php_zts 5.6
cd php/tests && /bin/bash ./test.sh 5.6-zts && cd ../..
Expand Down Expand Up @@ -552,6 +572,16 @@ build_php7.0_c() {
# popd
}

build_php7.0_mixed() {
use_php 7.0
pushd php
rm -rf vendor
composer update
/bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
popd
}

build_php7.0_zts_c() {
use_php_zts 7.0
cd php/tests && /bin/bash ./test.sh 7.0-zts && cd ../..
Expand Down Expand Up @@ -615,6 +645,16 @@ build_php7.1_c() {
fi
}

build_php7.1_mixed() {
use_php 7.1
pushd php
rm -rf vendor
composer update
/bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
popd
}

build_php7.1_zts_c() {
use_php_zts 7.1
cd php/tests && /bin/bash ./test.sh 7.1-zts && cd ../..
Expand All @@ -632,6 +672,10 @@ build_php_all_32() {
build_php5.6_c
build_php7.0_c
build_php7.1_c $1
build_php5.5_mixed
build_php5.6_mixed
build_php7.0_mixed
build_php7.1_mixed
build_php5.5_zts_c
build_php5.6_zts_c
build_php7.0_zts_c
Expand Down

0 comments on commit 93533f7

Please sign in to comment.