Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same functionality duplicated by several macros #802

Closed
ghost opened this issue Jul 8, 2013 · 2 comments
Closed

Same functionality duplicated by several macros #802

ghost opened this issue Jul 8, 2013 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 8, 2013

ext/kernel/memory.h:

#define PHALCON_INIT_VAR_OLD(z) \
    PHALCON_ALLOC_ZVAL(z); \
    phalcon_memory_observe(&z TSRMLS_CC);

#define PHALCON_ALLOC_ZVAL_MM(z) \
    PHALCON_ALLOC_ZVAL(z); \
    phalcon_memory_observe(&z TSRMLS_CC);

The first one is not used, the second one is used once and can be replaced with PHALCON_INIT_VAR()

#define PHALCON_OBS_NVAR(z)\
    if (z) { \
        if (Z_REFCOUNT_P(z) > 1) { \
            Z_DELREF_P(z); \
        } else {\
            zval_ptr_dtor(&z); \
        } \
    } else { \
        phalcon_memory_observe(&z TSRMLS_CC); \
    }

#define PHALCON_OBSERVE_VAR(var) \
    if (!var) { \
        phalcon_memory_observe(&var TSRMLS_CC); \
    } else { \
        zval_ptr_dtor(&var); \
    }

These two do the same: _zval_ptr_dtor() merely Z_DELREF_P(z); when Z_REFCOUNT_P(z) > 1 and therefore PHALCON_OBSERVE_VAR can be dropped in favor of PHALCON_OBS_NVAR.

#define PHALCON_SEPARATE(z) \
    { \
        zval *orig_ptr = z; \
        if (Z_REFCOUNT_P(orig_ptr) > 1) { \
            Z_DELREF_P(orig_ptr); \
            ALLOC_ZVAL(z); \
            *z = *orig_ptr; \
            zval_copy_ctor(z); \
            Z_SET_REFCOUNT_P(z, 1); \
            Z_UNSET_ISREF_P(z); \
        } \
    }

#define PHALCON_SEPARATE_NMO(z) \
    {\
        zval *orig_ptr = z;\
        if (Z_REFCOUNT_P(orig_ptr) > 1) {\
            Z_DELREF_P(orig_ptr);\
            ALLOC_ZVAL(z);\
            *z = *orig_ptr;\
            zval_copy_ctor(z);\
            Z_SET_REFCOUNT_P(z, 1);\
            Z_UNSET_ISREF_P(z);\
        }\
    }

I don't see any difference (except spaces). PHALCON_SEPARATE_NMO is used only once; they both do the same as

#define SEPARATE_ZVAL(ppzv)                                 \
    {                                                       \
        zval *orig_ptr = *(ppzv);                           \
                                                            \
        if (Z_REFCOUNT_P(orig_ptr) > 1) {                   \
            Z_DELREF_P(orig_ptr);                           \
            ALLOC_ZVAL(*(ppzv));                            \
            **(ppzv) = *orig_ptr;                           \
            zval_copy_ctor(*(ppzv));                        \
            Z_SET_REFCOUNT_PP(ppzv, 1);                     \
            Z_UNSET_ISREF_PP((ppzv));                       \
        }                                                   \
    }

and therefore

#define PHALCON_SEPARATE(pzv) SEPARATE_ZVAL(&ppzv) 

should do the trick.

#define PHALCON_SEPARATE_PARAM_NMO(z) { \
        zval *orig_ptr = z; \
        if (Z_REFCOUNT_P(orig_ptr) > 1) { \
            ALLOC_ZVAL(z); \
            *z = *orig_ptr; \
            zval_copy_ctor(z); \
            Z_SET_REFCOUNT_P(z, 1); \
            Z_UNSET_ISREF_P(z); \
        } \
    }

not used anywhere and probably can be dropped.

@phalcon
Copy link
Collaborator

phalcon commented Jul 24, 2013

@sjinks can you please submit a pull request removing the unused macros to 1.3.0?

@ghost
Copy link
Author

ghost commented Jul 25, 2013

Done, see #916

@ghost ghost closed this as completed Jul 25, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants