Skip to content

Commit 5c65399

Browse files
committed
Define ZSTR_VAL() for PHP 5 and remove phongo_str() macro
1 parent c7a418f commit 5c65399

File tree

5 files changed

+17
-33
lines changed

5 files changed

+17
-33
lines changed

phongo_compat.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
# error Unsupported architecture (integers are neither 32-bit nor 64-bit)
117117
#endif
118118
# define SIZEOF_PHONGO_LONG SIZEOF_ZEND_LONG
119-
# define phongo_str(str) (str)->val
120119
# define phongo_create_object_retval zend_object*
121120
# define PHONGO_ALLOC_OBJECT_T(_obj_t, _class_type) (_obj_t *)ecalloc(1, sizeof(_obj_t)+zend_object_properties_size(_class_type))
122121
# define PHONGO_TSRMLS_FETCH_FROM_CTX(user_data)
@@ -147,7 +146,7 @@
147146
# define phongo_long long
148147
# define PHONGO_LONG_FORMAT "ld"
149148
# define SIZEOF_PHONGO_LONG SIZEOF_LONG
150-
# define phongo_str(str) str
149+
# define ZSTR_VAL(str) str
151150
# define phongo_create_object_retval zend_object_value
152151
# define PHONGO_ALLOC_OBJECT_T(_obj_t, _class_type) (_obj_t *)ecalloc(1, sizeof(_obj_t))
153152
# define PHONGO_TSRMLS_FETCH_FROM_CTX(user_data) TSRMLS_FETCH_FROM_CTX(user_data)

php_phongo.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain,
224224
time(&t);
225225
dt = php_format_date((char *)"Y-m-d\\TH:i:sP", strlen("Y-m-d\\TH:i:sP"), t, 0 TSRMLS_CC);
226226

227-
fprintf(MONGODB_G(debug_fd), "[%s] %10s: %-8s> %s\n", phongo_str(dt), log_domain, mongoc_log_level_str(log_level), message);
227+
fprintf(MONGODB_G(debug_fd), "[%s] %10s: %-8s> %s\n", ZSTR_VAL(dt), log_domain, mongoc_log_level_str(log_level), message);
228228
fflush(MONGODB_G(debug_fd));
229229
efree(dt);
230230
} break;
@@ -1236,7 +1236,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
12361236
zend_restore_error_handling(&error_handling TSRMLS_CC);
12371237

