Skip to content

Commit

Permalink
Add TravisCI builds for arm64, ppc64le, and s390x
Browse files Browse the repository at this point in the history
* Adjust tests to pass on ppc64le
  • Loading branch information
jbboehr committed Jun 26, 2020
1 parent a473dac commit 125d254
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 31 deletions.
5 changes: 3 additions & 2 deletions .ci/travis_php.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash

export LIBHANDLEBARS_VERSION=${LIBHANDLEBARS_VERSION:-master}
#export PHP_PSR_VERSION=${PHP_PSR_VERSION:-master}
export PHP_PSR_VERSION=${PHP_PSR_VERSION:-master}
export AST=${AST:-false}
export PSR=${AST:-false}
export COVERAGE=${COVERAGE:-true}
export HARDENING=${HARDENING:-true}

Expand Down Expand Up @@ -150,7 +151,7 @@ function script() (
set -e -o pipefail

extra_flags=""
if [[ ! -z "${PHP_PSR_VERSION}" ]]; then
if [ "$PSR" = "true" ]; then
extra_flags="-d extension=third-party/php-psr/modules/psr.so"
fi

Expand Down
19 changes: 15 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ matrix:
php: '7.4'
- language: php
php: 'master'
# arches
- language: php
arch: arm64
php: '7.4'
- language: php
arch: ppc64le
php: '7.4'
- language: php
arch: s390x
php: '7.4'
# no hardening
- language: php
php: '7.4'
Expand All @@ -25,22 +35,22 @@ matrix:
php: '7.2'
env:
- AST=true
- PHP_PSR_VERSION=v1.0.0
- PSR=true
- language: php
php: '7.3'
env:
- AST=true
- PHP_PSR_VERSION=v1.0.0
- PSR=true
- language: php
php: '7.4'
env:
- AST=true
- PHP_PSR_VERSION=v1.0.0
- PSR=true
- language: php
php: 'master'
env:
- AST=true
- PHP_PSR_VERSION=v1.0.0
- PSR=true
# fedora
- services:
- docker
Expand All @@ -50,6 +60,7 @@ matrix:
env:
global:
- LIBHANDLEBARS_VERSION=8fe6213e3a15dec63e824d90e124949fffb07b91
- PHP_PSR_VERSION=v1.0.0

branches:
only:
Expand Down
37 changes: 21 additions & 16 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PHP_METHOD(HandlebarsUtils, appendContextPath)
zend_string * id = NULL;
zval * entry = NULL;
zend_string * tmp = NULL;
char * out;
zval rv = {0};

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_ZVAL(context_path)
Expand All @@ -40,28 +40,32 @@ PHP_METHOD(HandlebarsUtils, appendContextPath)

switch( Z_TYPE_P(context_path) ) {
case IS_ARRAY:
if( (entry = zend_hash_find(HASH_OF(context_path), INTERNED_CONTEXT_PATH)) ) {
if( Z_TYPE_P(entry) == IS_STRING ) {
tmp = Z_STR_P(entry);
}
}
entry = zend_hash_find(HASH_OF(context_path), INTERNED_CONTEXT_PATH);
break;
case IS_OBJECT:
entry = zend_read_property_ex(Z_OBJCE_P(context_path), context_path, INTERNED_CONTEXT_PATH, 1, NULL);
if( entry && Z_TYPE_P(entry) == IS_STRING ) {
tmp = Z_STR_P(entry);
}
entry = zend_read_property_ex(Z_OBJCE_P(context_path), context_path, INTERNED_CONTEXT_PATH, 1, &rv);
break;
case IS_STRING:
tmp = Z_STR_P(context_path);
entry = context_path;
break;
default: assert(0); break;
}

if( tmp != NULL && ZSTR_LEN(tmp) > 0 ) {
spprintf(&out, 0, "%.*s.%.*s", (int) ZSTR_LEN(tmp), ZSTR_VAL(tmp), (int) ZSTR_LEN(id), ZSTR_VAL(id));
RETVAL_STRING(out);
efree(out);
if (entry && Z_TYPE_P(entry) == IS_STRING) {
tmp = Z_STR_P(entry);
}

if (tmp != NULL && ZSTR_LEN(tmp) > 0) {
struct handlebars_string * tmp_str = handlebars_string_asprintf(
HANDLEBARS_G(context),
"%.*s.%.*s",
(int) ZSTR_LEN(tmp),
ZSTR_VAL(tmp),
(int) ZSTR_LEN(id),
ZSTR_VAL(id)
);
HBS_RETVAL_STR(tmp_str);
handlebars_string_delref(tmp_str);
} else {
RETVAL_STR(id);
}
Expand Down Expand Up @@ -117,6 +121,7 @@ void php_handlebars_name_lookup(zval * value, zval * field, zval * return_value)
zval * entry = NULL;
zval result;
zval *retval = NULL;
zval rv = {0};

ZVAL_UNDEF(&result);

Expand Down Expand Up @@ -163,7 +168,7 @@ void php_handlebars_name_lookup(zval * value, zval * field, zval * return_value)
RETVAL_ZVAL(&result, 0, 0);
}
} else {
entry = zend_read_property_ex(Z_OBJCE_P(value), value, Z_STR_P(field), 1, NULL);
entry = zend_read_property_ex(Z_OBJCE_P(value), value, Z_STR_P(field), 1, &rv);
}
break;
default: assert(0); break;
Expand Down
9 changes: 5 additions & 4 deletions tests/object-iteration.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ var_dump($vm->render('{{#each a}}{{@key}}={{.}},{{/each}}', [
'a' => new stdClass(),
]));

