I think I have a fix for Issue 34 (Disable EvalReader with a *read-
eval* flag). I added the *read-eval* variable and also created a
dispatch reader that sets the value at read time. Let me know any
comments.

Joshua



### Eclipse Workspace Patch 1.0
#P Clojure
Index: src/jvm/clojure/lang/RT.java
===================================================================
--- src/jvm/clojure/lang/RT.java        (revision 1326)
+++ src/jvm/clojure/lang/RT.java        (working copy)
@@ -178,6 +178,7 @@
                           new PrintWriter(new OutputStreamWriter(System.err,
UTF8), true));
 final static Keyword TAG_KEY = Keyword.intern(null, "tag");
 final static public Var AGENT = Var.intern(CLOJURE_NS, Symbol.create
("*agent*"), null);
+final static public Var READEVAL = Var.intern(CLOJURE_NS,
Symbol.create("*read-eval*"), T);
 final static public Var MACRO_META = Var.intern(CLOJURE_NS,
Symbol.create("*macro-meta*"), null);
 final static public Var MATH_CONTEXT = Var.intern(CLOJURE_NS,
Symbol.create("*math-context*"), null);
 static Keyword LINE_KEY = Keyword.intern(null, "line");
Index: src/jvm/clojure/lang/LispReader.java
===================================================================
--- src/jvm/clojure/lang/LispReader.java        (revision 1326)
+++ src/jvm/clojure/lang/LispReader.java        (working copy)
@@ -89,6 +89,7 @@
        dispatchMacros['('] = new FnReader();
        dispatchMacros['{'] = new SetReader();
        dispatchMacros['='] = new EvalReader();
+       dispatchMacros['r'] = new EvalDisabledReader();
        dispatchMacros['!'] = new CommentReader();
        dispatchMacros['<'] = new UnreadableReader();
        dispatchMacros['_'] = new DiscardReader();
@@ -901,8 +902,31 @@

 }

+public static class EvalDisabledReader extends AFn{
+       public Object invoke(Object reader, Object eq) throws Exception{
+               PushbackReader r = (PushbackReader) reader;
+               try
+                       {
+                       Var.pushThreadBindings(
+                                       RT.map(RT.READEVAL, RT.F));
+
+                       Object form = read(r, true, null, true);
+                       return form;
+                       }
+               finally
+                       {
+                       Var.popThreadBindings();
+                       }
+       }
+}
+
 public static class EvalReader extends AFn{
        public Object invoke(Object reader, Object eq) throws Exception{
+               if (!((Boolean)RT.READEVAL.get()))
+           {
+                 throw new Exception("EvalReader not allowed when *read-eval* 
is
false.");
+           }
+
                PushbackReader r = (PushbackReader) reader;
                Object o = read(r, true, null, true);
                if(o instanceof Symbol)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to