(dump)

Started by newdep, October 04, 2004, 12:12:22 PM

Previous topic - Next topic

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

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

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

#3
Seems to be the hard way.



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

newdep

#4
Yes its an option that but the "disable"/"enable" function

must be dynamic configurable for the user (im my applicaiton)...
-- (define? (Cornflakes))

Lutz

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

newdep

#6
Haa... 'delete...!!! Did not even noticed that one ;-) thanks...

(Its all there ;-)
-- (define? (Cornflakes))

Lutz

#7
I just realize it may not work on builtin functions



Lutz

Lutz

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



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

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

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

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

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



(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

#13
Mmmm yes, instead of deleting it ill link it to the function...

Nice workaround ;-) Thanks..
-- (define? (Cornflakes))