Skip to content

Commit ebfb7b2

Browse files
authored
PHPC-2028: Replace PHONGO_ALLOC_OBJECT_T with zend_object_alloc (#1296)
zend_object_alloc was introduced in php/php-src@b72b1a4 for PHP 7.3+. For PHP 7.2, we define a macro providing the original behavior of PHONGO_ALLOC_OBJECT_T (slower dynamic memset).
1 parent 4e69ea4 commit ebfb7b2

Some content is hidden

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

44 files changed

+48
-124
lines changed

phongo_compat.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@
8080
#else
8181
#error Unsupported architecture (integers are neither 32-bit nor 64-bit)
8282
#endif
83-
#define PHONGO_ALLOC_OBJECT_T(_obj_t, _class_type) (_obj_t*) ecalloc(1, sizeof(_obj_t) + zend_object_properties_size(_class_type))
83+
84+
#if PHP_VERSION_ID < 70300
85+
#define zend_object_alloc(obj_size, ce) ecalloc(1, obj_size + zend_object_properties_size(ce))
86+
#endif
87+
8488
#define ADD_ASSOC_STRING(_zv, _key, _value) add_assoc_string_ex(_zv, ZEND_STRL(_key), (char*) (_value));
8589
#define ADD_ASSOC_STRINGL(_zv, _key, _value, _len) add_assoc_stringl_ex(_zv, ZEND_STRL(_key), (char*) (_value), _len);
8690
#define ADD_ASSOC_STRING_EX(_zv, _key, _key_len, _value, _value_len) add_assoc_stringl_ex(_zv, _key, _key_len, (char*) (_value), _value_len);

src/BSON/Binary.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,7 @@ static void php_phongo_binary_free_object(zend_object* object) /* {{{ */
383383

384384
static zend_object* php_phongo_binary_create_object(zend_class_entry* class_type) /* {{{ */
385385
{
386-
php_phongo_binary_t* intern = NULL;
387-
388-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_binary_t, class_type);
386+
php_phongo_binary_t* intern = zend_object_alloc(sizeof(php_phongo_binary_t), class_type);
389387

390388
zend_object_std_init(&intern->std, class_type);
391389
object_properties_init(&intern->std, class_type);

src/BSON/DBPointer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,8 @@ static void php_phongo_dbpointer_free_object(zend_object* object) /* {{{ */
288288

289289
zend_object* php_phongo_dbpointer_create_object(zend_class_entry* class_type) /* {{{ */
290290
{
291-
php_phongo_dbpointer_t* intern = NULL;
291+
php_phongo_dbpointer_t* intern = zend_object_alloc(sizeof(php_phongo_dbpointer_t), class_type);
292292

293-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_dbpointer_t, class_type);
294293
zend_object_std_init(&intern->std, class_type);
295294
object_properties_init(&intern->std, class_type);
296295

src/BSON/Decimal128.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ static void php_phongo_decimal128_free_object(zend_object* object) /* {{{ */
320320

321321
static zend_object* php_phongo_decimal128_create_object(zend_class_entry* class_type) /* {{{ */
322322
{
323-
php_phongo_decimal128_t* intern = NULL;
324-
325-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_decimal128_t, class_type);
323+
php_phongo_decimal128_t* intern = zend_object_alloc(sizeof(php_phongo_decimal128_t), class_type);
326324

327325
zend_object_std_init(&intern->std, class_type);
328326
object_properties_init(&intern->std, class_type);

src/BSON/Int64.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ static void php_phongo_int64_free_object(zend_object* object) /* {{{ */
268268

269269
zend_object* php_phongo_int64_create_object(zend_class_entry* class_type) /* {{{ */
270270
{
271-
php_phongo_int64_t* intern = NULL;
271+
php_phongo_int64_t* intern = zend_object_alloc(sizeof(php_phongo_int64_t), class_type);
272272

273-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_int64_t, class_type);
274273
zend_object_std_init(&intern->std, class_type);
275274
object_properties_init(&intern->std, class_type);
276275

src/BSON/Javascript.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,8 @@ static void php_phongo_javascript_free_object(zend_object* object) /* {{{ */
441441

442442
zend_object* php_phongo_javascript_create_object(zend_class_entry* class_type) /* {{{ */
443443
{
444-
php_phongo_javascript_t* intern = NULL;
444+
php_phongo_javascript_t* intern = zend_object_alloc(sizeof(php_phongo_javascript_t), class_type);
445445

446-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_javascript_t, class_type);
447446
zend_object_std_init(&intern->std, class_type);
448447
object_properties_init(&intern->std, class_type);
449448

src/BSON/MaxKey.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ static void php_phongo_maxkey_free_object(zend_object* object) /* {{{ */
158158

159159
static zend_object* php_phongo_maxkey_create_object(zend_class_entry* class_type) /* {{{ */
160160
{
161-
php_phongo_maxkey_t* intern = NULL;
161+
php_phongo_maxkey_t* intern = zend_object_alloc(sizeof(php_phongo_maxkey_t), class_type);
162162

163-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_maxkey_t, class_type);
164163
zend_object_std_init(&intern->std, class_type);
165164
object_properties_init(&intern->std, class_type);
166165

src/BSON/MinKey.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ static void php_phongo_minkey_free_object(zend_object* object) /* {{{ */
158158

159159
static zend_object* php_phongo_minkey_create_object(zend_class_entry* class_type) /* {{{ */
160160
{
161-
php_phongo_minkey_t* intern = NULL;
162-
163-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_minkey_t, class_type);
161+
php_phongo_minkey_t* intern = zend_object_alloc(sizeof(php_phongo_minkey_t), class_type);
164162

165163
zend_object_std_init(&intern->std, class_type);
166164
object_properties_init(&intern->std, class_type);

src/BSON/ObjectId.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ static void php_phongo_objectid_free_object(zend_object* object) /* {{{ */
360360

361361
static zend_object* php_phongo_objectid_create_object(zend_class_entry* class_type) /* {{{ */
362362
{
363-
php_phongo_objectid_t* intern = NULL;
364-
365-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_objectid_t, class_type);
363+
php_phongo_objectid_t* intern = zend_object_alloc(sizeof(php_phongo_objectid_t), class_type);
366364

367365
zend_object_std_init(&intern->std, class_type);
368366
object_properties_init(&intern->std, class_type);

src/BSON/Regex.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,7 @@ static void php_phongo_regex_free_object(zend_object* object) /* {{{ */
396396

397397
static zend_object* php_phongo_regex_create_object(zend_class_entry* class_type) /* {{{ */
398398
{
399-
php_phongo_regex_t* intern = NULL;
400-
401-
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_regex_t, class_type);
399+
php_phongo_regex_t* intern = zend_object_alloc(sizeof(php_phongo_regex_t), class_type);
402400

403401
zend_object_std_init(&intern->std, class_type);
404402
object_properties_init(&intern->std, class_type);

0 commit comments

Comments
 (0)