[patch] require dlerror before dlsym

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
kosh
Posts: 72
Joined: Sun Sep 13, 2009 5:38 am
Location: Japan
Contact:

[patch] require dlerror before dlsym

Post by kosh »

Hi Lutz.

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

Code: Select all

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-H ... aries.html
4.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:

Code: Select all

 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:

Code: Select all

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: [patch] require dlerror before dlsym

Post by Lutz »


Locked