Skip to content

Commit 5d2dd03

Browse files
committed
Merge pull request #180 from krakjoe/moar-tests-passing
moar tests passing
2 parents c843be0 + aaed353 commit 5d2dd03

9 files changed

+49
-41
lines changed

.travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: php
22
php:
3-
- 5.5
4-
#- 5.4
5-
#- 5.3
3+
- 7.0
4+
65
env:
76
- LIBMEMCACHED_VERSION=1.0.17
87
- LIBMEMCACHED_VERSION=1.0.16

.travis/travis.sh

+8-7
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ function build_php_memcached() {
128128
sasl_flag="--enable-memcached-sasl"
129129
fi
130130

131-
./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag --enable-memcached-json --enable-memcached-igbinary --enable-memcached-msgpack
132-
make
131+
# ./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag --enable-memcached-json --enable-memcached-igbinary --enable-memcached-msgpack
132+
./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag
133+
make
133134
make install
134135
popd
135136
}
@@ -155,11 +156,11 @@ function run_memcached_tests() {
155156

156157
pushd "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}"
157158
# We have one xfail test, we run it separately
158-
php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/expire.phpt
159+
php run-tests.php -d extension=memcached.so -n ./tests/expire.phpt
159160
rm ./tests/expire.phpt
160161

161162
# Run normal tests
162-
php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/*.phpt
163+
php run-tests.php -d extension=memcached.so -n ./tests/*.phpt
163164
retval=$?
164165
for i in `ls tests/*.out 2>/dev/null`; do
165166
echo "-- START ${i}";
@@ -213,14 +214,14 @@ case $ACTION in
213214
install_libmemcached
214215

215216
# Install igbinary extension
216-
install_igbinary
217+
# install_igbinary
217218

218219
# install msgpack
219-
install_msgpack
220+
# install_msgpack
220221

221222
# install SASL
222223
if test "x$ENABLE_SASL" = "xyes"; then
223-
install_sasl
224+
install_sasl
224225
fi
225226
;;
226227

php_memcached.c

+21-19
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ typedef struct {
170170
} php_memc_t;
171171

172172
static inline php_memc_t *php_memc_fetch_object(zend_object *obj) {
173-
return (php_memc_t *)((char *)(obj) - XtOffsetOf(php_memc_t, zo));
173+
return (php_memc_t *)((char *)obj - XtOffsetOf(php_memc_t, zo));
174174
}
175175
#define Z_MEMC_OBJ_P(zv) php_memc_fetch_object(Z_OBJ_P(zv));
176176

@@ -356,20 +356,17 @@ char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_
356356
static zend_bool php_memcached_on_new_callback(zval *object, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, zend_string *persistent_id)
357357
{
358358
zend_bool ret = 1;
359-
zval retval;
360-
zval params[2];
359+
zval retval, id;
361360

362361
if (persistent_id) {
363-
ZVAL_STR(&params[1], persistent_id);
362+
ZVAL_STR(&id, persistent_id);
364363
} else {
365-
ZVAL_NULL(&params[1]);
364+
ZVAL_NULL(&id);
366365
}
367366

368-
/* Call the cb */
369-
ZVAL_COPY(&params[0], object);
367+
ZVAL_UNDEF(&retval);
370368

371-
fci->params = params;
372-
fci->param_count = 2;
369+
zend_fcall_info_argn(fci, 2, object, &id);
373370
fci->retval = &retval;
374371
fci->no_separation = 1;
375372

@@ -379,10 +376,12 @@ static zend_bool php_memcached_on_new_callback(zval *object, zend_fcall_info *fc
379376
efree (buf);
380377
ret = 0;
381378
}
379+
380+
if (Z_TYPE(retval) != IS_UNDEF)
381+
zval_ptr_dtor(&retval);
382+
383+
zend_fcall_info_args_clear(fci, 1);
382384

383-
zval_ptr_dtor(&params[0]);
384-
zval_ptr_dtor(&params[1]);
385-
zval_ptr_dtor(&retval);
386385
return ret;
387386
}
388387

@@ -407,7 +406,7 @@ static PHP_METHOD(Memcached, __construct)
407406
zend_fcall_info fci = {0};
408407
zend_fcall_info_cache fci_cache;
409408

410-
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|S!f!S", &persistent_id, &fci, &fci_cache, &conn_str) == FAILURE) {
409+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!f!S", &persistent_id, &fci, &fci_cache, &conn_str) == FAILURE) {
411410
return;
412411
}
413412

@@ -3295,6 +3294,7 @@ zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_typ
32953294

32963295
PHP_VAR_UNSERIALIZE_INIT(var_hash);
32973296
if (!php_var_unserialize(value, (const unsigned char **)&payload_tmp, (const unsigned char *)payload_tmp + payload_len, &var_hash)) {
3297+
zval_ptr_dtor(value);
32983298
ZVAL_FALSE(value);
32993299
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
33003300
php_error_docref(NULL, E_WARNING, "could not unserialize value");
@@ -3529,6 +3529,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35293529
fci->param_count = 4;
35303530

35313531
result = zend_call_function(fci, fcc);
3532+
35323533
ZVAL_DUP(value, Z_REFVAL(z_val));
35333534
expiration = Z_REFVAL(z_expiration);
35343535
if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
@@ -3573,6 +3574,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
35733574
zval_ptr_dtor(&z_key);
35743575
zval_ptr_dtor(&z_val);
35753576
zval_ptr_dtor(&z_expiration);
3577+
zval_ptr_dtor(zmemc_obj);
35763578

35773579
return status;
35783580
}
@@ -3594,9 +3596,7 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
35943596
int rc = 0;
35953597
php_memc_t *i_obj = NULL;
35963598

