Jacek Caban : jscript: Always alloc the first chunk of code buffer.

Alexandre Julliard julliard at winehq.org
Tue Jan 3 12:52:52 CST 2012


Module: wine
Branch: master
Commit: 11453b2414a3cde94887afa56fe6e26ca4f13027
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=11453b2414a3cde94887afa56fe6e26ca4f13027

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Jan  2 11:45:54 2012 +0100

jscript: Always alloc the first chunk of code buffer.

---

 dlls/jscript/compile.c |   43 ++++++++++++++++++++++++++-----------------
 1 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 60b0c2e..268c3b0 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -150,12 +150,7 @@ static unsigned push_instr(compiler_ctx_t *ctx, jsop_t op)
 {
     assert(ctx->code_size >= ctx->code_off);
 
-    if(!ctx->code_size) {
-        ctx->code->instrs = heap_alloc(64 * sizeof(instr_t));
-        if(!ctx->code->instrs)
-            return -1;
-        ctx->code_size = 64;
-    }else if(ctx->code_size == ctx->code_off) {
+    if(ctx->code_size == ctx->code_off) {
         instr_t *new_instrs;
 
         new_instrs = heap_realloc(ctx->code->instrs, ctx->code_size*2*sizeof(instr_t));
@@ -1647,22 +1642,36 @@ void release_compiler(compiler_ctx_t *ctx)
 
 static HRESULT init_compiler(parser_ctx_t *parser)
 {
-    if(!parser->code) {
-        parser->code = heap_alloc_zero(sizeof(bytecode_t));
-        if(!parser->code)
-            return E_OUTOFMEMORY;
-        jsheap_init(&parser->code->heap);
+    compiler_ctx_t *compiler;
+
+    if(parser->compiler)
+        return S_OK;
+
+    compiler = heap_alloc_zero(sizeof(*compiler));
+    if(!compiler)
+        return E_OUTOFMEMORY;
+
+    compiler->code = heap_alloc_zero(sizeof(bytecode_t));
+    if(!compiler->code) {
+        release_compiler(compiler);
+        return E_OUTOFMEMORY;
     }
 
-    if(!parser->compiler) {
-        parser->compiler = heap_alloc_zero(sizeof(compiler_ctx_t));
-        if(!parser->compiler)
-            return E_OUTOFMEMORY;
+    jsheap_init(&compiler->code->heap);
 
-        parser->compiler->parser = parser;
-        parser->compiler->code = parser->code;
+    compiler->code->instrs = heap_alloc(64 * sizeof(instr_t));
+    if(!compiler->code->instrs) {
+        release_bytecode(compiler->code);
+        release_compiler(compiler);
+        return E_OUTOFMEMORY;
     }
 
+    compiler->code_size = 64;
+
+    compiler->parser = parser;
+
+    parser->code = compiler->code;
+    parser->compiler = compiler;
     return S_OK;
 }
 




More information about the wine-cvs mailing list