Repository navigation
ffi: accept the full declaration form in dlsym() - #530
Merged
Merged
Conversation
The documentation of CLib#dlsym() names a full C declaration as the second form of its argument. uc_clib_dlsym() parses such a string with CPARSE_MODE_ABSTRACT, and in that mode the parser rejects a declarator with a name. So each declaration with a name fails with "failed to parse C declaration", also the example of the documentation. Add CPARSE_MODE_DIRECT, which uc_clib_resolve_common() also uses for wrap(). Keep CPARSE_MODE_ABSTRACT, so that a declaration without a name still gets the error "declaration does not define a named symbol". The form works for function declarations only; a variable or a constant declaration still fails, as before. So the documentation now names the form a full function declaration. The second line of the example read the code of getenv() as a char pointer through deref(), which ends with SIGSEGV. Call the symbol through wrap() instead, the documented way for a function pointer from dlsym(). Fixes: 23d5561 ("ffi: add LibFFI-based foreign function interface module") Fixes: ucode-lang#528 Signed-off-by: Piotr Kubik <piotr@kubik.pl>
Collaborator
|
Merged, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
uc_clib_dlsym()parses the documented full declaration form withCPARSE_MODE_ABSTRACTonly, which rejects a named declarator, soffi.C.dlsym('int abs(int)')fails.The change adds
CPARSE_MODE_DIRECT, as inwrap().Line 2 of the documented example now calls
getenv()throughwrap()instead of reading its code as a pointer.Limits: only function declarations work (the documentation now says so); variable and constant declarations still fail. The parser keeps the name of a failed non-function declaration on the shared type, so a later unnamed declaration can report it (
dlsym('int labs'), thendlsym('signed int')gives "missing declaration for symbol 'labs'"); master does the same throughwrap(), and this change leaves it.Test: the new
17_lib_ffi/37_dlsym_declarationfails on master and passes with the change; the other tests give the same results.Not tested: musl, 32-bit targets, valgrind.
Closes #528