- Notifications
You must be signed in to change notification settings - Fork 210
Print a custom error message on platforms with ext/json as shared extension #480
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
The extra warning there is of course not printed when things go fine:
|
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.
I left a few comments, but, in general, I am not sure whether we should do this.
It is really a distribution's problem. Their binaries mess up PHP's normal extension API, so they should also provide the solutions to fix this, or provide the extensions as binaries.
#endif | ||
| ||
static void _phongo_check_json (void) __attribute__((constructor)); | ||
static void _phongo_check_json (void) |
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.
This does not seem to be called from anywhere?
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.
Its called automatically during dlopen
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.
That's a problem then, as it would mean that PHP's normal loading reordering will no longer work. Basically, making the off case work (where distributions mangle PHP's original itents), but not the standard case where PHP itself manages the loading/symbol fetching order (the patch actively prevents this from working now).
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.
Does __attribute__((constructor))
result in this preempting PHP's own extension dependency resolution based on the list in our zend_module_entry?
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.
@derickr: How does this affect PHP's ordering if we're still keeping the dependency in our zend_module_dep
list? @bjori linked me to zend_startup_module_ex()
, which just appears to check that dependencies are already loaded at the time our extension is loaded.
If we're loaded via dlopen()
before json.so
and this triggers, hasn't PHP already failed to ensure our json.so
dependency?
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.
PHP's mechanism is as follows:
dlopen()
all extensions in their loading order (order as in .ini file). This works normally, asLTDL_LAZY
is being used and no symbols are being resolved yet.- create dependency graph
- go initialize extensions in the right order as to not have undefined symbols
The new constructor is run on dlopen()
, and hence, breaks the original mechanism of being to open extensions in a random order.
static void _phongo_check_json (void) | ||
{ | ||
DL_HANDLE handle = DL_LOAD(NULL); | ||
zend_class_entry *json = (zend_class_entry *)DL_FETCH_SYMBOL (handle, "php_json_serializable_ce"); |
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.
Some OSses prefix the symbols with a _
, and no check for that is done here.
See: https://github.com/php/php-src/blob/master/ext/standard/dl.c#L142
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.
I was under the impression the macro abstracted it. Looking it up, I guess not
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.
I have doubt about this working if php_json_serializable_ce is not publicly exported.
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.
this isn't actually needed. as long as the references to the symbol are removed and it rather dynamically loaded, like the rest of the patch.
This function is only for the purpose of augmenting the error message from php if they want to give direct instructions
PHP_MINIT_FUNCTION(Binary) | ||
{ | ||
zend_class_entry ce; | ||
zend_string *zstr = zend_string_init("jsonserializable", sizeof("jsonserializable") - 1, 0); |
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.
zend_string_init is new in PHP 7.0, so this needs an #ifdef.
This PR actually does two things.
I consider this to be significant improvement to the user experience and even it is not the mongodb drivers fault, we can still improve the experience for the users |
#endif | ||
| ||
static void _phongo_check_json (void) __attribute__((constructor)); | ||
static void _phongo_check_json (void) |
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.
That's a problem then, as it would mean that PHP's normal loading reordering will no longer work. Basically, making the off case work (where distributions mangle PHP's original itents), but not the standard case where PHP itself manages the loading/symbol fetching order (the patch actively prevents this from working now).
See #500. |
Before:
After: