Skip to content

ext/*: Make X_from_obj(zend_object *obj) functions macros#22183

Open
TimWolla wants to merge 3 commits into
php:masterfrom
TimWolla:from-obj-macro
Open

ext/*: Make X_from_obj(zend_object *obj) functions macros#22183
TimWolla wants to merge 3 commits into
php:masterfrom
TimWolla:from-obj-macro

Conversation

@TimWolla
Copy link
Copy Markdown
Member

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(...) { ... }

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(...) { ... }
Comment thread ext/sockets/sockets.c
php_socket *php_socket;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT_OF_CLASS(arg1, socket_ce)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible follow-up, but maybe we should refactor this to use the version that returns a zend_object rather than zval?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants