Skip to content

Commit cdc6471

Browse files
committed
PHPC-130: Update the get_current_key handler to support pre-5.5
1 parent f0b5e2e commit cdc6471

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

php_compat_53.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,25 @@
1010
# define object_properties_init(_std, _class_type) \
1111
zend_hash_copy(_std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
1212
#endif
13+
14+
#if PHP_VERSION_ID >= 50500
15+
#define ITERATOR_GET_CURRENT_KEY(it, z) \
16+
(it).funcs->get_current_key(&(it), z TSRMLS_CC);
17+
#else
18+
#define ITERATOR_GET_CURRENT_KEY(it, z) \
19+
{ \
20+
char *str_key; \
21+
uint str_key_len; \
22+
ulong int_key; \
23+
switch ((it).funcs->get_current_key(&(it), &str_key, &str_key_len, &int_key TSRMLS_CC)) { \
24+
case HASH_KEY_IS_LONG: \
25+
ZVAL_LONG(z, int_key); \
26+
break; \
27+
case HASH_KEY_IS_STRING: \
28+
ZVAL_STRINGL(z, str_key, str_key_len-1, 0); \
29+
break; \
30+
default: \
31+
RETURN_NULL(); \
32+
} \
33+
}
34+
#endif

src/MongoDB/Cursor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ PHP_METHOD(Cursor, key)
246246
}
247247

248248
if (intern->it->iterator.funcs->get_current_key) {
249-
intern->it->iterator.funcs->get_current_key(&intern->it->iterator, return_value TSRMLS_CC);
249+
ITERATOR_GET_CURRENT_KEY(intern->it->iterator, return_value);
250250
} else {
251251
RETURN_LONG(intern->it->current);
252252
}

0 commit comments

Comments
 (0)