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

Use zend_string for DBA path #10698

Merged
merged 3 commits into from
Apr 8, 2023
Merged

Use zend_string for DBA path #10698

merged 3 commits into from
Apr 8, 2023

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Feb 25, 2023

Doing this because I'm struggling to do the conversion from resource to opaque object for persistent resources.

Which also makes me wonder if there isn't an existing underlying bug somewhere because I cannot use zend_string_release_ex(info->path, info->flags&DBA_PERSISTENT); in dba_close() as the refcount seems to already be 0 for persistent resources. Something I really don't understand. So if anyone has any ideas...

Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

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

Looks good to me appart from a few comments

ext/dba/dba.c Outdated
Comment on lines 265 to 267
ZEND_ASSERT(info->path);
// Cannot use zend_string_release_ex(info->path, info->flags&DBA_PERSISTENT); as this fails GC assertion?
zend_string_free(info->path);
info->path = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Which test is failing the assertion?

If the failing assertion is ZEND_ASSERT(GC_FLAGS(s) & IS_STR_PERSISTENT);, there is a discrepancy between the persistent flag in info->flags and whether info->path is actually persistent.

zend_string_release() (non _ex variant) would be the right function to use here. zend_string_release_ex() is an optimization for when the persistent argument is known at compile time (removes a branch).

zend_string_free() is also suitable, as long as refcount is 1, but this seems less maintainable.

Copy link
Member Author

Choose a reason for hiding this comment

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

The failling assertion is:

php: /home/girgias/Dev/php-src/Zend/zend_rc_debug.c:38: void ZEND_RC_MOD_CHECK(const zend_refcounted_h *): Assertion `(zval_gc_flags(p->u.type_info) & ((1<<7)|(1<<8))) != (1<<7)' failed.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, thank you! I didn't have the ZEND_RC_DEBUG flag.

ZEND_RC_MOD_CHECK is complaining that we should not touch the refcount of a PERSISTENT string, under the expectation that PERSISTENT strings are not refcounted.

We can disable this check by using GC_MAKE_PERSISTENT_LOCAL(s) in php_dba_zend_string_dup_safe when persistent is true.

We also need to change php_dba_zend_string_dup_safe so that PERSISTENT strings are duplicated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the explanations! Will do this now. :)

ext/dba/dba.c Outdated
/* replace the path info with the real path of the opened file */
pefree(info->path, persistent);
info->path = pestrndup(ZSTR_VAL(opened_path), ZSTR_LEN(opened_path), persistent);
zend_string_release_ex(info->path, persistent);
Copy link
Member

Choose a reason for hiding this comment

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

We don't need zend_string_release_ex() here, we can use zend_string_release(), as it knows whether the str is persistent or not

ext/dba/dba.c Outdated
@@ -724,7 +725,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)

info = pemalloc(sizeof(dba_info), persistent);
memset(info, 0, sizeof(dba_info));
info->path = pestrdup(ZSTR_VAL(path), persistent);
info->path = zend_string_dup(path, persistent);
Copy link
Member

Choose a reason for hiding this comment

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

After looking at #9768, I think that we shouldn't use zend_string_dup when persistent might be true.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is confusing, but okay I see the issue :-/

@Girgias Girgias requested a review from arnaud-lb April 7, 2023 13:19
@Girgias Girgias merged commit 421c56d into php:master Apr 8, 2023
@Girgias Girgias deleted the dba-path-str branch April 8, 2023 16:03
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