Skip to content

Commit 6f6900f

Browse files
bjoriderickr
authored andcommitted
PHPC-405: zval drop a level; zval*->zval, zval**->zval*
1 parent 390b6fc commit 6f6900f

File tree

9 files changed

+166
-66
lines changed

9 files changed

+166
-66
lines changed

phongo_compat.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ void *x509_from_zval(zval *zval TSRMLS_DC) {
4040
void phongo_add_exception_prop(const char *prop, int prop_len, zval *value TSRMLS_DC)
4141
{
4242
if (EG(exception)) {
43-
zval *ex = NULL;
44-
EXCEPTION_P(EG(exception), ex);
4543
#if PHP_VERSION_ID >= 70000
46-
zend_update_property(Z_OBJCE_P(ex), ex, prop, prop_len, value);
44+
zval ex;
45+
EXCEPTION_P(EG(exception), ex);
46+
zend_update_property(Z_OBJCE(ex), &ex, prop, prop_len, value);
4747
#else
48+
zval *ex = NULL;
49+
EXCEPTION_P(EG(exception), ex);
4850
zend_update_property(Z_OBJCE_P(ex), ex, prop, prop_len, value TSRMLS_CC);
4951
#endif
5052

phongo_compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
# define PHONGO_TSRMLS_FETCH_FROM_CTX(user_data)
156156
# define SUPPRESS_UNUSED_WARNING(x)
157157
# define DECLARE_RETURN_VALUE_USED int return_value_used = 1;
158-
# define EXCEPTION_P(_ex, _zp) ZVAL_OBJ(_zp, _ex)
158+
# define EXCEPTION_P(_ex, _zp) ZVAL_OBJ(&_zp, _ex)
159159
# define PHONGO_STREAM_ID(stream) stream->res->handle
160160
# define ADD_ASSOC_STRING(_zv, _key, _value) add_assoc_string_ex(_zv, ZEND_STRL(_key), _value);
161161
# define ADD_ASSOC_STRINGL(_zv, _key, _value, _len) add_assoc_stringl_ex(_zv, ZEND_STRL(_key), _value, _len);

php_bson.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,28 @@ typedef struct {
6161
} php_phongo_bson_typemap;
6262

6363
typedef struct {
64+
#if PHP_VERSION_ID >= 70000
65+
zval zchild;
66+
#else
6467
zval *zchild;
68+
#endif
6569
php_phongo_bson_typemap map;
6670
zend_class_entry *odm;
6771
} php_phongo_bson_state;
6872

69-
#define PHONGO_BSON_STATE_INITIALIZER {NULL, { PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL}, NULL}
73+
#if PHP_VERSION_ID >= 70000
74+
#define PHONGO_BSON_STATE_INITIALIZER { {}, { PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL}, NULL}
75+
#else
76+
#define PHONGO_BSON_STATE_INITIALIZER { NULL, { PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL, PHONGO_TYPEMAP_NONE, NULL}, NULL}
77+
#endif
7078

7179
PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *bson, bson_t **bson_out TSRMLS_DC);
7280
PHONGO_API int bson_to_zval_ex(const unsigned char *data, int data_len, php_phongo_bson_state *state);
81+
#if PHP_VERSION_ID >= 70000
82+
PHONGO_API int bson_to_zval(const unsigned char *data, int data_len, zval *out);
83+
#else
7384
PHONGO_API int bson_to_zval(const unsigned char *data, int data_len, zval **out);
85+
#endif
7486
PHONGO_API void php_phongo_bson_typemap_to_state(zval *typemap, php_phongo_bson_typemap *map TSRMLS_DC);
7587

7688
PHP_FUNCTION(toPHP);

php_phongo.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ zend_bool phongo_writeconcernerror_init(zval *return_value, bson_t *bson TSRMLS_
415415
}
416416

417417
if (!bson_to_zval(data, len, &writeconcernerror->info)) {
418+
zval_ptr_dtor(&writeconcernerror->info);
418419
#if PHP_VERSION_ID >= 70000
419-
zval_ptr_dtor(writeconcernerror->info);
420+
ZVAL_UNDEF(&writeconcernerror->info);
420421
#else
421-
zval_ptr_dtor(&writeconcernerror->info);
422422
writeconcernerror->info = NULL;
423423
#endif
424424

@@ -449,12 +449,13 @@ zend_bool phongo_writeerror_init(zval *return_value, bson_t *bson TSRMLS_DC) /*
449449
bson_append_iter(&info, NULL, 0, &iter);
450450

451451
if (!bson_to_zval(bson_get_data(&info), info.len, &writeerror->info)) {
452+
zval_ptr_dtor(&writeerror->info);
452453
#if PHP_VERSION_ID >= 70000
453-
zval_ptr_dtor(writeerror->info);
454+
ZVAL_UNDEF(&writeerror->info);
454455
#else
455-
zval_ptr_dtor(&writeerror->info);
456456
writeerror->info = NULL;
457457
#endif
458+
458459
return false;
459460
}
460461
}
@@ -1996,13 +1997,13 @@ void php_phongo_new_regex_from_regex_and_options(zval *object, const char *patte
19961997

19971998
static void php_phongo_cursor_free_current(php_phongo_cursor_t *cursor) /* {{{ */
19981999
{
1999-
if (cursor->visitor_data.zchild) {
2000+
if (!Z_ISUNDEF(cursor->visitor_data.zchild)) {
2001+
zval_ptr_dtor(&cursor->visitor_data.zchild);
20002002
#if PHP_VERSION_ID >= 70000
2001-
zval_ptr_dtor(cursor->visitor_data.zchild);
2003+
ZVAL_UNDEF(&cursor->visitor_data.zchild);
20022004
#else
2003-
zval_ptr_dtor(&cursor->visitor_data.zchild);
2004-
#endif
20052005
cursor->visitor_data.zchild = NULL;
2006+
#endif
20062007
}
20072008
} /* }}} */
20082009

@@ -2037,7 +2038,7 @@ static int php_phongo_cursor_iterator_valid(zend_object_iterator *iter TSRMLS_DC
20372038
{
20382039
php_phongo_cursor_t *cursor = ((php_phongo_cursor_iterator *)iter)->cursor;
20392040

2040-
if (cursor->visitor_data.zchild) {
2041+
if (!Z_ISUNDEF(cursor->visitor_data.zchild)) {
20412042
return SUCCESS;
20422043
}
20432044

@@ -2069,7 +2070,7 @@ static zval* php_phongo_cursor_iterator_get_current_data(zend_object_iterator *i
20692070
{
20702071
php_phongo_cursor_t *cursor = ((php_phongo_cursor_iterator *)iter)->cursor;
20712072

2072-
return cursor->visitor_data.zchild;
2073+
return &cursor->visitor_data.zchild;
20732074
} /* }}} */
20742075
#endif
20752076

@@ -2144,10 +2145,10 @@ zend_object_iterator *php_phongo_cursor_get_iterator(zend_class_entry *ce, zval
21442145

21452146
cursor_it = ecalloc(1, sizeof(php_phongo_cursor_iterator));
21462147

2147-
Z_ADDREF_P(object);
21482148
#if PHP_VERSION_ID >= 70000
21492149
ZVAL_COPY(&cursor_it->intern.data, object);
21502150
#else
2151+
Z_ADDREF_P(object);
21512152
cursor_it->intern.data = (void*)object;
21522153
#endif
21532154
cursor_it->intern.funcs = &php_phongo_cursor_iterator_funcs;
@@ -2156,7 +2157,7 @@ zend_object_iterator *php_phongo_cursor_get_iterator(zend_class_entry *ce, zval
21562157

21572158
php_phongo_cursor_free_current(cursor_it->cursor);
21582159

2159-
return (zend_object_iterator*)cursor_it;
2160+
return &cursor_it->intern;
21602161
} /* }}} */
21612162
/* }}} */
21622163

php_phongo_structs-7.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ typedef struct {
9595
typedef struct {
9696
int code;
9797
char *message;
98-
zval *info;
98+
zval info;
9999
zend_object std;
100100
} php_phongo_writeconcernerror_t;
101101

102102
typedef struct {
103103
int code;
104104
char *message;
105-
zval *info;
105+
zval info;
106106
uint32_t index;
107107
zend_object std;
108108
} php_phongo_writeerror_t;

src/MongoDB/Server.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ PHP_METHOD(Server, getTags)
176176
state.map.document_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
177177

178178
bson_to_zval_ex(bson_get_data(&sd->tags), sd->tags.len, &state);
179+
#if PHP_VERSION_ID >= 70000
180+
RETURN_ZVAL(&state.zchild, 0, 1);
181+
#else
179182
RETURN_ZVAL(state.zchild, 0, 1);
183+
#endif
180184
}
181185

182186
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description: %s", error.message);
@@ -205,7 +209,12 @@ PHP_METHOD(Server, getInfo)
205209
state.map.document_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
206210

207211
bson_to_zval_ex(bson_get_data(&sd->last_is_master), sd->last_is_master.len, &state);
212+
213+
#if PHP_VERSION_ID >= 70000
214+
RETURN_ZVAL(&state.zchild, 0, 1);
215+
#else
208216
RETURN_ZVAL(state.zchild, 0, 1);
217+
#endif
209218
}
210219

211220
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to get server description: %s", error.message);

src/MongoDB/WriteConcernError.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ PHP_METHOD(WriteConcernError, getInfo)
7777
}
7878

7979

80-
if (intern->info) {
80+
if (!Z_ISUNDEF(intern->info)) {
81+
#if PHP_VERSION_ID >= 70000
82+
RETURN_ZVAL(&intern->info, 1, 0);
83+
#else
8184
RETURN_ZVAL(intern->info, 1, 0);
85+
#endif
8286
}
8387
}
8488
/* }}} */
@@ -137,12 +141,8 @@ static void php_phongo_writeconcernerror_free_object(phongo_free_object_arg *obj
137141
efree(intern->message);
138142
}
139143

140-
if (intern->info) {
141-
#if PHP_VERSION_ID >= 70000
142-
zval_ptr_dtor(intern->info);
143-
#else
144+
if (!Z_ISUNDEF(intern->info)) {
144145
zval_ptr_dtor(&intern->info);
145-
#endif
146146
}
147147

148148
#if PHP_VERSION_ID < 70000

src/MongoDB/WriteError.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ PHP_METHOD(WriteError, getInfo)
111111
}
112112

113113

114-
if (intern->info) {
114+
if (!Z_ISUNDEF(intern->info)) {
115+
#if PHP_VERSION_ID >= 70000
116+
RETURN_ZVAL(&intern->info, 1, 0);
117+
#else
115118
RETURN_ZVAL(intern->info, 1, 0);
119+
#endif
116120
}
117121
}
118122
/* }}} */
@@ -159,12 +163,8 @@ static void php_phongo_writeerror_free_object(phongo_free_object_arg *object TSR
159163
efree(intern->message);
160164
}
161165

162-
if (intern->info) {
163-
#if PHP_VERSION_ID >= 70000
164-
zval_ptr_dtor(intern->info);
165-
#else
166+
if (!Z_ISUNDEF(intern->info)) {
166167
zval_ptr_dtor(&intern->info);
167-
#endif
168168
}
169169

170170
#if PHP_VERSION_ID < 70000

0 commit comments

Comments
 (0)