Skip to content

Commit 69e023f

Browse files
authored
ext/*: Make X_from_obj(zend_object *obj) functions macros (#22183)
* ext/*: Make `X_from_obj(zend_object *obj)` functions macros With the introduction of the `ZEND_CONTAINER_OF()` macro we can now preserve whether or not the `zend_object *` is `const` when extracting the class-specific struct. This change will allow to use `const zend_object *` in more locations. Changes performed with Coccinelle followed by some manual cleanup for comment and whitespace formatting: @A@ attribute name zend_always_inline; type T; identifier obj; identifier f; typedef zend_object; @@ T* f(zend_object *obj) { return ZEND_CONTAINER_OF(obj, T, std); } + #define f(obj) ZEND_CONTAINER_OF(obj, T, std) @@ identifier a.f; @@ - f(...) { ... } @b@ attribute name zend_always_inline; type T; identifier obj; identifier f; typedef zend_object; @@ T* f(zend_object *obj) { return ZEND_CONTAINER_OF(obj, T, zo); } + #define f(obj) ZEND_CONTAINER_OF(obj, T, zo) @@ identifier b.f; @@ - f(...) { ... } * sockets: Fix build * odbc: Fix build
1 parent 61e679d commit 69e023f

56 files changed

Lines changed: 85 additions & 268 deletions

Some content is hidden

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

ext/curl/curl_private.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,11 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source);
151151
/* Consumes `zv` */
152152
zend_long php_curl_get_long(zval *zv);
153153

154-
static inline php_curl *curl_from_obj(zend_object *obj) {
155-
return ZEND_CONTAINER_OF(obj, php_curl, std);
156-
}
154+
#define curl_from_obj(obj) ZEND_CONTAINER_OF(obj, php_curl, std)
157155

158156
#define Z_CURL_P(zv) curl_from_obj(Z_OBJ_P(zv))
159157

160-
static inline php_curlsh *curl_share_from_obj(zend_object *obj) {
161-
return ZEND_CONTAINER_OF(obj, php_curlsh, std);
162-
}
158+
#define curl_share_from_obj(obj) ZEND_CONTAINER_OF(obj, php_curlsh, std)
163159

164160
#define Z_CURL_SHARE_P(zv) curl_share_from_obj(Z_OBJ_P(zv))
165161

ext/curl/multi.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848

4949
zend_class_entry *curl_multi_ce;
5050

51-
static inline php_curlm *curl_multi_from_obj(zend_object *obj) {
52-
return ZEND_CONTAINER_OF(obj, php_curlm, std);
53-
}
51+
#define curl_multi_from_obj(obj) ZEND_CONTAINER_OF(obj, php_curlm, std)
5452

5553
#define Z_CURL_MULTI_P(zv) curl_multi_from_obj(Z_OBJ_P(zv))
5654

ext/date/php_date.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ struct _php_date_obj {
5858
zend_object std;
5959
};
6060

61-
static inline php_date_obj *php_date_obj_from_obj(zend_object *obj) {
62-
return ZEND_CONTAINER_OF(obj, php_date_obj, std);
63-
}
61+
#define php_date_obj_from_obj(obj) ZEND_CONTAINER_OF(obj, php_date_obj, std)
6462

6563
#define Z_PHPDATE_P(zv) php_date_obj_from_obj(Z_OBJ_P((zv)))
6664

@@ -75,9 +73,7 @@ struct _php_timezone_obj {
7573
zend_object std;
7674
};
7775

78-
static inline php_timezone_obj *php_timezone_obj_from_obj(zend_object *obj) {
79-
return ZEND_CONTAINER_OF(obj, php_timezone_obj, std);
80-
}
76+
#define php_timezone_obj_from_obj(obj) ZEND_CONTAINER_OF(obj, php_timezone_obj, std)
8177

8278
#define Z_PHPTIMEZONE_P(zv) php_timezone_obj_from_obj(Z_OBJ_P((zv)))
8379

@@ -93,9 +89,7 @@ struct _php_interval_obj {
9389
zend_object std;
9490
};
9591

96-
static inline php_interval_obj *php_interval_obj_from_obj(zend_object *obj) {
97-
return ZEND_CONTAINER_OF(obj, php_interval_obj, std);
98-
}
92+
#define php_interval_obj_from_obj(obj) ZEND_CONTAINER_OF(obj, php_interval_obj, std)
9993

10094
#define Z_PHPINTERVAL_P(zv) php_interval_obj_from_obj(Z_OBJ_P((zv)))
10195

@@ -112,9 +106,7 @@ struct _php_period_obj {
112106
zend_object std;
113107
};
114108

115-
static inline php_period_obj *php_period_obj_from_obj(zend_object *obj) {
116-
return ZEND_CONTAINER_OF(obj, php_period_obj, std);
117-
}
109+
#define php_period_obj_from_obj(obj) ZEND_CONTAINER_OF(obj, php_period_obj, std)
118110

119111
#define Z_PHPPERIOD_P(zv) php_period_obj_from_obj(Z_OBJ_P((zv)))
120112

