protected versus libc functions

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

protected versus libc functions

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

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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.
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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

Post 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

Locked