Skip to content

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Apr 3, 2023

Because it shouldn't be modified, and I hit this while working on something related to #8294 as I was passing a const filename.

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

The argument was not made const on purpose. To keep an ability to return the copy of argument.

Actually, this should be the usual case for absolute paths without sym-links.

I remember I had some troubles converting php_resolve_path() to usezend_string instead of const char* in PHP-7 times and this opportunity wasn't implemented.

void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
ZEND_API zend_string *(*zend_resolve_path)(zend_string *filename);
ZEND_API zend_string *(*zend_resolve_path)(const zend_string *filename);
Copy link
Member

Choose a reason for hiding this comment

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

In general, zend_resolve_path() may return the same string and in case of non-interned string this requires incrementation if reference counter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, this makes sense, but are we not doing this in practice because tsrm_realpath() still returns a char * ?

Also, shouldn't the ZendAccelerator implementation also increment the refcount? Instead of doing what it does by returning the pointer directly instead of zend_string_copy(str);?

Copy link
Member

Choose a reason for hiding this comment

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

zend_string_copy() just increment the refcount and return the same string. See https://github.com/php/php-src/blob/master/Zend/zend_string.h#L236

Copy link
Member

Choose a reason for hiding this comment

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

Right, this makes sense, but are we not doing this in practice because tsrm_realpath() still returns a char * ?

Yes. It would be great to switch to zend_string in all related functions, but this is going to be a big and not simple patch.

Copy link
Member Author

Choose a reason for hiding this comment

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

zend_string_copy() just increment the refcount and return the same string. See https://github.com/php/php-src/blob/master/Zend/zend_string.h#L236

Yes I know this, my question is why in ZendAccelerator.c the string is returned directly without incrementing the refcount, as after your explanation it seems this should be done.


/* not use_cwd */
return str;
return (zend_string*)str;
Copy link
Member

Choose a reason for hiding this comment

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

Here you remove const, so something in your patch is not consistent.

@Girgias
Copy link
Member Author

Girgias commented Apr 5, 2023

Closing as it doesn't make sense in practice as the string might need to increment the refcount.

I will look into switch the relevant functions from const char*, size_t to zend_string *.

@Girgias Girgias closed this Apr 5, 2023
@Girgias Girgias deleted the resolve-path-const-qualifier branch April 5, 2023 11:34
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.

3 participants