Skip to content

Commit 5470e28

Browse files
committed
Macro-ify zval-changes between PHP 5 and PHP 7
1 parent bece8d7 commit 5470e28

28 files changed

+34
-140
lines changed

phongo_compat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
# define PHONGO_RETVAL_STRING(s) RETVAL_STRING(s)
100100
# define PHONGO_RETURN_STRING(s) RETURN_STRING(s)
101101
# define PHONGO_RETVAL_SMART_STR(val) PHONGO_RETVAL_STRINGL(ZSTR_VAL((val).s), ZSTR_LEN((val).s));
102+
# define ZVAL_RETVAL_TYPE zval
103+
# define ZVAL_STATIC_INIT { { 0 } }
102104
#else
103105
# define phongo_char char
104106
# define phongo_long long
@@ -135,6 +137,8 @@
135137
# define PHONGO_RETVAL_STRING(s) RETVAL_STRING(s, 1)
136138
# define PHONGO_RETURN_STRING(s) RETURN_STRING(s, 1)
137139
# define PHONGO_RETVAL_SMART_STR(val) PHONGO_RETVAL_STRINGL((val).c, (val).len);
140+
# define ZVAL_RETVAL_TYPE zval*
141+
# define ZVAL_STATIC_INIT zval_used_for_init
138142
#endif
139143

140144
#if SIZEOF_PHONGO_LONG == 8

php_bson.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ typedef struct {
5050
} php_phongo_bson_typemap;
5151

