Skip to content

Commit

Permalink
Adjust JSON API usage for differences in versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Zmievski committed Jul 17, 2009
1 parent ccbdf1d commit 23dd98b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,5 +1,9 @@
memcached extension changelog

Version 1.0.1
-------------
* Fix php_json.h inclusion.

Version 1.0.0
-------------
* First stable release.
Expand Down
32 changes: 25 additions & 7 deletions php_memcached.c
Expand Up @@ -45,12 +45,15 @@

#include "php_memcached.h"

#ifdef HAVE_MEMCACHED_IGBINARY
#if HAVE_MEMCACHED_IGBINARY
#include "ext/igbinary/igbinary.h"
#endif
#ifdef HAVE_JSON_API
#if HAVE_JSON_API
#include "ext/json/php_json.h"
#endif
#if HAVE_JSON_API_5_3
#include "ext/json/JSON_parser.h"
#endif

/****************************************
Custom options
Expand Down Expand Up @@ -1993,7 +1996,12 @@ static char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t
#if HAVE_JSON_API
case SERIALIZER_JSON:
{

#if HAVE_JSON_API_5_2
php_json_encode(&buf, value TSRMLS_CC);
#elif HAVE_JSON_API_5_3
php_json_encode(&buf, value, 0 TSRMLS_CC); //options
#endif
buf.c[buf.len] = 0;
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_JSON);
break;
Expand Down Expand Up @@ -2157,9 +2165,13 @@ static int php_memc_zval_from_payload(zval *value, char *payload, size_t payload
break;

case MEMC_VAL_IS_JSON:
#if HAVE_JSON_API
#if HAVE_JSON_API_5_2
php_json_decode(value, payload, payload_len, 0 TSRMLS_CC);
#else
#elif HAVE_JSON_API_5_3
php_json_decode(value, payload, payload_len, 0, JSON_PARSER_DEFAULT_DEPTH TSRMLS_CC);
#endif

#if (!HAVE_JSON_API)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not unserialize value, no json support");
return -1;
#endif
Expand Down Expand Up @@ -2791,7 +2803,7 @@ static const zend_module_dep memcached_deps[] = {
#ifdef HAVE_MEMCACHED_SESSION
ZEND_MOD_REQUIRED("session")
#endif
#ifdef HAVA_MEMCACHED_IGBINARY
#ifdef HAVE_MEMCACHED_IGBINARY
ZEND_MOD_REQUIRED("igbinary")
#endif
#ifdef HAVE_SPL
Expand Down Expand Up @@ -2837,7 +2849,7 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
/*
* Indicate whether igbinary serializer is available
*/
#ifdef HAVE_MEMCACHED_IGBINARY
#if HAVE_MEMCACHED_IGBINARY
REGISTER_MEMC_CLASS_CONST_LONG(HAVE_IGBINARY, 1);
#else
REGISTER_MEMC_CLASS_CONST_LONG(HAVE_IGBINARY, 0);
Expand All @@ -2846,7 +2858,7 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
/*
* Indicate whether json serializer is available
*/
#ifdef HAVE_JSON_API
#if HAVE_JSON_API
REGISTER_MEMC_CLASS_CONST_LONG(HAVE_JSON, 1);
#else
REGISTER_MEMC_CLASS_CONST_LONG(HAVE_JSON, 0);
Expand Down Expand Up @@ -2998,6 +3010,12 @@ PHP_MINFO_FUNCTION(memcached)
php_info_print_table_row(2, "igbinary support", "no");
#endif

#if HAVE_JSON_API
php_info_print_table_row(2, "json support", "yes");
#else
php_info_print_table_row(2, "json support", "no");
#endif

php_info_print_table_end();
}
/* }}} */
Expand Down
8 changes: 6 additions & 2 deletions php_memcached.h
Expand Up @@ -67,9 +67,13 @@ PS_FUNCS(memcached);
#endif

/* json serializer */
#if (PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 2) || (PHP_MAJOR_VERSION ==5 && PHP_MINOR_VERSION == 2 && PHP_RELEASE_VERSION > 9)
#define HAVE_JSON_API 1
#if (PHP_MAJOR_VERSION ==5 && PHP_MINOR_VERSION == 2 && PHP_RELEASE_VERSION > 9)
#define HAVE_JSON_API_5_2 1
#endif
#if (PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 2)
#define HAVE_JSON_API_5_3 1
#endif
#define HAVE_JSON_API (HAVE_JSON_API_5_2 || HAVE_JSON_API_5_3)

#endif /* PHP_MEMCACHED_H */

Expand Down

0 comments on commit 23dd98b

Please sign in to comment.