12381238
if (!stream) {
1239-
bson_set_error (error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Failed connecting to '%s:%d': %s", host->host, host->port, phongo_str(errmsg));
1239+
bson_set_error (error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Failed connecting to '%s:%d': %s", host->host, host->port, ZSTR_VAL(errmsg));
12401240
efree(dsn);
12411241
efree(uniqid);
12421242
if (errmsg) {
@@ -2342,11 +2342,11 @@ ZEND_INI_MH(OnUpdateDebug)
23422342
MONGODB_G(debug_fd) = NULL;
23432343
}
23442344

2345-
if (!new_value || (new_value && !phongo_str(new_value)[0])
2346-
|| strcasecmp("0", phongo_str(new_value)) == 0
2347-
|| strcasecmp("off", phongo_str(new_value)) == 0
2348-
|| strcasecmp("no", phongo_str(new_value)) == 0
2349-
|| strcasecmp("false", phongo_str(new_value)) == 0
2345+
if (!new_value || (new_value && !ZSTR_VAL(new_value)[0])
2346+
|| strcasecmp("0", ZSTR_VAL(new_value)) == 0
2347+
|| strcasecmp("off", ZSTR_VAL(new_value)) == 0
2348+
|| strcasecmp("no", ZSTR_VAL(new_value)) == 0
2349+
|| strcasecmp("false", ZSTR_VAL(new_value)) == 0
23502350
) {
23512351
mongoc_log_trace_disable();
23522352
mongoc_log_set_handler(NULL, NULL);
@@ -2359,19 +2359,19 @@ ZEND_INI_MH(OnUpdateDebug)
23592359
}
23602360

23612361

2362-
if (strcasecmp(phongo_str(new_value), "stderr") == 0) {
2362+
if (strcasecmp(ZSTR_VAL(new_value), "stderr") == 0) {
23632363
MONGODB_G(debug_fd) = stderr;
2364-
} else if (strcasecmp(phongo_str(new_value), "stdout") == 0) {
2364+
} else if (strcasecmp(ZSTR_VAL(new_value), "stdout") == 0) {
23652365
MONGODB_G(debug_fd) = stdout;
23662366
} else if (
2367-
strcasecmp("1", phongo_str(new_value)) == 0
2368-
|| strcasecmp("on", phongo_str(new_value)) == 0
2369-
|| strcasecmp("yes", phongo_str(new_value)) == 0
2370-
|| strcasecmp("true", phongo_str(new_value)) == 0
2367+
strcasecmp("1", ZSTR_VAL(new_value)) == 0
2368+
|| strcasecmp("on", ZSTR_VAL(new_value)) == 0
2369+
|| strcasecmp("yes", ZSTR_VAL(new_value)) == 0
2370+
|| strcasecmp("true", ZSTR_VAL(new_value)) == 0
23712371
) {
23722372
tmp_dir = NULL;
23732373
} else {
2374-
tmp_dir = phongo_str(new_value);
2374+
tmp_dir = ZSTR_VAL(new_value);
23752375
}
23762376

23772377
if (!MONGODB_G(debug_fd)) {
@@ -2386,7 +2386,7 @@ ZEND_INI_MH(OnUpdateDebug)
23862386

23872387
fd = php_open_temporary_fd(tmp_dir, prefix, &filename TSRMLS_CC);
23882388
if (fd != -1) {
2389-
const char *path = phongo_str(filename);
2389+
const char *path = ZSTR_VAL(filename);
23902390
MONGODB_G(debug_fd) = VCWD_FOPEN(path, "a");
23912391
}
23922392
efree(filename);

src/BSON/UTCDateTime.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ PHP_METHOD(UTCDateTime, __construct)
140140
php_phongo_utcdatetime_init_from_date(intern, Z_PHPDATE_P(datetime));
141141
#endif
142142
} else {
143-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC,
144-
"Expected instance of DateTimeInterface, %s given",
145-
phongo_str(Z_OBJCE_P(datetime)->name)
146-
);
143+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected instance of DateTimeInterface, %s given", ZSTR_VAL(Z_OBJCE_P(datetime)->name));
147144
}
148145

149146
zend_restore_error_handling(&error_handling TSRMLS_CC);

src/MongoDB/Query.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ PHP_METHOD(Query, __construct)
8383
zval *zread_concern = php_array_fetchc(zoptions, "readConcern");
8484

8585
if (Z_TYPE_P(zread_concern) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(zread_concern), php_phongo_readconcern_ce TSRMLS_CC)) {
86-
#if PHP_VERSION_ID >= 70000
8786
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"readConcern\" option to be %s, %s given", ZSTR_VAL(php_phongo_readconcern_ce->name), zend_get_type_by_const(Z_TYPE_P(zread_concern)));
88-
#else
89-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"readConcern\" option to be %s, %s given", php_phongo_readconcern_ce->name, zend_get_type_by_const(Z_TYPE_P(zread_concern)));
90-
#endif
9187
bson_clear(&intern->query);
9288
return;
9389
}

src/bson.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,7 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
10121012
return;
10131013
}
10141014

1015-
#if PHP_VERSION_ID >= 70000
10161015
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Unexpected %s instance: %s", ZSTR_VAL(php_phongo_type_ce->name), ZSTR_VAL(Z_OBJCE_P(object)->name));
1017-
#else
1018-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Unexpected %s instance: %s", php_phongo_type_ce->name, Z_OBJCE_P(object)->name);
1019-
#endif
10201016
return;
10211017
}
10221018

@@ -1218,11 +1214,7 @@ PHONGO_API void phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, b
12181214
}
12191215

12201216
if (instanceof_function(Z_OBJCE_P(data), php_phongo_type_ce TSRMLS_CC)) {
1221-
#if PHP_VERSION_ID >= 70000
12221217
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s instance %s cannot be serialized as a root element", ZSTR_VAL(php_phongo_type_ce->name), ZSTR_VAL(Z_OBJCE_P(data)->name));
1223-
#else
1224-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "%s instance %s cannot be serialized as a root element", php_phongo_type_ce->name, Z_OBJCE_P(data)->name);
1225-
#endif
12261218

12271219
break;
12281220
}

0 commit comments

Comments
 (0)