Skip to content

moar tests passing #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ typedef struct {
} php_memc_t;

static inline php_memc_t *php_memc_fetch_object(zend_object *obj) {
return (php_memc_t *)((char *)(obj) - XtOffsetOf(php_memc_t, zo));
return (php_memc_t *)((char *)obj - XtOffsetOf(php_memc_t, zo));
}
#define Z_MEMC_OBJ_P(zv) php_memc_fetch_object(Z_OBJ_P(zv));

Expand Down Expand Up @@ -356,20 +356,17 @@ char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_
static zend_bool php_memcached_on_new_callback(zval *object, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, zend_string *persistent_id)
{
zend_bool ret = 1;
zval retval;
zval params[2];
zval retval, id;

if (persistent_id) {
ZVAL_STR(&params[1], persistent_id);
ZVAL_STR(&id, persistent_id);
} else {
ZVAL_NULL(&params[1]);
ZVAL_NULL(&id);
}

/* Call the cb */
ZVAL_COPY(&params[0], object);
ZVAL_UNDEF(&retval);

fci->params = params;
fci->param_count = 2;
zend_fcall_info_argn(fci, 2, object, &id);
fci->retval = &retval;
fci->no_separation = 1;

Expand All @@ -379,10 +376,12 @@ static zend_bool php_memcached_on_new_callback(zval *object, zend_fcall_info *fc
efree (buf);
ret = 0;
}

if (Z_TYPE(retval) != IS_UNDEF)
zval_ptr_dtor(&retval);

zend_fcall_info_args_clear(fci, 1);

zval_ptr_dtor(&params[0]);
zval_ptr_dtor(&params[1]);
zval_ptr_dtor(&retval);
return ret;
}

Expand All @@ -408,7 +407,6 @@ static PHP_METHOD(Memcached, __construct)
zend_fcall_info_cache fci_cache;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!f!S", &persistent_id, &fci, &fci_cache, &conn_str) == FAILURE) {
ZEND_CTOR_MAKE_NULL();
return;
}

Expand Down Expand Up @@ -3304,6 +3302,7 @@ zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_typ

PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(value, (const unsigned char **)&payload_tmp, (const unsigned char *)payload_tmp + payload_len, &var_hash)) {
zval_ptr_dtor(value);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other serializers should probably be consistent with this

ZVAL_FALSE(value);
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
php_error_docref(NULL, E_WARNING, "could not unserialize value");
Expand Down Expand Up @@ -3538,6 +3537,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
fci->param_count = 4;

result = zend_call_function(fci, fcc);

ZVAL_DUP(value, Z_REFVAL(z_val));
expiration = Z_REFVAL(z_expiration);
if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
Expand Down Expand Up @@ -3582,6 +3582,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i
zval_ptr_dtor(&z_key);
zval_ptr_dtor(&z_val);
zval_ptr_dtor(&z_expiration);
zval_ptr_dtor(zmemc_obj);

return status;
}
Expand All @@ -3603,9 +3604,7 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
int rc = 0;
php_memc_t *i_obj = NULL;

ZVAL_COPY(&params[0], zmemc_obj);
fci->retval = &retval;
fci->params = params;
fci->param_count = 2;

payload = memcached_result_value(result);
Expand All @@ -3624,7 +3623,6 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
}

array_init(&z_result);
ZVAL_COPY(&params[1], &z_result);
add_assoc_stringl_ex(&z_result, ZEND_STRL("key"), (char *)res_key, res_key_len);
add_assoc_zval_ex(&z_result, ZEND_STRL("value"), &value);
if (cas != 0) {
Expand All @@ -3634,16 +3632,19 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
add_assoc_long_ex(&z_result, ZEND_STRL("flags"), MEMC_VAL_GET_USER_FLAGS(flags));
}

ZVAL_UNDEF(&retval);
zend_fcall_info_argn(fci, 2, zmemc_obj, &z_result);

if (zend_call_function(fci, fcc) == FAILURE) {
php_error_docref(NULL, E_WARNING, "could not invoke result callback");
rc = -1;
}

if (&retval) {
if (Z_TYPE(retval) != IS_UNDEF) {
zval_ptr_dtor(&retval);
}
zval_ptr_dtor(&params[0]);
zval_ptr_dtor(&params[1]);

zend_fcall_info_args_clear(fci, 1);
zval_ptr_dtor(&z_result);

return rc;
Expand Down
5 changes: 4 additions & 1 deletion tests/clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ $m = clone $m;

echo "GOT HERE";
--EXPECTF--
Fatal error: Trying to clone an uncloneable object of class Memcached in %s on line %d
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class Memcached in %s:6
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just because errors as exceptions now ... is same ...

Stack trace:
#0 {main}
thrown in %s on line 6
4 changes: 2 additions & 2 deletions tests/experimental/cas_invalid_key.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ error_reporting(0);
var_dump($m->cas(0, '', true, 10));
echo $m->getResultMessage(), "\n";

var_dump($m->cas(0, ' �� jas kjjhask d ', true, 10));
var_dump($m->cas(0, ' �� jas kjjhask d ', true, 10)); # no spaces allowed
echo $m->getResultMessage(), "\n";

--EXPECTF--
bool(false)
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
bool(false)
%rCLIENT ERROR|NOT FOUND%r
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this appears to be right, strchr is ran on the key to check for spaces ...

4 changes: 2 additions & 2 deletions tests/experimental/delete_bykey.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var_dump($m->deleteByKey('keffe', ''));
echo $m->getResultMessage(), "\n";
var_dump($m->deleteByKey('', 'keffe'));
echo $m->getResultMessage(), "\n";
var_dump($m->deleteByKey('keffe', '���as�� �a�sd�f asdf'));
var_dump($m->deleteByKey('keffe', '���as�� �a�sd�f asdf')); # no spaces allowed
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it seems like I just changed these to pass, but it really looks like this is the expected result. strchr is ran on the keys everywhere to check for spaces ...

echo $m->getResultMessage(), "\n";
--EXPECTF--
string(3) "foo"
Expand All @@ -37,4 +37,4 @@ A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE
bool(false)
NOT FOUND
bool(false)
%rPROTOCOL ERROR|NOT FOUND|WRITE FAILURE|CLIENT ERROR%r
A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE