[macruby-changes] [1416] MacRuby/branches/experimental/parse.y
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 13 14:04:12 PDT 2009
Revision: 1416
http://trac.macosforge.org/projects/ruby/changeset/1416
Author: lsansonetti at apple.com
Date: 2009-04-13 14:04:12 -0700 (Mon, 13 Apr 2009)
Log Message:
-----------
use the previous parsing code path in case the IO object we are using does not seem to be a regular file
Modified Paths:
--------------
MacRuby/branches/experimental/parse.y
Modified: MacRuby/branches/experimental/parse.y
===================================================================
--- MacRuby/branches/experimental/parse.y 2009-04-13 20:25:07 UTC (rev 1415)
+++ MacRuby/branches/experimental/parse.y 2009-04-13 21:04:12 UTC (rev 1416)
@@ -5122,7 +5122,7 @@
};
static VALUE
-lex_io_gets(struct parser_params *parser, VALUE udata)
+lex_io_gets_fast(struct parser_params *parser, VALUE udata)
{
struct lex_io_gets_data *data = (struct lex_io_gets_data *)udata;
@@ -5149,6 +5149,12 @@
return (VALUE)v;
}
+static VALUE
+lex_io_gets(struct parser_params *parser, VALUE io)
+{
+ return rb_io_gets(io, 0);
+}
+
NODE*
rb_compile_file(const char *f, VALUE file, int start)
{
@@ -5166,31 +5172,38 @@
struct parser_params *parser;
volatile VALUE tmp;
NODE *node;
+ UInt8 *buf = NULL;
+ struct lex_io_gets_data data;
Data_Get_Struct(vparser, struct parser_params, parser);
size_t buflen = rb_io_file_size(file);
if (buflen == 0) {
- return NULL;
+ // may be a pipe or something, use the less-efficient code path.
+ lex_gets = lex_io_gets;
+ lex_input = file;
}
- // TODO use mmap() if the file is too big
- UInt8 *buf = (UInt8 *)xmalloc(buflen);
- if (!rb_io_read_all_file(file, buf, buflen)) {
- return NULL;
+ else {
+ // TODO use mmap() if the file is too big
+ buf = (UInt8 *)xmalloc(buflen);
+ if (!rb_io_read_all_file(file, buf, buflen)) {
+ return NULL;
+ }
+
+ data.buf = buf;
+ data.buflen = buflen;
+
+ lex_gets = lex_io_gets_fast;
+ lex_input = (VALUE)&data;
}
- struct lex_io_gets_data data;
- data.buf = buf;
- data.buflen = buflen;
-
- lex_gets = lex_io_gets;
- lex_input = (VALUE)&data;
lex_pbeg = lex_p = lex_pend = 0;
-
node = yycompile(parser, f, start);
tmp = vparser; /* prohibit tail call optimization */
- xfree(buf);
+ if (buf != NULL) {
+ xfree(buf);
+ }
return node;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090413/7d8bdf76/attachment.html>
More information about the macruby-changes
mailing list