Skip to content

Commit a53062d

Browse files
committed
support php8+
1 parent 4728989 commit a53062d

File tree

2 files changed

+101
-22
lines changed

2 files changed

+101
-22
lines changed

SeasClick.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ ZEND_BEGIN_ARG_INFO_EX(SeasCilck_construct, 0, 0, 1)
6868
ZEND_ARG_INFO(0, connectParames)
6969
ZEND_END_ARG_INFO()
7070

71+
72+
ZEND_BEGIN_ARG_INFO_EX(SeasCilck_destruct, 0, 0, 1)
73+
ZEND_ARG_INFO(0, params)
74+
ZEND_END_ARG_INFO()
75+
7176
ZEND_BEGIN_ARG_INFO_EX(SeasCilck_select, 0, 0, 2)
7277
ZEND_ARG_INFO(0, sql)
7378
ZEND_ARG_INFO(0, params)
@@ -107,7 +112,7 @@ const zend_function_entry SeasClick_functions[] =
107112
const zend_function_entry SeasClick_methods[] =
108113
{
109114
PHP_ME(SEASCLICK_RES_NAME, __construct, SeasCilck_construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
110-
PHP_ME(SEASCLICK_RES_NAME, __destruct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
115+
PHP_ME(SEASCLICK_RES_NAME, __destruct, SeasCilck_destruct, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
111116
PHP_ME(SEASCLICK_RES_NAME, select, SeasCilck_select, ZEND_ACC_PUBLIC)
112117
PHP_ME(SEASCLICK_RES_NAME, insert, SeasCilck_insert, ZEND_ACC_PUBLIC)
113118
PHP_ME(SEASCLICK_RES_NAME, writeStart, SeasCilck_writeStart, ZEND_ACC_PUBLIC)
@@ -128,12 +133,24 @@ PHP_MINIT_FUNCTION(SeasClick)
128133
#else
129134
SeasClick_ce = zend_register_internal_class_ex(&SeasClick, NULL, NULL TSRMLS_CC);
130135
#endif
136+
137+
#if PHP_VERSION_ID <= 70000
131138
zend_declare_property_stringl(SeasClick_ce, "host", strlen("host"), "127.0.0.1", sizeof("127.0.0.1") - 1, ZEND_ACC_PROTECTED TSRMLS_CC);
132139
zend_declare_property_long(SeasClick_ce, "port", strlen("port"), 9000, ZEND_ACC_PROTECTED TSRMLS_CC);
133140
zend_declare_property_stringl(SeasClick_ce, "database", strlen("database"), "default", sizeof("default") - 1, ZEND_ACC_PROTECTED TSRMLS_CC);
134141
zend_declare_property_null(SeasClick_ce, "user", strlen("user"), ZEND_ACC_PROTECTED TSRMLS_CC);
135142
zend_declare_property_null(SeasClick_ce, "passwd", strlen("passwd"), ZEND_ACC_PROTECTED TSRMLS_CC);
136143
zend_declare_property_bool(SeasClick_ce, "compression", strlen("compression"), false, ZEND_ACC_PROTECTED TSRMLS_CC);
144+
#else
145+
zend_declare_property_stringl(SeasClick_ce, "host", strlen("host"), "127.0.0.1", sizeof("127.0.0.1") - 1, ZEND_ACC_PROTECTED );
146+
zend_declare_property_long(SeasClick_ce, "port", strlen("port"), 9000, ZEND_ACC_PROTECTED );
147+
zend_declare_property_stringl(SeasClick_ce, "database", strlen("database"), "default", sizeof("default") - 1, ZEND_ACC_PROTECTED );
148+
zend_declare_property_null(SeasClick_ce, "user", strlen("user"), ZEND_ACC_PROTECTED );
149+
zend_declare_property_null(SeasClick_ce, "passwd", strlen("passwd"), ZEND_ACC_PROTECTED );
150+
zend_declare_property_bool(SeasClick_ce, "compression", strlen("compression"), false, ZEND_ACC_PROTECTED );
151+
#endif
152+
153+
137154

138155
SeasClick_ce->ce_flags |= ZEND_ACC_FINAL;
139156
return SUCCESS;
@@ -224,19 +241,19 @@ PHP_METHOD(SEASCLICK_RES_NAME, __construct)
224241
if (php_array_get_value(_ht, "host", value))
225242
{
226243
convert_to_string(value);
227-
zend_update_property_string(SeasClick_ce, this_obj, "host", sizeof("host") - 1, Z_STRVAL_P(value) TSRMLS_CC);
244+
sc_zend_update_property_string(SeasClick_ce, this_obj, "host", sizeof("host") - 1, Z_STRVAL_P(value));
228245
}
229246

230247
if (php_array_get_value(_ht, "port", value))
231248
{
232249
convert_to_long(value);
233-
zend_update_property_long(SeasClick_ce, this_obj, "port", sizeof("port") - 1, Z_LVAL_P(value) TSRMLS_CC);
250+
sc_zend_update_property_long(SeasClick_ce, this_obj, "port", sizeof("port") - 1, Z_LVAL_P(value));
234251
}
235252

236253
if (php_array_get_value(_ht, "compression", value))
237254
{
238255
convert_to_boolean(value);
239-
zend_update_property_bool(SeasClick_ce, this_obj, "compression", sizeof("compression") - 1, Z_LVAL_P(value) TSRMLS_CC);
256+
sc_zend_update_property_long(SeasClick_ce, this_obj, "compression", sizeof("compression") - 1, Z_LVAL_P(value));
240257
}
241258

242259
zval *host = sc_zend_read_property(SeasClick_ce, this_obj, "host", sizeof("host") - 1, 0);
@@ -255,21 +272,21 @@ PHP_METHOD(SEASCLICK_RES_NAME, __construct)
255272
if (php_array_get_value(_ht, "database", value))
256273
{
257274
convert_to_string(value);
258-
zend_update_property_string(SeasClick_ce, this_obj, "database", sizeof("database") - 1, Z_STRVAL_P(value) TSRMLS_CC);
275+
sc_zend_update_property_string(SeasClick_ce, this_obj, "database", sizeof("database") - 1, Z_STRVAL_P(value));
259276
Options = Options.SetDefaultDatabase(Z_STRVAL_P(value));
260277
}
261278

262279
if (php_array_get_value(_ht, "user", value))
263280
{
264281
convert_to_string(value);
265-
zend_update_property_string(SeasClick_ce, this_obj, "user", sizeof("user") - 1, Z_STRVAL_P(value) TSRMLS_CC);
282+
sc_zend_update_property_string(SeasClick_ce, this_obj, "user", sizeof("user") - 1, Z_STRVAL_P(value));
266283
Options = Options.SetUser(Z_STRVAL_P(value));
267284
}
268285

269286
if (php_array_get_value(_ht, "passwd", value))
270287
{
271288
convert_to_string(value);
272-
zend_update_property_string(SeasClick_ce, this_obj, "passwd", sizeof("passwd") - 1, Z_STRVAL_P(value) TSRMLS_CC);
289+
sc_zend_update_property_string(SeasClick_ce, this_obj, "passwd", sizeof("passwd") - 1, Z_STRVAL_P(value));
273290
Options = Options.SetPassword(Z_STRVAL_P(value));
274291
}
275292

@@ -283,7 +300,7 @@ PHP_METHOD(SEASCLICK_RES_NAME, __construct)
283300
}
284301
catch (const std::exception& e)
285302
{
286-
sc_zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
303+
sc_zend_throw_exception_tsrmls_cc(NULL, e.what(), 0);
287304
}
288305

289306
RETURN_TRUE;
@@ -398,7 +415,7 @@ PHP_METHOD(SEASCLICK_RES_NAME, select)
398415
}
399416
catch (const std::exception& e)
400417
{
401-
sc_zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
418+
sc_zend_throw_exception_tsrmls_cc(NULL, e.what(), 0);
402419
}
403420
}
404421
/* }}} */
@@ -506,7 +523,7 @@ PHP_METHOD(SEASCLICK_RES_NAME, insert)
506523
}
507524
catch (const std::exception& e)
508525
{
509-
sc_zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
526+
sc_zend_throw_exception_tsrmls_cc(NULL, e.what(), 0);
510527
}
511528
RETURN_TRUE;
512529
}
@@ -561,7 +578,7 @@ PHP_METHOD(SEASCLICK_RES_NAME, writeStart)
561578
}
562579
catch (const std::exception& e)
563580
{
564-
sc_zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
581+
sc_zend_throw_exception_tsrmls_cc(NULL, e.what(), 0);
565582
}
566583
RETURN_TRUE;
567584
}
@@ -662,7 +679,7 @@ PHP_METHOD(SEASCLICK_RES_NAME, write)
662679
}
663680
catch (const std::exception& e)
664681
{
665-
sc_zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
682+
sc_zend_throw_exception_tsrmls_cc(NULL, e.what(), 0);
666683
}
667684
RETURN_TRUE;
668685
}
@@ -682,7 +699,7 @@ PHP_METHOD(SEASCLICK_RES_NAME, writeEnd)
682699
}
683700
catch (const std::exception& e)
684701
{
685-
sc_zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
702+
sc_zend_throw_exception_tsrmls_cc(NULL, e.what(), 0);
686703
}
687704
RETURN_TRUE;
688705
}
@@ -750,7 +767,7 @@ PHP_METHOD(SEASCLICK_RES_NAME, execute)
750767
}
751768
catch (const std::exception& e)
752769
{
753-
sc_zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
770+
sc_zend_throw_exception_tsrmls_cc(NULL, e.what(), 0);
754771
}
755772
RETURN_TRUE;
756773
}
@@ -771,7 +788,7 @@ PHP_METHOD(SEASCLICK_RES_NAME, __destruct)
771788
}
772789
catch (const std::exception& e)
773790
{
774-
sc_zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
791+
sc_zend_throw_exception_tsrmls_cc(NULL, e.what(), 0);
775792
}
776793
RETURN_TRUE;
777794
}