5252
typedef struct {
53-
#if PHP_VERSION_ID >= 70000
54-
zval zchild;
55-
#else
56-
zval *zchild;
57-
#endif
53+
ZVAL_RETVAL_TYPE zchild;
5854
php_phongo_bson_typemap map;
5955
zend_class_entry *odm;
6056
bool is_visiting_array;

src/BSON/Binary.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,7 @@ static PHP_METHOD(Binary, jsonSerialize)
211211
static PHP_METHOD(Binary, serialize)
212212
{
213213
php_phongo_binary_t *intern;
214-
#if PHP_VERSION_ID >= 70000
215-
zval retval;
216-
#else
217-
zval *retval;
218-
#endif
214+
ZVAL_RETVAL_TYPE retval;
219215
php_serialize_data_t var_hash;
220216
smart_str buf = { 0 };
221217

src/BSON/DBPointer.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,8 @@ static PHP_METHOD(DBPointer, __toString)
104104
static PHP_METHOD(DBPointer, jsonSerialize)
105105
{
106106
php_phongo_dbpointer_t *intern;
107-
#if PHP_VERSION_ID >= 70000
108-
zval zdb_pointer, zoid;
109-
#else
110-
zval *zdb_pointer, *zoid;
111-
#endif
107+
ZVAL_RETVAL_TYPE zdb_pointer;
108+
ZVAL_RETVAL_TYPE zoid;
112109

113110
if (zend_parse_parameters_none() == FAILURE) {
114111
return;
@@ -144,12 +141,7 @@ static PHP_METHOD(DBPointer, jsonSerialize)
144141
static PHP_METHOD(DBPointer, serialize)
145142
{
146143
php_phongo_dbpointer_t *intern;
147-
#if PHP_VERSION_ID >= 70000
148-
zval retval;
149-
#else
150-
zval *retval;
151-
#endif
152-
144+
ZVAL_RETVAL_TYPE retval;
153145
php_serialize_data_t var_hash;
154146
smart_str buf = { 0 };
155147

src/BSON/Decimal128.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ static PHP_METHOD(Decimal128, jsonSerialize)
151151
static PHP_METHOD(Decimal128, serialize)
152152
{
153153
php_phongo_decimal128_t *intern;
154-
#if PHP_VERSION_ID >= 70000
155-
zval retval;
156-
#else
157-
zval *retval;
158-
#endif
154+
ZVAL_RETVAL_TYPE retval;
159155
php_serialize_data_t var_hash;
160156
smart_str buf = { 0 };
161157
char outbuf[BSON_DECIMAL128_STRING];

src/BSON/Javascript.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,8 @@ static PHP_METHOD(Javascript, jsonSerialize)
228228
static PHP_METHOD(Javascript, serialize)
229229
{
230230
php_phongo_javascript_t *intern;
231-
#if PHP_VERSION_ID >= 70000
232-
zval retval;
233-
#else
234-
zval *retval;
235-
#endif
231+
ZVAL_RETVAL_TYPE retval;
236232
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
237-
238233
php_serialize_data_t var_hash;
239234
smart_str buf = { 0 };
240235

src/BSON/ObjectId.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ static PHP_METHOD(ObjectId, jsonSerialize)
190190
static PHP_METHOD(ObjectId, serialize)
191191
{
192192
php_phongo_objectid_t *intern;
193-
#if PHP_VERSION_ID >= 70000
194-
zval retval;
195-
#else
196-
zval *retval;
197-
#endif
193+
ZVAL_RETVAL_TYPE retval;
198194
php_serialize_data_t var_hash;
199195
smart_str buf = { 0 };
200196

src/BSON/Regex.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,7 @@ static PHP_METHOD(Regex, jsonSerialize)
215215
static PHP_METHOD(Regex, serialize)
216216
{
217217
php_phongo_regex_t *intern;
218-
#if PHP_VERSION_ID >= 70000
219-
zval retval;
220-
#else
221-
zval *retval;
222-
#endif
218+
ZVAL_RETVAL_TYPE retval;
223219
php_serialize_data_t var_hash;
224220
smart_str buf = { 0 };
225221

src/BSON/Symbol.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,7 @@ static PHP_METHOD(Symbol, jsonSerialize)
106106
static PHP_METHOD(Symbol, serialize)
107107
{
108108
php_phongo_symbol_t *intern;
109-
#if PHP_VERSION_ID >= 70000
110-
zval retval;
111-
#else
112-
zval *retval;
113-
#endif
114-
109+
ZVAL_RETVAL_TYPE retval;
115110
php_serialize_data_t var_hash;
116111
smart_str buf = { 0 };
117112

src/BSON/Timestamp.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,7 @@ static PHP_METHOD(Timestamp, jsonSerialize)
274274
static PHP_METHOD(Timestamp, serialize)
275275
{
276276
php_phongo_timestamp_t *intern;
277-
#if PHP_VERSION_ID >= 70000
278-
zval retval;
279-
#else
280-
zval *retval;
281-
#endif
277+
ZVAL_RETVAL_TYPE retval;
282278
php_serialize_data_t var_hash;
283279
smart_str buf = { 0 };
284280
char s_increment[12];

src/BSON/UTCDateTime.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,7 @@ static PHP_METHOD(UTCDateTime, jsonSerialize)
311311
static PHP_METHOD(UTCDateTime, serialize)
312312
{
313313
php_phongo_utcdatetime_t *intern;
314-
#if PHP_VERSION_ID >= 70000
315-
zval retval;
316-
#else
317-
zval *retval;
318-
#endif
314+
ZVAL_RETVAL_TYPE retval;
319315
php_serialize_data_t var_hash;
320316
smart_str buf = { 0 };
321317
char s_milliseconds[24];

src/MongoDB/BulkWrite.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,7 @@ static phongo_create_object_retval php_phongo_bulkwrite_create_object(zend_class
461461

462462
static HashTable *php_phongo_bulkwrite_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
463463
{
464-
#if PHP_VERSION_ID >= 70000
465-
zval retval;
466-
#else
467-
zval retval = zval_used_for_init;
468-
#endif
464+
zval retval = ZVAL_STATIC_INIT;
469465
php_phongo_bulkwrite_t *intern = NULL;
470466

471467

src/MongoDB/Command.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ static phongo_create_object_retval php_phongo_command_create_object(zend_class_e
174174
static HashTable *php_phongo_command_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
175175
{
176176
php_phongo_command_t *intern;
177-
#if PHP_VERSION_ID >= 70000
178-
zval retval;
179-
#else
180-
zval retval = zval_used_for_init;
181-
#endif
177+
zval retval = ZVAL_STATIC_INIT;
182178

183179

184180
*is_temp = 1;

src/MongoDB/Cursor.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,7 @@ static phongo_create_object_retval php_phongo_cursor_create_object(zend_class_en
426426
static HashTable *php_phongo_cursor_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
427427
{
428428
php_phongo_cursor_t *intern;
429-
#if PHP_VERSION_ID >= 70000
430-
zval retval;
431-
#else
432-
zval retval = zval_used_for_init;
433-
#endif
429+
zval retval = ZVAL_STATIC_INIT;
434430

435431

436432
*is_temp = 1;

src/MongoDB/CursorId.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ static phongo_create_object_retval php_phongo_cursorid_create_object(zend_class_
9999
static HashTable *php_phongo_cursorid_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
100100
{
101101
php_phongo_cursorid_t *intern;
102-
#if PHP_VERSION_ID >= 70000
103-
zval retval;
104-
#else
105-
zval retval = zval_used_for_init;
106-
#endif
102+
zval retval = ZVAL_STATIC_INIT;
107103

108104

109105
*is_temp = 1;

src/MongoDB/Manager.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,10 @@ static HashTable *php_phongo_manager_get_debug_info(zval *object, int *is_temp T
786786
php_phongo_manager_t *intern;
787787
mongoc_server_description_t **sds;
788788
size_t i, n = 0;
789+
zval retval = ZVAL_STATIC_INIT;
789790
#if PHP_VERSION_ID >= 70000
790-
zval retval, cluster;
791+
zval cluster;
791792
#else
792-
zval retval = zval_used_for_init;
793793
zval *cluster = NULL;
794794
#endif
795795

src/MongoDB/Monitoring/CommandFailedEvent.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,7 @@ static phongo_create_object_retval php_phongo_commandfailedevent_create_object(z
202202
static HashTable *php_phongo_commandfailedevent_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
203203
{
204204
php_phongo_commandfailedevent_t *intern;
205-
#if PHP_VERSION_ID >= 70000
206-
zval retval;
207-
#else
208-
zval retval = zval_used_for_init;
209-
#endif
205+
zval retval = ZVAL_STATIC_INIT;
210206
char operation_id[20], request_id[20];
211207

212208
intern = Z_COMMANDFAILEDEVENT_OBJ_P(object);

src/MongoDB/Monitoring/CommandStartedEvent.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,7 @@ static phongo_create_object_retval php_phongo_commandstartedevent_create_object(
206206
static HashTable *php_phongo_commandstartedevent_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
207207
{
208208
php_phongo_commandstartedevent_t *intern;
209-
#if PHP_VERSION_ID >= 70000
210-
zval retval;
211-
#else
212-
zval retval = zval_used_for_init;
213-
#endif
209+
zval retval = ZVAL_STATIC_INIT;
214210
char operation_id[20], request_id[20];
215211
php_phongo_bson_state command_state = PHONGO_BSON_STATE_INITIALIZER;
216212

src/MongoDB/Monitoring/CommandSucceededEvent.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,7 @@ static phongo_create_object_retval php_phongo_commandsucceededevent_create_objec
203203
static HashTable *php_phongo_commandsucceededevent_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
204204
{
205205
php_phongo_commandsucceededevent_t *intern;
206-
#if PHP_VERSION_ID >= 70000
207-
zval retval;
208-
#else
209-
zval retval = zval_used_for_init;
210-
#endif
206+
zval retval = ZVAL_STATIC_INIT;
211207
char operation_id[20], request_id[20];
212208
php_phongo_bson_state reply_state = PHONGO_BSON_STATE_INITIALIZER;
213209

src/MongoDB/Query.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,7 @@ static phongo_create_object_retval php_phongo_query_create_object(zend_class_ent
418418
static HashTable *php_phongo_query_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
419419
{
420420
php_phongo_query_t *intern;
421-
#if PHP_VERSION_ID >= 70000
422-
zval retval;
423-
#else
424-
zval retval = zval_used_for_init;
425-
#endif
421+
zval retval = ZVAL_STATIC_INIT;
426422

427423

428424
*is_temp = 1;

src/MongoDB/ReadConcern.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ static phongo_create_object_retval php_phongo_readconcern_create_object(zend_cla
171171

172172
static HashTable *php_phongo_readconcern_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
173173
{
174-
#if PHP_VERSION_ID >= 70000
175-
zval retval;
176-
#else
177-
zval retval = zval_used_for_init;
178-
#endif
174+
zval retval = ZVAL_STATIC_INIT;
179175
const mongoc_read_concern_t *read_concern = phongo_read_concern_from_zval(object TSRMLS_CC);
180176

181177

src/MongoDB/ReadPreference.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,7 @@ static phongo_create_object_retval php_phongo_readpreference_create_object(zend_
276276

277277
static HashTable *php_phongo_readpreference_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
278278
{
279-
#if PHP_VERSION_ID >= 70000
280-
zval retval;
281-
#else
282-
zval retval = zval_used_for_init;
283-
#endif
279+
zval retval = ZVAL_STATIC_INIT;
284280
const mongoc_read_prefs_t *read_prefs = phongo_read_preference_from_zval(object TSRMLS_CC);
285281

286282

src/MongoDB/Server.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,7 @@ static phongo_create_object_retval php_phongo_server_create_object(zend_class_en
621621
static HashTable *php_phongo_server_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
622622
{
623623
php_phongo_server_t *intern = NULL;
624-
#if PHP_VERSION_ID >= 70000
625-
zval retval;
626-
#else
627-
zval retval = zval_used_for_init;
628-
#endif
624+
zval retval = ZVAL_STATIC_INIT;
629625
mongoc_server_description_t *sd;
630626

631627
*is_temp = 1;

src/MongoDB/Session.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,7 @@ static HashTable *php_phongo_session_get_debug_info(zval *object, int *is_temp T
299299
{
300300
php_phongo_session_t *intern = NULL;
301301
const mongoc_session_opt_t *cs_opts;
302-
#if PHP_VERSION_ID >= 70000
303-
zval retval;
304-
#else
305-
zval retval = zval_used_for_init;
306-
#endif
302+
zval retval = ZVAL_STATIC_INIT;
307303

308304
*is_temp = 1;
309305
intern = Z_SESSION_OBJ_P(object);

src/MongoDB/WriteConcern.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,7 @@ static phongo_create_object_retval php_phongo_writeconcern_create_object(zend_cl
254254

255255
static HashTable *php_phongo_writeconcern_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
256256
{
257-
#if PHP_VERSION_ID >= 70000
258-
zval retval;
259-
#else
260-
zval retval = zval_used_for_init;
261-
#endif
257+
zval retval = ZVAL_STATIC_INIT;
262258
const mongoc_write_concern_t *write_concern = phongo_write_concern_from_zval(object TSRMLS_CC);
263259

264260

src/MongoDB/WriteConcernError.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ static phongo_create_object_retval php_phongo_writeconcernerror_create_object(ze
145145
static HashTable *php_phongo_writeconcernerror_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
146146
{
147147
php_phongo_writeconcernerror_t *intern;
148-
#if PHP_VERSION_ID >= 70000
149-
zval retval;
150-
#else
151-
zval retval = zval_used_for_init;
152-
#endif
148+
zval retval = ZVAL_STATIC_INIT;
153149

154150

155151
*is_temp = 1;

src/MongoDB/WriteError.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,7 @@ static phongo_create_object_retval php_phongo_writeerror_create_object(zend_clas
165165
static HashTable *php_phongo_writeerror_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
166166
{
167167
php_phongo_writeerror_t *intern;
168-
#if PHP_VERSION_ID >= 70000
169-
zval retval;
170-
#else
171-
zval retval = zval_used_for_init;
172-
#endif
168+
zval retval = ZVAL_STATIC_INIT;
173169

174170

175171
*is_temp = 1;

src/MongoDB/WriteResult.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,7 @@ static phongo_create_object_retval php_phongo_writeresult_create_object(zend_cla
416416
static HashTable *php_phongo_writeresult_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
417417
{
418418
php_phongo_writeresult_t *intern;
419-
#if PHP_VERSION_ID >= 70000
420-
zval retval;
421-
#else
422-
zval retval = zval_used_for_init;
423-
#endif
419+
zval retval = ZVAL_STATIC_INIT;
424420
bson_iter_t iter;
425421

426422
intern = Z_WRITERESULT_OBJ_P(object);

0 commit comments

Comments
 (0)