This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Safe Guile?


knotwell suggested using `undefine', which i think is going to be
necessary.  there are two steps: choosing "dangerous" things to undefine
(like `define'); and then adding back sufficient things to be useful
(like a custom `define' that does checks).  if you can rework baselevel
"builder" code to use the new define, that would be best.

to be more concrete... look in boot-9.scm for the construction of the
module system (i'm assuming you will eventually turn in this direction).
if you still have hair left and are not deafened by your own shrieking
insanity, you will notice `the-root-module' and `the-scm-module'.  a fun
thing to do is to start guile and try:

  guile> (module-obarray the-root-module)
  guile> (module-obarray the-scm-module)

you will need to construct `the-player-module' in whose obarray are most
but not all of the variables from these modules' obarrays.  then when
you create new modules per player, add `the-player-module' to their "use
lists", but NOT the above two.  this effectively means you cannot use
`define-module' directly, although probably much of its implementation
is what you want for `define-player-module'.

confused!?  no worries, pretty soon you too will be reduced to babbling
likewise to horrified newbies [sounds of brain frying...]

in any case, it's probably a good idea to avoid having data hanging
around to be munged by a player's inconsiderate `set!'; they should be
protected by access procedures.  see below for the monstrous `defvar'
used in THUD, for example...

good luck!
thi



---------------------
(defmacro defvar (name init docstring . override-setter-body)
  (let ((setter (symbol-append 'set-        name '!))
	(getter (symbol-append 'get-        name))
	(wrline (symbol-append 'write-line- name))
	(sbody  (if (not (eq? '() override-setter-body))
		    (car override-setter-body)
		    `(lambda (val)
		       ,(string-append
			 "Set `" (symbol->string name) "' to VAL.\n"
			 docstring)
		       (set! ,name val)))))
    `(begin
       ;; init
       (define ,name ,init)
       ;; setter
       (define ,setter ,sbody)
       ;; getter
       (define ,getter (lambda ()
			 ,(string-append
			   "Return value of `" (symbol->string name) "'.\n"
			   docstring)
			 ,name))
       ;; write-line
       (define ,wrline (lambda ()
			 ,(string-append
			   "Display value of `" (symbol->string name) "'.\n"
			   docstring
			   "\nUse `" (symbol->string getter) "' to get the"
			   " value without display.")
			 (write-line ,name)))
       ;; export
       (export ,name ,setter ,getter ,wrline))))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]