ext/dba/dba.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,7 @@ static zend_result dba_connection_cast_object(zend_object *obj, zval *result, in
335335
return zend_std_cast_object_tostring(obj, result, type);
336336
}
337337

338-
static inline dba_connection *dba_connection_from_obj(zend_object *obj)
339-
{
340-
return ZEND_CONTAINER_OF(obj, dba_connection, std);
341-
}
338+
#define dba_connection_from_obj(obj) ZEND_CONTAINER_OF(obj, dba_connection, std)
342339

343340
#define Z_DBA_CONNECTION_P(zv) dba_connection_from_obj(Z_OBJ_P(zv))
344341
#define Z_DBA_INFO_P(zv) Z_DBA_CONNECTION_P(zv)->info

ext/dom/xml_common.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ typedef struct _dom_object {
2727
zend_object std;
2828
} dom_object;
2929

30-
static inline dom_object *php_dom_obj_from_obj(zend_object *obj) {
31-
return ZEND_CONTAINER_OF(obj, dom_object, std);
32-
}
30+
#define php_dom_obj_from_obj(obj) ZEND_CONTAINER_OF(obj, dom_object, std)
3331

3432
#define Z_DOMOBJ_P(zv) php_dom_obj_from_obj(Z_OBJ_P((zv)))
3533

ext/enchant/enchant.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ typedef struct _dict_struct {
4848
zend_class_entry *enchant_broker_ce;
4949
static zend_object_handlers enchant_broker_handlers;
5050

51-
static inline enchant_broker *enchant_broker_from_obj(zend_object *obj) {
52-
return ZEND_CONTAINER_OF(obj, enchant_broker, std);
53-
}
51+
#define enchant_broker_from_obj(obj) ZEND_CONTAINER_OF(obj, enchant_broker, std)
5452

5553
#define Z_ENCHANT_BROKER_P(zv) enchant_broker_from_obj(Z_OBJ_P(zv))
5654

@@ -66,9 +64,7 @@ static zend_object *enchant_broker_create_object(zend_class_entry *class_type) {
6664
zend_class_entry *enchant_dict_ce;
6765
static zend_object_handlers enchant_dict_handlers;
6866

69-
static inline enchant_dict *enchant_dict_from_obj(zend_object *obj) {
70-
return ZEND_CONTAINER_OF(obj, enchant_dict, std);
71-
}
67+
#define enchant_dict_from_obj(obj) ZEND_CONTAINER_OF(obj, enchant_dict, std)
7268

7369
#define Z_ENCHANT_DICT_P(zv) enchant_dict_from_obj(Z_OBJ_P(zv))
7470

ext/fileinfo/fileinfo.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ typedef struct _finfo_object {
4343
zend_object zo;
4444
} finfo_object;
4545

46-
static inline finfo_object *php_finfo_fetch_object(zend_object *obj) {
47-
return ZEND_CONTAINER_OF(obj, finfo_object, zo);
48-
}
46+
#define php_finfo_fetch_object(obj) ZEND_CONTAINER_OF(obj, finfo_object, zo)
4947

5048
#define Z_FINFO_P(zv) php_finfo_fetch_object(Z_OBJ_P((zv)))
5149

ext/gd/gd.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,7 @@ static zend_function *php_gd_image_object_get_constructor(zend_object *object)
144144
return NULL;
145145
}
146146

147-
/**
148-
* Returns the underlying php_gd_image_object from a zend_object
149-
*/
150-
151-
static zend_always_inline php_gd_image_object* php_gd_exgdimage_from_zobj_p(zend_object* obj)
152-
{
153-
return ZEND_CONTAINER_OF(obj, php_gd_image_object, std);
154-
}
147+
#define php_gd_exgdimage_from_zobj_p(obj) ZEND_CONTAINER_OF(obj, php_gd_image_object, std)
155148

156149
/**
157150
* Converts an extension GdImage instance contained within a zval into the gdImagePtr

ext/gmp/php_gmp_int.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ typedef struct _gmp_object {
3535
zend_object std;
3636
} gmp_object;
3737

38-
static inline gmp_object *php_gmp_object_from_zend_object(zend_object *zobj) {
39-
return ZEND_CONTAINER_OF(zobj, gmp_object, std);
40-
}
38+
#define php_gmp_object_from_zend_object(zobj) ZEND_CONTAINER_OF(zobj, gmp_object, std)
4139

4240
PHP_GMP_API zend_class_entry *php_gmp_class_entry(void);
4341

ext/intl/breakiterator/breakiterator_class.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ typedef struct {
4141
zend_object zo;
4242
} BreakIterator_object;
4343

44-
static inline BreakIterator_object *php_intl_breakiterator_fetch_object(zend_object *obj) {
45-
return ZEND_CONTAINER_OF(obj, BreakIterator_object, zo);
46-
}
44+
#define php_intl_breakiterator_fetch_object(obj) ZEND_CONTAINER_OF(obj, BreakIterator_object, zo)
4745
#define Z_INTL_BREAKITERATOR_P(zv) php_intl_breakiterator_fetch_object(Z_OBJ_P(zv))
4846

4947
#define BREAKITER_ERROR(bio) (bio)->err

0 commit comments

Comments
 (0)