Skip to content

Commit

Permalink
Merge pull request #1212 from phpredis/runtime-exception
Browse files Browse the repository at this point in the history
runtime exteption
  • Loading branch information
yatsukhnenko committed Jul 26, 2017
2 parents 1a7a259 + be59914 commit 8dcaa48
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 54 deletions.
19 changes: 19 additions & 0 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@
extern zend_class_entry *redis_ce;
extern zend_class_entry *redis_exception_ce;

static zend_class_entry *runtime_exception_ce = NULL;

PHP_REDIS_API zend_class_entry *
redis_get_exception_base(TSRMLS_D)
{
if (runtime_exception_ce = NULL) {
#if HAVE_SPL
runtime_exception_ce = zend_hash_str_find_ptr(CG(class_table), "RuntimeException", sizeof("RuntimeException") - 1);
#else
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
runtime_exception_ce = zend_exception_get_default();
#else
runtime_exception_ce = zend_exception_get_default(TSRMLS_C);
#endif
#endif
}
return runtime_exception_ce;
}

/* Helper to reselect the proper DB number when we reconnect */
static int reselect_db(RedisSock *redis_sock TSRMLS_DC) {
char *cmd, *response;
Expand Down
1 change: 1 addition & 0 deletions library.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ PHP_REDIS_API int redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo

PHP_REDIS_API void redis_client_list_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab);

PHP_REDIS_API zend_class_entry *redis_get_exception_base(TSRMLS_D);
#endif
34 changes: 4 additions & 30 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ extern zend_class_entry *redis_cluster_ce;
zend_class_entry *redis_ce;
zend_class_entry *redis_exception_ce;
extern zend_class_entry *redis_cluster_exception_ce;
static zend_class_entry *spl_ce_RuntimeException = NULL;

extern zend_function_entry redis_array_functions[];
extern zend_function_entry redis_cluster_functions[];
Expand Down Expand Up @@ -880,31 +879,6 @@ zend_module_entry redis_module_entry = {
ZEND_GET_MODULE(redis)
#endif

PHP_REDIS_API zend_class_entry *redis_get_exception_base(int root TSRMLS_DC)
{
#if HAVE_SPL
if (!root) {
if (!spl_ce_RuntimeException) {
zend_class_entry *pce;

if ((pce = zend_hash_str_find_ptr(CG(class_table), "runtimeexception",
sizeof("RuntimeException") - 1)))
{
spl_ce_RuntimeException = pce;
return pce;
}
} else {
return spl_ce_RuntimeException;
}
}
#endif
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
return zend_exception_get_default();
#else
return zend_exception_get_default(TSRMLS_C);
#endif
}

/* Send a static DISCARD in case we're in MULTI mode. */
static int
redis_send_discard(RedisSock *redis_sock TSRMLS_DC)
Expand Down Expand Up @@ -1173,10 +1147,10 @@ PHP_MINIT_FUNCTION(redis)
redis_exception_ce = zend_register_internal_class_ex(
&redis_exception_class_entry,
#if (PHP_MAJOR_VERSION < 7)
redis_get_exception_base(0 TSRMLS_CC),
redis_get_exception_base(TSRMLS_C),
NULL TSRMLS_CC
#else
redis_get_exception_base(0)
redis_get_exception_base(TSRMLS_C)
#endif
);

Expand All @@ -1186,10 +1160,10 @@ PHP_MINIT_FUNCTION(redis)
redis_cluster_exception_ce = zend_register_internal_class_ex(
&redis_cluster_exception_class_entry,
#if (PHP_MAJOR_VERSION < 7)
rediscluster_get_exception_base(0 TSRMLS_CC),
redis_get_exception_base(TSRMLS_C),
NULL TSRMLS_CC
#else
rediscluster_get_exception_base(0)
redis_get_exception_base(TSRMLS_C)
#endif
);

Expand Down
24 changes: 0 additions & 24 deletions redis_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ zend_class_entry *redis_cluster_ce;
/* Exception handler */
zend_class_entry *redis_cluster_exception_ce;

static zend_class_entry *spl_rte_ce = NULL;
/* Handlers for RedisCluster */
zend_object_handlers RedisCluster_handlers;

Expand Down Expand Up @@ -253,29 +252,6 @@ static void ht_free_node(zval *data)
cluster_free_node(node);
}

/* Initialize/Register our RedisCluster exceptions */
PHPAPI zend_class_entry *rediscluster_get_exception_base(int root TSRMLS_DC) {
#if HAVE_SPL
if(!root) {
if(!spl_rte_ce) {
zend_class_entry *pce;

if ((pce = zend_hash_str_find_ptr(CG(class_table), "runtimeexception", sizeof("runtimeexception") - 1))) {
spl_rte_ce = pce;
return pce;
}
} else {
return spl_rte_ce;
}
}
#endif
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
return zend_exception_get_default();
#else
return zend_exception_get_default(TSRMLS_C);
#endif
}

/* Create redisCluster context */
#if (PHP_MAJOR_VERSION < 7)
zend_object_value
Expand Down

0 comments on commit 8dcaa48

Please sign in to comment.