Skip to content

Refactor SplFileObject methods #6014

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

Closed
wants to merge 18 commits into from
Closed

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Aug 18, 2020

This is an attempted at making this class a bit easier to follow...

However since PHP 8 disabled functions are unregistered it's possible to hit some new unconventional paths which I tried to drop however I ran into some issues with flock(). [The compatibility layer wasn't completely useful and just needed some tweaks...]

For fstat() the best way to mitigate this is by extracting the actual part populating the array into a separate function which is exported so that SPL can call that.

@@ -344,7 +344,9 @@ PHP_FUNCTION(flock)

PHP_STREAM_TO_ZVAL(stream, res);

act = operation & 3;
act = operation & PHP_LOCK_UN;
// TODO doesn't this fail if operation is a bitmask with LOCK_NB?
Copy link
Member

Choose a reason for hiding this comment

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

Assuming that LOCK_NB==4 and PHP_LOCK_UN==3, the former would have already been masked out.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not very good at understanding masks so I assume that you're correct

@@ -57,6 +52,13 @@ PHPAPI zend_class_entry *spl_ce_GlobIterator;
PHPAPI zend_class_entry *spl_ce_SplFileObject;
PHPAPI zend_class_entry *spl_ce_SplTempFileObject;

// TODO Use standard Error
#define CHECK_SPL_FILE_OBJECT_IS_INITIALIZED() \
Copy link
Member

Choose a reason for hiding this comment

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

Maybe accept the spl_filesystem_object * as parameter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, will do that

@@ -1,3 +1,3 @@
PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c, no,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h])
PHP_ADD_EXTENSION_DEP(spl, pcre, true)
PHP_ADD_EXTENSION_DEP(standard, spl, pcre, true)
Copy link
Member

Choose a reason for hiding this comment

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

Are the first two arguments swapped?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed


/* {{{ Stat() on a filehandle */
PHP_FUNCTION(fstat)
PHPAPI void php_fstat(php_stream *stream, zval *return_value)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should I make this return a zval* instead of the out param?

Copy link
Member

Choose a reason for hiding this comment

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

How is failure signaled?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be signalled by a IS_FALSE zval* as it's currently the value returned when fstats() fails. Not sure if that's a good idea but signalling it via SUCCESS/FAILURE or true/false seems rather pointless because I would expect anyone using this API to want the result of the fstats call if it succeeded.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, thanks! If I understand correctly, return_value is an in/out parameter, and that would be fine.

@php-pulls php-pulls closed this in 430b3ac Sep 3, 2020
@Girgias Girgias deleted the spl-dir-refactor branch September 3, 2020 12:24
static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN };

/* {{{ Portable file locking, copy pasted from ext/standard/file.c flock() function.
* This is done to prevent this to fail if flock is disabled via disable_functions */
Copy link
Member

Choose a reason for hiding this comment

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

Is that a bug or a feature? If someone disabled flock(), I imagine they also wouldn't want SplFileInfo::flock() to work, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good question, but most SPL methods are not disabled when the corresponding functional version is disabled. That's why I did this, moreover this was considered as an internal "bug" so if we want to revert this I think any function which is disabled should then disable it's SPL counterpart IMHO

Copy link
Member

Choose a reason for hiding this comment

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

Either way, copy and paste doesn't look like a good idea to me.

Copy link
Member

Choose a reason for hiding this comment

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

That's a good question, but most SPL methods are not disabled when the corresponding functional version is disabled.

Good point. If it's the same with other functions, then I'm fine with it.

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

Successfully merging this pull request may close these issues.

3 participants