protected versus libc functions

Started by newdep, March 24, 2004, 02:23:21 PM

Previous topic - Next topic

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.
-- (define? (Cornflakes))

HPW

#1
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.
Hans-Peter

Lutz

#2
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

Lutz

#3
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

newdep

#4
Thats a dymanic part of newlisp i like Lutz ;-)

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



Norman.
-- (define? (Cornflakes))

Lutz

#5
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