Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dcaa48

Browse files
authored
Merge pull request #1212 from phpredis/runtime-exception
runtime exteption
2 parents 1a7a259 + be59914 commit 8dcaa48

4 files changed

Lines changed: 24 additions & 54 deletions

File tree

library.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@
4949
extern zend_class_entry *redis_ce;
5050
extern zend_class_entry *redis_exception_ce;
5151

52+
static zend_class_entry *runtime_exception_ce = NULL;
53+
54+
PHP_REDIS_API zend_class_entry *
55+
redis_get_exception_base(TSRMLS_D)
56+
{
57+
if (runtime_exception_ce = NULL) {
58+
#if HAVE_SPL
59+
runtime_exception_ce = zend_hash_str_find_ptr(CG(class_table), "RuntimeException", sizeof("RuntimeException") - 1);
60+
#else
61+
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
62+
runtime_exception_ce = zend_exception_get_default();
63+
#else
64+
runtime_exception_ce = zend_exception_get_default(TSRMLS_C);
65+
#endif
66+
#endif
67+
}
68+
return runtime_exception_ce;
69+
}
70+
5271
/* Helper to reselect the proper DB number when we reconnect */
5372
static int reselect_db(RedisSock *redis_sock TSRMLS_DC) {
5473
char *cmd, *response;

library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ PHP_REDIS_API int redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
8888

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

91+
PHP_REDIS_API zend_class_entry *redis_get_exception_base(TSRMLS_D);
9192
#endif

redis.c

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ extern zend_class_entry *redis_cluster_ce;
4848
zend_class_entry *redis_ce;
4949
zend_class_entry *redis_exception_ce;
5050
extern zend_class_entry *redis_cluster_exception_ce;
51-
static zend_class_entry *spl_ce_RuntimeException = NULL;
5251

5352
extern zend_function_entry redis_array_functions[];
5453
extern zend_function_entry redis_cluster_functions[];
@@ -880,31 +879,6 @@ zend_module_entry redis_module_entry = {
880879
ZEND_GET_MODULE(redis)
881880
#endif
882881

883-
PHP_REDIS_API zend_class_entry *redis_get_exception_base(int root TSRMLS_DC)
884-
{
885-
#if HAVE_SPL
886-
if (!root) {
887-
if (!spl_ce_RuntimeException) {
888-
zend_class_entry *pce;
889-
890-
if ((pce = zend_hash_str_find_ptr(CG(class_table), "runtimeexception",
891-
sizeof("RuntimeException") - 1)))
892-
{
893-
spl_ce_RuntimeException = pce;
894-
return pce;
895-
}
896-
} else {
897-
return spl_ce_RuntimeException;
898-
}
899-
}
900-
#endif
901-
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
902-
return zend_exception_get_default();
903-
#else
904-
return zend_exception_get_default(TSRMLS_C);
905-
#endif
906-
}
907-
908882
/* Send a static DISCARD in case we're in MULTI mode. */
909883
static int
910884
redis_send_discard(RedisSock *redis_sock TSRMLS_DC)
@@ -1173,10 +1147,10 @@ PHP_MINIT_FUNCTION(redis)
11731147
redis_exception_ce = zend_register_internal_class_ex(
11741148
&redis_exception_class_entry,
11751149
#if (PHP_MAJOR_VERSION < 7)
1176-
redis_get_exception_base(0 TSRMLS_CC),
1150+
redis_get_exception_base(TSRMLS_C),
11771151
NULL TSRMLS_CC
11781152
#else
1179-
redis_get_exception_base(0)
1153+
redis_get_exception_base(TSRMLS_C)
11801154
#endif
11811155
);
11821156

@@ -1186,10 +1160,10 @@ PHP_MINIT_FUNCTION(redis)
11861160
redis_cluster_exception_ce = zend_register_internal_class_ex(
11871161
&redis_cluster_exception_class_entry,
11881162
#if (PHP_MAJOR_VERSION < 7)
1189-
rediscluster_get_exception_base(0 TSRMLS_CC),
1163+
redis_get_exception_base(TSRMLS_C),
11901164
NULL TSRMLS_CC
11911165
#else
1192-
rediscluster_get_exception_base(0)
1166+
redis_get_exception_base(TSRMLS_C)
11931167
#endif
11941168
);
11951169

redis_cluster.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ zend_class_entry *redis_cluster_ce;
3737
/* Exception handler */
3838
zend_class_entry *redis_cluster_exception_ce;
3939

40-
static zend_class_entry *spl_rte_ce = NULL;
4140
/* Handlers for RedisCluster */
4241
zend_object_handlers RedisCluster_handlers;
4342

@@ -253,29 +252,6 @@ static void ht_free_node(zval *data)
253252
cluster_free_node(node);
254253
}
255254

256-
/* Initialize/Register our RedisCluster exceptions */
257-
PHPAPI zend_class_entry *rediscluster_get_exception_base(int root TSRMLS_DC) {
258-
#if HAVE_SPL
259-
if(!root) {
260-
if(!spl_rte_ce) {
261-
zend_class_entry *pce;
262-
263-
if ((pce = zend_hash_str_find_ptr(CG(class_table), "runtimeexception", sizeof("runtimeexception") - 1))) {
264-
spl_rte_ce = pce;
265-
return pce;
266-
}
267-
} else {
268-
return spl_rte_ce;
269-
}
270-
}
271-
#endif
272-
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
273-
return zend_exception_get_default();
274-
#else
275-
return zend_exception_get_default(TSRMLS_C);
276-
#endif
277-
}
278-
279255
/* Create redisCluster context */
280256
#if (PHP_MAJOR_VERSION < 7)
281257
zend_object_value

0 commit comments

Comments
 (0)