Skip to content

Commit efd9331

Browse files
committed
Merged pull request #175
2 parents d910576 + 9aad293 commit efd9331

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2912
-980
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: php
22
php:
3+
- 7.0
34
- 5.6
45
- 5.5
56
- 5.4

config.m4

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ AC_DEFUN([PHP_BSON_CLOCK],
7070

7171
MONGOC_SYMBOL_SUFFIX="priv"
7272

73+
AC_MSG_CHECKING(PHP version)
74+
PHP_FOUND_VERSION=`${PHP_CONFIG} --version`
75+
PHP_FOUND_VERNUM=`echo "${PHP_FOUND_VERSION}" | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 100 + [$]2) * 100 + [$]3;}'`
76+
AC_MSG_RESULT($PHP_FOUND_VERNUM)
77+
7378
if test "$MONGODB" != "no"; then
7479
PHP_ARG_ENABLE(developer-flags, whether to enable developer build flags,
7580
[ --enable-developer-flags Enable developer flags],, no)
@@ -110,10 +115,7 @@ if test "$MONGODB" != "no"; then
110115
PHP_CHECK_GCC_ARG(-Wparentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wparentheses")
111116
PHP_CHECK_GCC_ARG(-Wdeclaration-after-statement, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdeclaration-after-statement")
112117

113-
PHP_MONGODB_FOUND_VERSION=`${PHP_CONFIG} --version`
114-
PHP_MONGODB_FOUND_VERNUM=`echo "${PHP_MONGODB_FOUND_VERSION}" | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 100 + [$]2) * 100 + [$]3;}'`
115-
116-
if test "$PHP_MONGODB_FOUND_VERNUM" -ge "50400"; then
118+
if test "$PHP_FOUND_VERNUM" -ge "50400"; then
117119
PHP_CHECK_GCC_ARG(-Werror, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Werror")
118120
fi
119121

@@ -135,6 +137,7 @@ if test "$MONGODB" != "no"; then
135137
MONGODB_BSON="\
136138
src/bson.c \
137139
";
140+
138141
MONGODB_BSON_CLASSES="\
139142
src/BSON/Type.c \
140143
src/BSON/Unserializable.c \
@@ -151,6 +154,7 @@ if test "$MONGODB" != "no"; then
151154
";
152155
MONGODB_ROOT="\
153156
php_phongo.c \
157+
phongo_compat.c \
154158
";
155159
MONGODB_CONTRIB="\
156160
src/contrib/php-ssl.c \

config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if (PHP_MONGODB != "no") {
88

99
ADD_FLAG("CFLAGS_MONGODB", " /I" + configure_module_dirname + " /I" + configure_module_dirname + "/src/libmongoc/src/mongoc" + " /I" + configure_module_dirname + "/src/libbson/src/bson/ /I" + configure_module_dirname + "/src/libbson/src /I" + configure_module_dirname + "/src/contrib /D HAVE_MONGODB_SASL=1 /D BSON_COMPILATION=1 /D MONGOC_COMPILATION=1 /D MONGOC_TRACE=1 /D MONGOC_NO_AUTOMATIC_GLOBALS=1 /D BSON_EXTRA_ALIGN=0");
1010
EXTENSION("mongodb", "php_phongo.c");
11+
ADD_SOURCES(configure_module_dirname + "/", "phongo_compat.c", "mongodb");
1112
ADD_SOURCES(configure_module_dirname + "/src", "bson.c", "mongodb");
1213
ADD_SOURCES(configure_module_dirname + "/src/BSON", "Type.c Unserializable.c Serializable.c Persistable.c Binary.c Javascript.c MaxKey.c MinKey.c ObjectID.c Regex.c Timestamp.c UTCDateTime.c", "mongodb");
1314
ADD_SOURCES(configure_module_dirname + "/src/MongoDB", "Command.c Cursor.c CursorId.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c BulkWrite.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c", "mongodb");

phongo_compat.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
+---------------------------------------------------------------------------+
3+
| PHP Driver for MongoDB |
4+
+---------------------------------------------------------------------------+
5+
| Copyright 2013-2015 MongoDB, Inc. |
6+
| |
7+
| Licensed under the Apache License, Version 2.0 (the "License"); |
8+
| you may not use this file except in compliance with the License. |
9+
| You may obtain a copy of the License at |
10+
| |
11+
| http://www.apache.org/licenses/LICENSE-2.0 |
12+
| |
13+
| Unless required by applicable law or agreed to in writing, software |
14+
| distributed under the License is distributed on an "AS IS" BASIS, |
15+
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16+
| See the License for the specific language governing permissions and |
17+
| limitations under the License. |
18+
+---------------------------------------------------------------------------+
19+
| Copyright (c) 2015 MongoDB, Inc. |
20+
+---------------------------------------------------------------------------+
21+
*/
22+
23+
24+
/* Our Compatability header */
25+
#include "phongo_compat.h"
26+
27+
28+
void *x509_from_zval(zval *zval TSRMLS_DC) {
29+
#if PHP_VERSION_ID >= 70000
30+
return Z_RES_P(zval)->ptr;
31+
#else
32+
int resource_type;
33+
int type;
34+
35+
zend_list_find(Z_LVAL_P(zval), &resource_type);
36+
return zend_fetch_resource(&zval TSRMLS_CC, -1, "OpenSSL X.509", &type, 1, resource_type);
37+
#endif
38+
}
39+
40+
void phongo_add_exception_prop(const char *prop, int prop_len, zval *value TSRMLS_DC)
41+
{
42+
if (EG(exception)) {
43+
#if PHP_VERSION_ID >= 70000
44+
zval ex;
45+
EXCEPTION_P(EG(exception), ex);
46+
zend_update_property(Z_OBJCE(ex), &ex, prop, prop_len, value);
47+
#else
48+
zval *ex = NULL;
49+
EXCEPTION_P(EG(exception), ex);
50+
zend_update_property(Z_OBJCE_P(ex), ex, prop, prop_len, value TSRMLS_CC);
51+
#endif
52+
53+
}
54+
}
55+
56+
/*
57+
* Local variables:
58+
* tab-width: 4
59+
* c-basic-offset: 4
60+
* End:
61+
* vim600: noet sw=4 ts=4 fdm=marker
62+
* vim<600: noet sw=4 ts=4
63+
*/

phongo_compat.h

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
/*
2+
+---------------------------------------------------------------------------+
3+
| PHP Driver for MongoDB |
4+
+---------------------------------------------------------------------------+
5+
| Copyright 2013-2015 MongoDB, Inc. |
6+
| |
7+
| Licensed under the Apache License, Version 2.0 (the "License"); |
8+
| you may not use this file except in compliance with the License. |
9+
| You may obtain a copy of the License at |
10+
| |
11+
| http://www.apache.org/licenses/LICENSE-2.0 |
12+
| |
13+
| Unless required by applicable law or agreed to in writing, software |
14+
| distributed under the License is distributed on an "AS IS" BASIS, |
15+
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16+
| See the License for the specific language governing permissions and |
17+
| limitations under the License. |
18+
+---------------------------------------------------------------------------+
19+
| Copyright (c) 2015 MongoDB, Inc. |
20+
+---------------------------------------------------------------------------+
21+
*/
22+
23+
#ifndef PHONGO_COMPAT_H
24+
#define PHONGO_COMPAT_H
25+
26+
#include <php.h>
27+
#include <Zend/zend_string.h>
28+
#if PHP_VERSION_ID >= 70000
29+
#include <Zend/zend_portability.h>
30+
#endif
31+
132
#ifdef PHP_WIN32
233
# include "config.w32.h"
334
#else
@@ -17,7 +48,9 @@
1748
zend_hash_copy(*_std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
1849
#endif
1950

20-
#if PHP_VERSION_ID < 50400
51+
#if PHP_VERSION_ID >= 70000
52+
# define str_efree(s) efree((char*)s)
53+
#elif PHP_VERSION_ID < 50400
2154
# define str_efree(s) efree((char*)s)
2255
#else
2356
# include <Zend/zend_string.h>
@@ -112,3 +145,76 @@
112145
# endif
113146
#endif
114147

148+
#if PHP_VERSION_ID >= 70000
149+
# define phongo_char zend_string
150+
# define phongo_char_pdup(str) pestrdup(filename->val, 1)
151+
# define phongo_char_free(str) zend_string_release(str)
152+
# define phongo_str(str) str->val
153+
# define phongo_create_object_retval zend_object*
154+
# define PHONGO_ALLOC_OBJECT_T(_obj_t, _class_type) (_obj_t *)ecalloc(1, sizeof(_obj_t)+zend_object_properties_size(_class_type))
155+
# define PHONGO_TSRMLS_FETCH_FROM_CTX(user_data)
156+
# define SUPPRESS_UNUSED_WARNING(x)
157+
# define DECLARE_RETURN_VALUE_USED int return_value_used = 1;
158+
# define EXCEPTION_P(_ex, _zp) ZVAL_OBJ(&_zp, _ex)
159+
# define PHONGO_STREAM_ID(stream) stream->res ? stream->res->handle : -1
160+
# define ADD_ASSOC_STRING(_zv, _key, _value) add_assoc_string_ex(_zv, ZEND_STRL(_key), _value);
161+
# define ADD_ASSOC_STRINGL(_zv, _key, _value, _len) add_assoc_stringl_ex(_zv, ZEND_STRL(_key), _value, _len);
162+
# define ADD_ASSOC_LONG_EX(_zv, _key, _value) add_assoc_long_ex(_zv, ZEND_STRL(_key), _value);
163+
# define ADD_ASSOC_STRING_EX(_zv, _key, _key_len, _value, _value_len) add_assoc_stringl_ex(_zv, _key, _key_len, _value, _value_len);
164+
# define ADD_ASSOC_ZVAL_EX(_zv, _key, _value) add_assoc_zval_ex(_zv, ZEND_STRL(_key), _value);
165+
# define ADD_ASSOC_ZVAL(_zv, _key, _value) add_assoc_zval(_zv, _key, _value);
166+
# define ADD_ASSOC_NULL_EX(_zv, _key) add_assoc_null_ex(_zv, ZEND_STRL(_key));
167+
# define ADD_ASSOC_BOOL_EX(_zv, _key, _value) add_assoc_bool_ex(_zv, ZEND_STRL(_key), _value);
168+
# define phongo_free_object_arg zend_object
169+
# define phongo_zpp_char_len size_t
170+
# define ZEND_HASH_APPLY_COUNT(ht) (ht)->u.v.nApplyCount
171+
# define PHONGO_RETVAL_STRINGL(s, slen) RETVAL_STRINGL(s, slen)
172+
# define PHONGO_RETURN_STRINGL(s, slen) RETURN_STRINGL(s, slen)
173+
# define PHONGO_RETURN_STRING(s) RETURN_STRING(s)
174+
#else
175+
# define phongo_char char
176+
# define phongo_char_pdup(str) pestrdup(filename, 1)
177+
# define phongo_char_free(str) _efree(str ZEND_FILE_LINE_CC ZEND_FILE_LINE_CC)
178+
# define phongo_str(str) str
179+
# define phongo_create_object_retval zend_object_value
180+
# define PHONGO_ALLOC_OBJECT_T(_obj_t, _class_type) (_obj_t *)ecalloc(1, sizeof(_obj_t))
181+
# define PHONGO_TSRMLS_FETCH_FROM_CTX(user_data) TSRMLS_FETCH_FROM_CTX(user_data)
182+
# define SUPPRESS_UNUSED_WARNING(x) (void)x;
183+
# define DECLARE_RETURN_VALUE_USED
184+
# define EXCEPTION_P(_ex, _zp) _zp = _ex
185+
# define PHONGO_STREAM_ID(stream) stream->rsrc_id
186+
# define ADD_ASSOC_STRING(_zv, _key, _value) add_assoc_string_ex(_zv, ZEND_STRS(_key), _value, 1);
187+
# define ADD_ASSOC_STRINGL(_zv, _key, _value, _len) add_assoc_stringl_ex(_zv, ZEND_STRS(_key), _value, _len, 1);
188+
# define ADD_ASSOC_STRING_EX(_zv, _key, _key_len, _value, _value_len) add_assoc_stringl_ex(_zv, _key, _key_len+1, _value, _value_len, 1);
189+
# define ADD_ASSOC_LONG_EX(_zv, _key, _value) add_assoc_long_ex(_zv, ZEND_STRS(_key), _value);
190+
# define ADD_ASSOC_ZVAL_EX(_zv, _key, _value) add_assoc_zval_ex(_zv, ZEND_STRS(_key), _value);
191+
# define ADD_ASSOC_ZVAL(_zv, _key, _value) add_assoc_zval(_zv, _key, _value);
192+
# define ADD_ASSOC_NULL_EX(_zv, _key) add_assoc_null_ex(_zv, ZEND_STRS(_key));
193+
# define ADD_ASSOC_BOOL_EX(_zv, _key, _value) add_assoc_bool_ex(_zv, ZEND_STRS(_key), _value);
194+
# define Z_PHPDATE_P(object) zend_object_store_get_object(object TSRMLS_CC)
195+
# define Z_ISUNDEF(x) !x
196+
# define phongo_free_object_arg void
197+
# define phongo_zpp_char_len int
198+
# define ZEND_HASH_APPLY_COUNT(ht) (ht)->nApplyCount
199+
# define PHONGO_RETVAL_STRINGL(s, slen) RETVAL_STRINGL(s, slen, 1)
200+
# define PHONGO_RETURN_STRINGL(s, slen) RETURN_STRINGL(s, slen, 1)
201+
# define PHONGO_RETURN_STRING(s) RETURN_STRING(s, 1)
202+
# define PHP_STREAM_CONTEXT(stream) ((php_stream_context*) (stream)->context)
203+
#endif
204+
205+
206+
void *x509_from_zval(zval *zval TSRMLS_DC);
207+
void phongo_add_exception_prop(const char *prop, int prop_len, zval *value TSRMLS_DC);
208+
209+
210+
#endif /* PHONGO_COMPAT_H */
211+
212+
213+
/*
214+
* Local variables:
215+
* tab-width: 4
216+
* c-basic-offset: 4
217+
* End:
218+
* vim600: noet sw=4 ts=4 fdm=marker
219+
* vim<600: noet sw=4 ts=4
220+
*/

php_bson.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +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);
72-
PHONGO_API int bson_to_zval(const unsigned char *data, int data_len, php_phongo_bson_state *state);
80+
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
84+
PHONGO_API int bson_to_zval(const unsigned char *data, int data_len, zval **out);
85+
#endif
7386
PHONGO_API void php_phongo_bson_typemap_to_state(zval *typemap, php_phongo_bson_typemap *map TSRMLS_DC);
7487

7588
PHP_FUNCTION(toPHP);

0 commit comments

Comments
 (0)