3597-
ZVAL_COPY(&params[0], zmemc_obj);
35983599
fci->retval = &retval;
3599-
fci->params = params;
36003600
fci->param_count = 2;
36013601

36023602
payload = memcached_result_value(result);
@@ -3615,7 +3615,6 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
36153615
}
36163616

36173617
array_init(&z_result);
3618-
ZVAL_COPY(&params[1], &z_result);
36193618
add_assoc_stringl_ex(&z_result, ZEND_STRL("key"), (char *)res_key, res_key_len);
36203619
add_assoc_zval_ex(&z_result, ZEND_STRL("value"), &value);
36213620
if (cas != 0) {
@@ -3625,16 +3624,19 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
36253624
add_assoc_long_ex(&z_result, ZEND_STRL("flags"), MEMC_VAL_GET_USER_FLAGS(flags));
36263625
}
36273626

3627+
ZVAL_UNDEF(&retval);
3628+
zend_fcall_info_argn(fci, 2, zmemc_obj, &z_result);
3629+
36283630
if (zend_call_function(fci, fcc) == FAILURE) {
36293631
php_error_docref(NULL, E_WARNING, "could not invoke result callback");
36303632
rc = -1;
36313633
}
36323634

3633-
if (&retval) {
3635+
if (Z_TYPE(retval) != IS_UNDEF) {
36343636
zval_ptr_dtor(&retval);
36353637
}
3636-
zval_ptr_dtor(&params[0]);
3637-
zval_ptr_dtor(&params[1]);
3638+
3639+
zend_fcall_info_args_clear(fci, 1);
36383640
zval_ptr_dtor(&z_result);
36393641

36403642
return rc;

tests/bad_construct.phpt

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Memcached construct with bad arguments
44
<?php if (!extension_loaded("memcached")) print "skip"; ?>
55
--FILE--
66
<?php
7-
error_reporting(0);
7+
88
$m = new Memcached((object)array());
99
echo $php_errormsg, "\n";
1010
var_dump($m);
@@ -21,9 +21,12 @@ var_dump ($extended->setOption (Memcached::OPT_BINARY_PROTOCOL, true));
2121
echo "OK" . PHP_EOL;
2222

2323
--EXPECTF--
24-
Memcached::__construct() expects parameter %s
25-
NULL
24+
Warning: Memcached::__construct() expects parameter 1 to be string, object given in %s on line 3
25+
Memcached::__construct() expects parameter 1 to be string, object given
26+
object(Memcached)#1 (0) {
27+
}
2628

27-
Warning: Memcached::setOption(): Memcached constructor was not called in %s on line %d
29+
Warning: Memcached::setOption(): Memcached constructor was not called in %s on line 14
2830
NULL
29-
OK
31+
OK
32+

tests/clone.phpt

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ $m = clone $m;
1212

1313
echo "GOT HERE";
1414
--EXPECTF--
15-
Fatal error: Trying to clone an uncloneable object of class Memcached in %s on line %d
15+
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class Memcached in %s:6
16+
Stack trace:
17+
#0 {main}
18+
thrown in %s on line 6

tests/experimental/cas_invalid_key.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ error_reporting(0);
1111
var_dump($m->cas(0, '', true, 10));
1212
echo $m->getResultMessage(), "\n";
1313

14-
var_dump($m->cas(0, ' äö jas kjjhask d ', true, 10));
14+
var_dump($m->cas(0, ' äö jas kjjhask d ', true, 10)); # no spaces allowed
1515
echo $m->getResultMessage(), "\n";
1616

1717
--EXPECTF--
1818
bool(false)
1919
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
2020
bool(false)
21-
%rCLIENT ERROR|NOT FOUND%r
21+
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE

tests/experimental/delete_bykey.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var_dump($m->deleteByKey('keffe', ''));
2121
echo $m->getResultMessage(), "\n";
2222
var_dump($m->deleteByKey('', 'keffe'));
2323
echo $m->getResultMessage(), "\n";
24-
var_dump($m->deleteByKey('keffe', 'äöåasäö åaösdäf asdf'));
24+
var_dump($m->deleteByKey('keffe', 'äöåasäö åaösdäf asdf')); # no spaces allowed
2525
echo $m->getResultMessage(), "\n";
2626
--EXPECTF--
2727
string(3) "foo"
@@ -37,4 +37,4 @@ A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
3737
bool(false)
3838
NOT FOUND
3939
bool(false)
40-
%rPROTOCOL ERROR|NOT FOUND|WRITE FAILURE|CLIENT ERROR%r
40+
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE

tests/experimental/get.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
3030
string(4) "asdf"
3131
SUCCESS
3232
bool(false)
33-
NOT FOUND
33+
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE

tests/experimental/get_bykey_cas.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ string(4) "asdf"
5959
float(%d)
6060
SUCCESS
6161
bool(false)
62-
NULL
62+
float(0)
6363
NOT FOUND
6464
bool(false)
6565
NULL

0 commit comments

Comments
 (0)