[patch] require dlerror before dlsym

Started by kosh, December 16, 2013, 11:11:57 AM

Previous topic - Next topic

kosh

Hi Lutz.



I found unusual behavior when 'import' called from url.


newLISP v.10.5.4 32-bit on BSD IPv4/6 UTF-8 libffi, options: newlisp -h

> (setq url "http://lambda.que.jp/files/x.lsp")
> (get-url url)
"(import "libc.so" "printf")n"
> (load url)

ERR: import function not found in function import : "Undefined symbol "_nss_cac
he_cycle_prevention_function""


Perhaps, you should call the dlerror() to clear error code before dlsym().



http://tldp.org/HOWTO/Program-Library-HOWTO/dl-libraries.html">http://tldp.org/HOWTO/Program-Library-H ... aries.html">http://tldp.org/HOWTO/Program-Library-HOWTO/dl-libraries.html


Quote4.3. dlsym()

...

The standard solution is to call dlerror() first (to clear any error condition that may have existed), then call dlsym() to request a symbol, then call dlerror() again to see if an error occurred. A code snippet would look like this:


dlerror(); /* clear error code */
 s = (actual_type) dlsym(handle, symbol_being_searched_for);
 if ((err = dlerror()) != NULL) {
  /* handle error, the symbol wasn't found */
 } else {
  /* symbol found, its value is in s */
 }



Patch file here:


diff --git a/nl-import.c b/nl-import.c
index a14264f..40a1320 100644
--- a/nl-import.c
+++ b/nl-import.c
@@ -172,6 +172,8 @@ pCell = getCell(type);
 deleteList((CELL *)symbol->contents);
 symbol->contents = (UINT)pCell;

+dlerror();
+
 pCell->contents = (UINT)dlsym(hLibrary, funcName);

 if((error = (char *)dlerror()) != NULL)

Lutz

#1
Thanks Kosh: http://www.newlisp.org/downloads/development/inprogress/">http://www.newlisp.org/downloads/develo ... nprogress/">http://www.newlisp.org/downloads/development/inprogress/