On 5 February 2015 at 22:28, Rasmus Lerdorf <ras...@lerdorf.com> wrote:
> Any suggestions for how to handle annotating it? We could turn it into a
> fake PR and mark it up using github's PR comments.

I think that's a good idea. It is very easy for people to ask
questions about any change that they don't understand on the exact
lines that are confusing them.

Also, I found it useful when converting Imagick to have a checklist of
everything that needed to be done, in a simple format, rather than the
full explanation of the changes at
https://wiki.php.net/phpng-upgrading. That allowed me to search for
the things that needed fixing.

You could then put links to the PR from checklist for an example of
the change in place.

cheers
Dan


An incomplete checklist for migrating an extension to PHP7
------------------------------------------------------------------------------

1) Parse parameters changed from zval ** to just zval*

- zval **pzv;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &pzv) == FAILURE) {
+ zval *zv;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zv) == FAILURE) {


2) Geting value from a reference has changed:

- if (Z_ISREF_P(zv) && Z_TYPE_P(zv) == IS_ARRAY) {
+ if (Z_ISREF_P(zv) && Z_TYPE_P(Z_REFVAL_P(zv)) == IS_ARRAY) {


3) remove IS_BOOL, replace with IS_TRUE or IS_FALSE

- if ((Z_TYPE_PP(item) == IS_BOOL || Z_TYPE_PP(item) == IS_LONG) &&
Z_LVAL_PP(item)) {
+ if (Z_TYPE_P(item) == IS_TRUE || (Z_TYPE_P(item) == IS_LONG &&
Z_LVAL_P(item))) {


4) change Z_ADDREF_P

- Z_ADDREF_P(zv)
+ if (Z_REFCOUNTED_P(zv)) {Z_ADDREF_P(zv);}
# or equivalently
+ Z_TRY_ADDREF_P(zv);

5) zval values should be copied using ZVAL_COPY_VALUE() macro

6) Nulling things
If you converted a zval* into a zval and previously used NULL to
indicate an undefined value,
you can now use the IS_UNDEF type instead. It can be set using
ZVAL_UNDEF(&zv) and
checked using if (Z_ISUNDEF(zv)).

7) Copying zvals to avoid modification not needed as much. You can get
the value directly.

- zval tmp;
- ZVAL_COPY_VALUE(&tmp, zv);
- zval_copy_ctor(&tmp);
- convert_to_string(&tmp);
- // ...
- zval_dtor(&tmp);
+ zend_string *str = zval_get_string(zv);
+ // ...
+ STR_RELEASE(str);


8) Change string access from Z_STRVAL_P for intern checking
- if (IS_INTERNED(Z_STRVAL_P(zv))) {
+ if (IS_INTERNED(Z_STR_P(zv))) {


9) Creation of zval_string, remove redundant param

- ZVAL_STRINGL(zv, str, len, 1);
+ ZVAL_STRINGL(zv, str, len);

- ZVAL_STRING(zv, str, 0);
+ ZVAL_STRING(zv, str);
+ efree(str);


10) Zend_hash_find has changed
- if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key)+1,
(void**)&zv_ptr) == SUCCESS) {
+ if ((zv = zend_hash_find(ht, Z_STR_P(key))) != NULL) {


11) Change zend_string is used instead of char * and len for parameters
- char *str;
- int len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str,
&len) == FAILURE) {
+ zend_string *str;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) {


12) References access has changed.

- zval **ret;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &ret) == FAILURE) {
+ zval *ret;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &ret) == FAILURE) {
    return;
  }
- ZVAL_LONG(*ret, 0);
+ ZVAL_LONG(ret, 0);


13) Arrays are initialised with

- MAKE_STD_ZVAL(tmp);
- array_init(tmp);
+ ZVAL_NEW_ARR(&tmp);
+ array_init(&tmp);


14) Iterating over a hash has a macro, and the key has been changd to zend_ulong

- ulong num_key;
+ zend_ulong num_key;

- for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(param_array));
- zend_hash_get_current_data(Z_ARRVAL_P(param_array), (void **)
&ppzval) == SUCCESS;
- zend_hash_move_forward(Z_ARRVAL_P(param_array)), i++)
- {
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(param_array), num_key, key, pzvalue) {
+ zval tmp_zval, *tmp_pzval;
+ long value = 0;

+ } ZEND_HASH_FOREACH_END();


15) Remove all MAKE_STD_ZVAL and turn those variables from  "zval
*zv;" to "zval zv;"

16) TSRM macros now do nothing. They can either be left in place or
removed if you do not need to support 5.x

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to