php7_wrapper.h

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,29 @@
1515
| Author: SeasX Group <ahhhh.wang@gmail.com> |
1616
+----------------------------------------------------------------------+
1717
*/
18-
// PHP7.4 +
18+
19+
20+
// PHP7.4 +
1921
#if !defined(ZEND_ACC_IMPLICIT_PUBLIC)
2022
# define ZEND_ACC_IMPLICIT_PUBLIC ZEND_ACC_PUBLIC
2123
#endif
2224

23-
// PHP7+
24-
#if PHP_MAJOR_VERSION < 7
25+
26+
// PHP8+
27+
#if !defined(ZEND_ACC_DTOR)
28+
#define ZEND_ACC_DTOR 0x4000
29+
#endif
30+
31+
// PHP5+
32+
#if PHP_MAJOR_VERSION <7
2533

2634
#if PHP_VERSION_ID < 50500
2735
#define sc_zend_throw_exception(a, b, c) zend_throw_exception(a, (char *)b, c)
2836
#else
2937
#define sc_zend_throw_exception zend_throw_exception
3038
#endif
3139

40+
#define sc_zend_throw_exception_tsrmls_cc sc_zend_throw_exception
3241
#define IS_TRUE 1
3342
#define SC_MAKE_STD_ZVAL(p) MAKE_STD_ZVAL(p)
3443
#define SC_RETURN_STRINGL(k, l) RETURN_STRINGL(k, l, 1)
@@ -85,7 +94,9 @@ static inline zval *sc_zend_hash_index_find(HashTable *ht, ulong h)
8594
}
8695
}
8796