// casting array to object is broken on ppc64le
$obj = new stdClass;
$obj->b = 'c';
$obj->d = 'e';
var_dump($vm->render('{{#each a}}{{@key}}={{.}},{{/each}}', [
'a' => (object) [
'b' => 'c',
'd' => 'e',
],
'a' => $obj,
]));

var_dump($vm->render('{{#each a}}{{@key}}={{.}},{{/each}}', [
Expand Down
5 changes: 4 additions & 1 deletion tests/utils/appendContextPath.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ Handlebars\Utils::appendContextPath()
<?php
use Handlebars\Utils;
var_dump(Utils::appendContextPath(array('contextPath' => 'foo'), 'bar'));
var_dump(Utils::appendContextPath((object) array('contextPath' => 'foo'), 'bar'));
// casting array to object is broken on ppc64le
$obj = new stdClass;
$obj->contextPath = 'foo';
var_dump(Utils::appendContextPath($obj, 'bar'));
var_dump(Utils::appendContextPath('foo', 'bar'));
var_dump(Utils::appendContextPath(array(), 'bar'));
var_dump(Utils::appendContextPath(null, 'bar'));
Expand Down
5 changes: 4 additions & 1 deletion tests/utils/expression.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ try {
var_dump(Utils::expression('string'));
var_dump(Utils::expression(new MyString));
try {
var_dump(Utils::expression((object) array('a' => 'b')));
// casting array to object is broken on ppc64le
$obj = new stdClass;
$obj->a = 'b';
var_dump(Utils::expression($obj));
} catch( \Exception $e ) {
var_dump(get_class($e));
}
Expand Down
15 changes: 12 additions & 3 deletions tests/utils/nameLookup.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ class HandlebarsLookupArrayAccessFixture implements ArrayAccess {
error_reporting(E_ALL);

var_dump(Utils::nameLookup(array('foo' => 'bar1'), 'foo'));
var_dump(Utils::nameLookup((object) array('foo' => 'bar2'), 'foo'));
// casting array to object is broken on ppc64le
$obj = new stdClass;
$obj->foo = 'bar2';
var_dump(Utils::nameLookup($obj, 'foo'));
var_dump(Utils::nameLookup(new \ArrayObject(array('foo' => 'bar3')), 'foo'));
var_dump(Utils::nameLookup(new HandlebarsLookupArrayAccessFixture(array('foo' => 'bar4')), 'foo'));
var_dump(Utils::nameLookup(null, 'foo'));
var_dump((array) Utils::nameLookup((object) array('foo' => (object) array('bar' => 'baz')), 'foo'));
// casting array to object is broken on ppc64le
$obj2 = new stdClass;
$obj2->bar = 'baz';
$obj3 = new stdClass;
$obj3->foo = $obj2;
var_dump((array) Utils::nameLookup($obj3, 'foo'));
var_dump(Utils::nameLookup(array(404 => 'bar5'), 404));
// Make sure it doesn't cause a notice
var_dump(Utils::nameLookup((object) array(), 'missing'));
// casting array to object is broken on ppc64le
var_dump(Utils::nameLookup(new stdClass, 'missing'));
var_dump(Utils::nameLookup(new ArrayObject(), 'missing'));
var_dump(Utils::nameLookup(new HandlebarsLookupArrayAccessFixture(), 'missing'));
--EXPECT--
Expand Down

0 comments on commit 125d254

Please sign in to comment.