newLISP Fan Club

Forum => newLISP in the real world => Topic started by: newdep on October 04, 2004, 12:12:22 PM

Title: (dump)
Post by: newdep on October 04, 2004, 12:12:22 PM
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.
Title:
Post by: HPW on October 04, 2004, 12:23:43 PM
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.
Title:
Post by: newdep on October 04, 2004, 12:28:29 PM
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.
Title:
Post by: HPW on October 04, 2004, 01:07:09 PM
Seems to be the hard way.



Why not compile your special newLISP with removed function?
Title:
Post by: newdep on October 04, 2004, 01:10:58 PM
Yes its an option that but the "disable"/"enable" function

must be dynamic configurable for the user (im my applicaiton)...
Title:
Post by: Lutz on October 04, 2004, 01:15:38 PM
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
Title:
Post by: newdep on October 04, 2004, 01:16:55 PM
Haa... 'delete...!!! Did not even noticed that one ;-) thanks...

(Its all there ;-)
Title:
Post by: Lutz on October 04, 2004, 01:22:49 PM
I just realize it may not work on builtin functions



Lutz
Title:
Post by: Lutz on October 04, 2004, 01:27:31 PM
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
Title:
Post by: newdep on October 04, 2004, 02:25:03 PM
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$
Title:
Post by: Lutz on October 04, 2004, 04:14:20 PM
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
Title:
Post by: newdep on October 05, 2004, 01:00:58 AM
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.
Title:
Post by: Lutz on October 05, 2004, 05:15:24 AM
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
Title:
Post by: newdep on October 05, 2004, 06:09:50 AM
Mmmm yes, instead of deleting it ill link it to the function...

Nice workaround ;-) Thanks..