88-
#define sc_zend_read_property(a, b, c, d, e) zend_read_property(a, b, c, d, e TSRMLS_CC)
97+
#define sc_zend_update_property_string zend_update_property_string
98+
99+
#define sc_zend_read_property(a, b, c, d, e) zend_read_property(a, b, c, d, e TSRMLS_CC)
89100

90101
#define SC_HASHTABLE_FOREACH_START2(ht, k, klen, ktype, entry)\
91102
zval **tmp = NULL; ulong_t idx;\
@@ -104,9 +115,8 @@ static inline zval *sc_zend_hash_index_find(HashTable *ht, ulong h)
104115
#define sc_add_next_index_stringl add_next_index_stringl
105116
#define sc_zend_hash_get_current_data zend_hash_get_current_data
106117
#else
107-
// PHP5
118+
// PHP7
108119
#define sc_zend_throw_exception zend_throw_exception
109-
110120
#define sc_zend_hash_find zend_hash_str_find
111121
#define sc_zend_hash_index_find zend_hash_index_find
112122
#define SC_MAKE_STD_ZVAL(p) zval _stack_zval_##p; p = &(_stack_zval_##p)
@@ -118,10 +128,62 @@ static inline zval *sc_zend_hash_index_find(HashTable *ht, ulong h)
118128
#define sc_add_assoc_zval_ex add_assoc_zval_ex
119129
#define sc_add_assoc_stringl_ex(a, b, c, d, e, f) add_assoc_stringl_ex(a, b, c, d, e)
120130
#define sc_add_assoc_null_ex(a, b, c) add_assoc_null_ex(a, b, c)
131+
132+
133+
134+
#if PHP_VERSION_ID < 80000
135+
#define sc_zend_throw_exception_tsrmls_cc(a, b, c) sc_zend_throw_exception(a, b, c TSRMLS_CC)
136+
#else
137+
#define sc_zend_throw_exception_tsrmls_cc(a, b, c) sc_zend_throw_exception(a, b, c)
138+
#endif
139+
140+
121141
static inline zval* sc_zend_read_property(zend_class_entry *class_ptr, zval *obj, const char *s, int len, int silent)
122142
{
123143
zval rv;
124-
return zend_read_property(class_ptr, obj, s, len, silent, &rv);
144+
#if PHP_VERSION_ID < 80000
145+
return zend_read_property(class_ptr, obj, s, len, silent, &rv);
146+
#else
147+
zend_object *zendObject;
148+
zendObject=Z_OBJ_P(obj);
149+
return zend_read_property(class_ptr, zendObject, s, len, silent, &rv);
150+
#endif
151+
152+
}
153+
154+
155+
static inline void sc_zend_update_property_string( zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value)
156+
{
157+
#if PHP_VERSION_ID < 80000
158+
return zend_update_property_string(scope, object, name, name_length, value TSRMLS_CC);
159+
#else
160+
zend_object *zendObject;
161+
zendObject=Z_OBJ_P(object);
162+
return zend_update_property_string(scope, zendObject, name, name_length, value);
163+
#endif
164+
}
165+
166+
167+
static inline void sc_zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value)
168+
{
169+
#if PHP_VERSION_ID < 80000
170+
return zend_update_property_long(scope, object, name, name_length, value TSRMLS_CC);
171+
#else
172+
zend_object *zendObject;
173+
zendObject=Z_OBJ_P(object);
174+
return zend_update_property_long(scope, zendObject, name, name_length, value);
175+
#endif
176+
}
177+
178+
static inline void sc_zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value) /* {{{ */
179+
{
180+
#if PHP_VERSION_ID < 80000
181+
return zend_update_property_bool(scope, object, name, name_length, value TSRMLS_CC);
182+
#else
183+
zend_object *zendObject;
184+
zendObject=Z_OBJ_P(object);
185+
return zend_update_property_bool(scope, zendObject, name, name_length, value);
186+
#endif
125187
}
126188

127189
#define SC_HASHTABLE_FOREACH_START2(ht, k, klen, ktype, _val) zend_string *_foreach_key;\

0 commit comments

Comments
 (0)