(dump)

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

(dump)

Post by newdep »

Hi Lutz,

Is it possible to clear a complete function from newlisp
using dump/pack/cpymem.. If yes then what byte do i
exactly need to set/remove to make sure the function is:

a) disabled (or just make it 0x00 ?)
b) cleared from the newlisp stack? (if possible at all)

Thanks in advance... Norman.
-- (define? (Cornflakes))

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

Post by HPW »

When I have a function:

(define (bla )("MyFunction"))

I can delete it:

(setq bla nil)

It is not protected with 'constant.

I does not appear in the function-browser any more.
Hans-Peter

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

Post by newdep »

Oo sorry i must clarify my question...(Thanks anyway HPW ;-)

I ment Newlisp Internal "protected" functions.

So after making then "unprotected" (0 32) i want to remove it from newlisp.

Norman.
-- (define? (Cornflakes))

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

Post by HPW »

Seems to be the hard way.

Why not compile your special newLISP with removed function?
Hans-Peter

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

Post by newdep »

Yes its an option that but the "disable"/"enable" function
must be dynamic configurable for the user (im my applicaiton)...
-- (define? (Cornflakes))

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

Post by Lutz »

read "doc/hacking_newlisp.html" from the source distribution. Remove the protection bit, then use 'delete' to delete the symbol

I just realize it works not on built-ins

Lutz
Last edited by Lutz on Mon Oct 04, 2004 8:22 pm, edited 2 times in total.

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

Post by newdep »

Haa... 'delete...!!! Did not even noticed that one ;-) thanks...
(Its all there ;-)
-- (define? (Cornflakes))

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

Post by Lutz »

I just realize it may not work on builtin functions

Lutz

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

Post by Lutz »

But here is a way to make it work with (set 'print nil) inbetween:

Code: Select all

symbol is protected in function set : print

> (cpymem (pack "c c" 0 32) (last (dump 'print)) 2)
2
> (set 'print nil)
nil
> (delete 'print)
true
Lutz

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

Post by newdep »

every combination i make it keep dumping... on linux (slackware 9.1)
(newlisp 8.2.0) ->

bash-2.05b$ newlisp
newLISP v.8.2.0 Copyright (c) 2004 Lutz Mueller. All rights reserved.

> (cpymem (pack "c c" 0 32) (last (dump 'pipe )) 2)
2
> (set 'pipe nil)
nil
> (delete 'pipe)
Segmentation fault

bash-2.05b$ newlisp
newLISP v.8.2.0 Copyright (c) 2004 Lutz Mueller. All rights reserved.

> (cpymem (pack "c c" 0 32) (last (dump 'print )) 2)
2
> (set 'print nil)
nil
> (delete 'print)
Segmentation fault
bash-2.05b$
-- (define? (Cornflakes))

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

Post by Lutz »

I guess it depends on how data-, static- and code segments are organized on different OS's and compilers. My tests where on Win32/MinGW and FreeBSD/GCC, where it seemed to work fine. It probably happens when newLISP is trying to free/access memory for the symbol name, when deleting the symbol of a built-in.

If it crashes your machine, then don't do it :-). This is why this example is in the 'hacking newLISP' section. It should be safe though on all other (non-buit-in) symbols.

What is this all about anyway? Tell us more about what you want to do. Perhaps there is a different approach to make it work.

Lutz

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

Post by newdep »

Hello Lutz,

Im trying to create from the current newlisp version a "shell" like replacement
for i.e. Bash/Ksh/csh.... Not all the file/net-io should be usable but must be
configurable per users...Thats why i want to emleminate some functions during
startup of newlisp... Its still expirimental but it would be nice if i could get
newlisp to replace bash on some shell parts...

Regards, Norman.
-- (define? (Cornflakes))

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

Post by Lutz »

You could just redefine the built-in to some default message:

Code: Select all

(define (default-message)  (silent (println "Not a valid command!")))

(constant 'pipe default-message)

(pipe)
Not a valid command!
The 'silent' avoids that you see the return value from the function, which again would be the message, but quoted.

Becuase you are using 'constant' to redefine the built-in you don't need the 'cpymem' trick at all, (constant 'pipe ...) alone will do it.

Lutz

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

Post by newdep »

Mmmm yes, instead of deleting it ill link it to the function...
Nice workaround ;-) Thanks..
-- (define? (Cornflakes))

Locked