On Tue, Jul 5, 2011 at 11:22 AM, Patrick Houk <path...@gmail.com> wrote:
> Does the file you are evaluating have more than 65535 characters?  As
> far as I can tell, that is the maximum length of a String literal in
> Java (see the CONSTANT_Utf8_info struct in
> http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html).
> I've encountered that limit when using Eclipse/CounterClockwise.  The
> problem occurs when evaluating a file by doing something like:
>
> (clojure.lang.Compiler/load (java.io.StringReader. "the-whole-file-as-
> a-string"))
>
> So the contents of the file ends up as a String literal, and Clojure
> will generate a corrupt class if that String is too long.
> CounterClockwise calls a function in nREPL (helpers/load-file-command)
> that does this.  Perhaps Emacs/Slime is doing something similar.

Smells like multiple bugs to me.

1. A too-large string literal should have a specific error message,
rather than generate a misleading one suggesting a different type of
problem.

2. The limit should not be different from that on String objects in
general, namely 2147483647 characters which nobody is likely to hit
unless they mistakenly call read-string on that 1080p Avatar blu-ray
rip .mkv they aren't legally supposed to possess.

3. Though both of the above bugs are in Oracle's Java implementation,
it would seem to be a bug in Clojure's compiler if it is trying to
make the entire source code of a namespace into a string *literal* in
dynamically-generated bytecode somewhere rather than a string
*object*. Sensible alternatives are a) get the string to whatever
consumes it by some other means than embedding it as a single
monolithic constant in bytecode, b) convert long strings into shorter
chunks and emit a static initializer into the bytecode to reassemble
them with concatenation into a single runtime-computed string constant
stored in another static field, and c) restructure whatever consumes
the string to consume a seq, java.util.List, or whatever of strings
instead and feed it digestible chunks (e.g. a separate string for each
defn or other top-level form, in order of appearance in the input file
-- surely nobody has *individual defns* exceeding 64KB).

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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