newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: newdep on March 24, 2004, 02:23:21 PM

Title: protected versus libc functions
Post by: newdep on March 24, 2004, 02:23:21 PM
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.
Title:
Post by: HPW on March 24, 2004, 10:43:38 PM
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.
Title:
Post by: Lutz on March 25, 2004, 05:34:51 AM
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
Title:
Post by: Lutz on March 25, 2004, 05:46:16 AM
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
Title:
Post by: newdep on March 25, 2004, 03:49:57 PM
Thats a dymanic part of newlisp i like Lutz ;-)

Ill give it a try..always good to play with the internals..



Norman.
Title:
Post by: Lutz on March 26, 2004, 09:07:46 AM
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