diff -r b3f0aaee735a -r c9fa93ce2f1f src/API.cpp --- a/src/API.cpp Sun Aug 05 01:45:37 2012 -0700 +++ b/src/API.cpp Sun Aug 05 01:56:10 2012 -0700 @@ -126,8 +126,8 @@ return module; } -Ke::Local -Ke::Compile(const char *path) +ke::Module * +InternalCompile(const char *path) { RootScope roots(ZONE()); CompileContext cc(ZONE(), path); @@ -138,19 +138,19 @@ FILE *fp = fopen(path, "rb"); if (!fp) { cc.reportError(SourcePosition(), Message_CantOpenFile); - return Ke::Local(); + return NULL; } if (fseek(fp, 0, SEEK_END)) { cc.reportError(SourcePosition(), Message_ErrorSeekingFile); fclose(fp); - return Ke::Local();; + return NULL; } long size = ftell(fp); if (size < 0) { cc.reportError(SourcePosition(), Message_ErrorSeekingFile); fclose(fp); - return Ke::Local();; + return NULL; } rewind(fp); length = size_t(size); @@ -159,7 +159,7 @@ cc.reportError(SourcePosition(), Message_ErrorReadingFile); fclose(fp); delete [] bytes; - return Ke::Local();; + return NULL; } fclose(fp); } @@ -167,13 +167,22 @@ ke::Local module(ZONE(), CompileFromSource(cc, path, bytes, length)); delete [] bytes; if (!module) - return Ke::Local(); + return NULL; ke::Local pathstr(ZONE(), ke::String::New(ZONE(), path, Heap::Tenure_Old)); if (!pathstr) - return Ke::Local(); + return NULL; module->setPath(pathstr); + return module; +} + +// This is split out from InternalCompile so the RootScope doesn't conflict +// with making a return handle. +Ke::Local +Ke::Compile(const char *path) +{ + ke::Local module(ZONE(), InternalCompile(path)); return ToLocal(module); }