-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add an OOP API to HashContext #6347
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
Conversation
i think the failing test is just a stupid DIRECTORY_SEPARATOR issue in could just let %s take care of it,
|
dc3472d
to
115dcc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't see any issues, just one nit on folding brackets.
Overall, it seems like an improvement and a less error-prone alternate API
{ | ||
do_hash_init(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL); | ||
} | ||
/* {{{ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* {{{ */ | |
/* }}} */ |
What about making the context immutable? I have implemented a HashContext similar to this recently in PSL, with an immutable API: https://github.com/azjezz/psl/blob/8eece3a3c289922622136ec24d3e21c63b34a9ac/src/Psl/Hash/Context.php#L18-L31 this means whenever a function recieve an instance of with this implementation, if i write a function that is supposed to take a |
@@ -715,69 +682,54 @@ PHP_FUNCTION(hash_update_stream) | |||
} | |||
|
|||
if ((n = php_stream_read(stream, buf, toread)) <= 0) { | |||
RETURN_LONG(didread); | |||
if (throwOnError && (n < 0) && !EG(exception)) { | |||
zend_throw_exception_ex(NULL, 0, "Stream read encountered error, %zd bytes copied", didread); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try
zend_throw_exception_ex(NULL, 0, "Stream read encountered error, " ZEND_LONG_FMT " byte(s) copied", didread);
(something about 32bit zend_long printf format, check line 57 & 86 here here https://github.com/php/php-src/blob/master/Zend/zend_long.h#L57 )
i oppose this idea. i do not want the vanilla HashContext immutable. this would result in quite a few more malloc()+memcpy()'s for the "common" case of ->update(),
|
What's the status here? There are merge conflicts, and the PR might need an RFC (IMO it does). |
Closing as there was no response. |
Preliminary to writing up an RFC and following up on this thread: https://externals.io/message/112034
Summary:
__construct()
- Same signature as hash_init, callingnew HashContext(...)
should be equivalent tohash_init(same args)
update/updateStream/updateFile()
- Same parameters as functional API without having to pass the object.$this
for fluent calling. If an error is encountered, an exception is thrown.final()
- Exactly like callinghash_final($ctx)
getAlgo()
- Returns the name of the hashing algorithm in use.I resisted the urge to add static methods echoing APIs like hash_algos() as this didn't seem to add much, if anything.