Skip to content

Conversation

@bukka
Copy link
Member

@bukka bukka commented Sep 27, 2025

Currently filter seeking does not work correctly for most streams. The idea is to extend API to allow seeking for some streams. There are couple of cases:

  • filter is always seekable - e.g. string.rot13, string.toupper, string.tolower
  • filter is seekable only when sought to start or when it re-run the data from the start (it means when there is some data buffered) - this is for pretty much all other filters that keep some state.
  • user filters are seekable by default for BC reason but if new seek method is implemented, then it is called and based on the bool result the seeking either fails or succeed.

The seeking to zero is implemented by resetting the internal state.

Fixes https://bugs.php.net/bug.php?id=49874

@bukka
Copy link
Member Author

bukka commented Sep 27, 2025

Just to note that the current implementation is just an API draft that is not really tested. It's also does not handle the buffered procession and no current filter implements it. Also it will need proper tests.

@bukka
Copy link
Member Author

bukka commented Nov 24, 2025

This is now ready for review.

@bukka bukka requested a review from ndossche November 24, 2025 22:02
@bukka
Copy link
Member Author

bukka commented Jan 1, 2026

This is just a heads up that I plan to merge it tomorrow unless someone wants more time for review or finds anything that needs to be addressed. Of course, I'm happy to address any potentially issue even if found after merging. I just don't want to wait for review forever as this needs to get merged (part of my stream work)...

Copy link
Member

@ndossche ndossche left a comment

Choose a reason for hiding this comment

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

Cursory look

RETURN_LONG(PSFS_ERR_FATAL);
}

PHP_METHOD(php_user_filter, seek)
Copy link
Member

Choose a reason for hiding this comment

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

What does this mean for the check you added earlier that checks if "seek" is part of the function_table?

Copy link
Member Author

Choose a reason for hiding this comment

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

So this is because the filter is not required to be subclass of php_user_filter so if it isn't its subclass and it doesn't implement it, we return true for BC. If it is subclass of php_user_filter, then I thought it might be good to have it implemented so the child class can call parent::seek.

Copy link
Member

Choose a reason for hiding this comment

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

Okay I see. In the future I feel like we should require subclassing php_user_filter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah might be good candidate for deprecation and PHP 9 change...

@bukka bukka force-pushed the stream_filter_seeking branch from 73bcbd9 to f6f6152 Compare January 2, 2026 13:46
@bukka
Copy link
Member Author

bukka commented Jan 2, 2026

@ndossche Thanks a lot for the review. Hopefully all comments addressed.

Copy link
Member

@ndossche ndossche left a comment

Choose a reason for hiding this comment

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

Some nits

}

/* Make sure the stream is not closed while the filter callback executes. */
uint32_t orig_no_fclose = stream->flags & PHP_STREAM_FLAG_NO_FCLOSE;
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps I miss something here, but can't you move this flag update right before "Setup calling arguments" ?
Then you can clean up the error handling in the "userfilter_assign_stream" failure path as well.

Copy link
Member

Choose a reason for hiding this comment

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

And same for the other caller of userfilter_assign_stream

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 thought that it might cleaner not to pass orig_no_fclose but doesn't really matter. So changed as suggested.

Copy link
Member

Choose a reason for hiding this comment

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

No, I perhaps didn't express myself good enough.
What I meant was to move lines 283-284 to after userfilter_assign_stream, but now I see that idea is actually bogus because of property hooks. So perhaps the original code was better although the current code also seems fine.

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