Fixed rooting bug in Ke::Compile.
authorDavid Anderson <dvander@alliedmods.net>
Sun Aug 05 01:56:10 2012 -0700 (2012-08-05)
changeset 162c9fa93ce2f1f
parent 161 b3f0aaee735a
child 163 efc3f91dbe42
Fixed rooting bug in Ke::Compile.
src/API.cpp
src/main.cpp
     1.1 --- a/src/API.cpp	Sun Aug 05 01:45:37 2012 -0700
     1.2 +++ b/src/API.cpp	Sun Aug 05 01:56:10 2012 -0700
     1.3 @@ -126,8 +126,8 @@
     1.4      return module;
     1.5  }
     1.6  
     1.7 -Ke::Local<Ke::Module>
     1.8 -Ke::Compile(const char *path)
     1.9 +ke::Module *
    1.10 +InternalCompile(const char *path)
    1.11  {
    1.12      RootScope roots(ZONE());
    1.13      CompileContext cc(ZONE(), path);
    1.14 @@ -138,19 +138,19 @@
    1.15          FILE *fp = fopen(path, "rb");
    1.16          if (!fp) {
    1.17              cc.reportError(SourcePosition(), Message_CantOpenFile);
    1.18 -            return Ke::Local<Ke::Module>();
    1.19 +            return NULL;
    1.20          }
    1.21  
    1.22          if (fseek(fp, 0, SEEK_END)) {
    1.23              cc.reportError(SourcePosition(), Message_ErrorSeekingFile);
    1.24              fclose(fp);
    1.25 -            return Ke::Local<Ke::Module>();;
    1.26 +            return NULL;
    1.27          }
    1.28          long size = ftell(fp);
    1.29          if (size < 0) {
    1.30              cc.reportError(SourcePosition(), Message_ErrorSeekingFile);
    1.31              fclose(fp);
    1.32 -            return Ke::Local<Ke::Module>();;
    1.33 +            return NULL;
    1.34          }
    1.35          rewind(fp);
    1.36          length = size_t(size);
    1.37 @@ -159,7 +159,7 @@
    1.38              cc.reportError(SourcePosition(), Message_ErrorReadingFile);
    1.39              fclose(fp);
    1.40              delete [] bytes;
    1.41 -            return Ke::Local<Ke::Module>();;
    1.42 +            return NULL;
    1.43          }
    1.44          fclose(fp);
    1.45      }
    1.46 @@ -167,13 +167,22 @@
    1.47      ke::Local<ke::Module> module(ZONE(),  CompileFromSource(cc, path, bytes, length));
    1.48      delete [] bytes;
    1.49      if (!module)
    1.50 -        return Ke::Local<Ke::Module>();
    1.51 +        return NULL;
    1.52  
    1.53      ke::Local<ke::String> pathstr(ZONE(), ke::String::New(ZONE(), path, Heap::Tenure_Old));
    1.54      if (!pathstr)
    1.55 -        return Ke::Local<Ke::Module>();
    1.56 +        return NULL;
    1.57  
    1.58      module->setPath(pathstr);
    1.59 +    return module;
    1.60 +}
    1.61 +
    1.62 +// This is split out from InternalCompile so the RootScope doesn't conflict
    1.63 +// with making a return handle.
    1.64 +Ke::Local<Ke::Module>
    1.65 +Ke::Compile(const char *path)
    1.66 +{
    1.67 +    ke::Local<ke::Module> module(ZONE(), InternalCompile(path));
    1.68      return ToLocal<ke::Module, Ke::Module>(module);
    1.69  }
    1.70  
     2.1 --- a/src/main.cpp	Sun Aug 05 01:45:37 2012 -0700
     2.2 +++ b/src/main.cpp	Sun Aug 05 01:56:10 2012 -0700
     2.3 @@ -109,7 +109,7 @@
     2.4          if (!module)
     2.5              return 1;
     2.6  
     2.7 -	// Keima::CollectGarbage();
     2.8 +	Keima::CollectGarbage();
     2.9  
    2.10          //Local<Native> native = module->getNative(0);
    2.11          //native->bind(reinterpret_cast<void *>(PrintToServer));