Page 1 of 1

protected versus libc functions

Posted: Wed Mar 24, 2004 10:23 pm
by newdep
Lutz,

Actualy this should not occeur but its posisble, newlisp has some function
names "not much, luckely" that overlap 100% the C function names..

An example is "getenv" which occeurs in libc but also in libncurses, so
if you want to import it the "protection" error pops up... This all is not a problem
though to make newlisp functions unique an option could be to place an "-"
in between i.e. get-env to make it more newlispy...?

Well it not a big issue actualy because if you know its predefined in newlisp...

Norman.

Posted: Thu Mar 25, 2004 6:43 am
by HPW
The only thing which can we do in the moemnt is to define a wrapper function/DLL, when we want to import a function which exists as a newLISP command. The wrapper would translate a new name to the existing one.

Posted: Thu Mar 25, 2004 1:34 pm
by Lutz
No problem at all, you still can import getenv inside a context:

(context 'MYLIB)

(import "/usr/lib/libc.so.6" "getenv")

(context 'MAIN)

(get-string (MYLIB:getenv "PATH")) => "/bin:/usr/bin:/usr/local/bin ........


Lutz

Posted: Thu Mar 25, 2004 1:46 pm
by Lutz
if you insist on having it in the MAIN context you can read "hacking_newlisp.html" in the distribution doc directory and do:

(cpymem (pack "c c" 0 32) (last (dump 'getenv)) 2)

This will reset the protection bit on the symbol and still leave it global (see newlisp.h for the type flags)

Lutz

Posted: Thu Mar 25, 2004 11:49 pm
by newdep
Thats a dymanic part of newlisp i like Lutz ;-)
Ill give it a try..always good to play with the internals..

Norman.

Posted: Fri Mar 26, 2004 5:07 pm
by Lutz
when you play with 'cpymem' make sure your are aware of the byte-order of your machine, the example was for Intel CPUs; on Mac OSX or Solaris you would have to do:

(cpymem (pack "c c" 32 0) (last (dump 'getenv)) 2)

reversing the bytes to high->low order

Lutz