tizen 2.3.1 release
[framework/uifw/embryo.git] / src / lib / embryo_amx.c
index 1462a54..192a685 100644 (file)
@@ -29,8 +29,8 @@
 #include <stdio.h>
 #include <string.h>
 
-#ifdef HAVE_EVIL
-# include <Evil.h>
+#ifdef HAVE_EXOTIC
+# include <Exotic.h>
 #endif
 
 #include "Embryo.h"
@@ -43,9 +43,9 @@
 static void _embryo_byte_swap_16 (unsigned short *v);
 static void _embryo_byte_swap_32 (unsigned int *v);
 #endif
-static int  _embryo_native_call  (Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result, Embryo_Cell *params);
-static int  _embryo_func_get     (Embryo_Program *ep, int index, char *funcname);
-static int  _embryo_var_get      (Embryo_Program *ep, int index, char *varname, Embryo_Cell *ep_addr);
+static int  _embryo_native_call  (Embryo_Program *ep, Embryo_Cell idx, Embryo_Cell *result, Embryo_Cell *params);
+static int  _embryo_func_get     (Embryo_Program *ep, int idx, char *funcname);
+static int  _embryo_var_get      (Embryo_Program *ep, int idx, char *varname, Embryo_Cell *ep_addr);
 static int  _embryo_program_init (Embryo_Program *ep, void *code);
 
 #ifdef WORDS_BIGENDIAN
@@ -70,14 +70,14 @@ _embryo_byte_swap_32(unsigned int *v)
 #endif
 
 static int
-_embryo_native_call(Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result, Embryo_Cell *params)
+_embryo_native_call(Embryo_Program *ep, Embryo_Cell idx, Embryo_Cell *result, Embryo_Cell *params)
 {
    Embryo_Header    *hdr;
    Embryo_Func_Stub *func_entry;
    Embryo_Native     f;
 
    hdr = (Embryo_Header *)ep->base;
-   func_entry = GETENTRY(hdr, natives, index);
+   func_entry = GETENTRY(hdr, natives, idx);
    if ((func_entry->address <= 0) ||
        (func_entry->address > ep->native_calls_size))
      {
@@ -96,32 +96,32 @@ _embryo_native_call(Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result,
 }
 
 static int
-_embryo_func_get(Embryo_Program *ep, int index, char *funcname)
+_embryo_func_get(Embryo_Program *ep, int idx, char *funcname)
 {
    Embryo_Header    *hdr;
    Embryo_Func_Stub *func;
 
    hdr = (Embryo_Header *)ep->code;
-   if (index >= (Embryo_Cell)NUMENTRIES(hdr, publics, natives))
+   if (idx >= (Embryo_Cell)NUMENTRIES(hdr, publics, natives))
      return EMBRYO_ERROR_INDEX;
 
-   func = GETENTRY(hdr, publics, index);
+   func = GETENTRY(hdr, publics, idx);
    strcpy(funcname, GETENTRYNAME(hdr, func));
    return EMBRYO_ERROR_NONE;
 }
 
 static int
-_embryo_var_get(Embryo_Program *ep, int index, char *varname, Embryo_Cell *ep_addr)
+_embryo_var_get(Embryo_Program *ep, int idx, char *varname, Embryo_Cell *ep_addr)
 {
 
   Embryo_Header    *hdr;
   Embryo_Func_Stub *var;
 
   hdr=(Embryo_Header *)ep->base;
-  if (index >= (Embryo_Cell)NUMENTRIES(hdr, pubvars, tags))
+  if (idx >= (Embryo_Cell)NUMENTRIES(hdr, pubvars, tags))
      return EMBRYO_ERROR_INDEX;
 
-  var = GETENTRY(hdr, pubvars, index);
+  var = GETENTRY(hdr, pubvars, idx);
   strcpy(varname, GETENTRYNAME(hdr, var));
   *ep_addr = var->address;
   return EMBRYO_ERROR_NONE;
@@ -205,6 +205,8 @@ _embryo_program_init(Embryo_Program *ep, void *code)
 #endif
    ep->flags = EMBRYO_FLAG_RELOC;
 
+#ifdef WORDS_BIGENDIAN
+/* until we do more... this is only used for bigendian */
      {
        Embryo_Cell cip, code_size, cip_end;
        Embryo_Cell *code;
@@ -220,9 +222,10 @@ _embryo_program_init(Embryo_Program *ep, void *code)
 #ifdef WORDS_BIGENDIAN
             embryo_swap_32(&(code[cip]));
 #endif
-
          }
      }
+#endif
+
    /* init native api for handling floating point - default in embryo */
    _embryo_args_init(ep);
    _embryo_fp_init(ep);
@@ -290,7 +293,7 @@ embryo_program_load(const char *file)
    if (!f) return NULL;
    fseek(f, 0, SEEK_END);
    program_size = ftell(f);
-   rewind(f);
+   fseek(f, 0L, SEEK_SET);
    if (program_size < (int)sizeof(Embryo_Header))
      {
        fclose(f);
@@ -301,7 +304,7 @@ embryo_program_load(const char *file)
        fclose(f);
        return NULL;
      }
-   rewind(f);
+   fseek(f, 0L, SEEK_SET);
 #ifdef WORDS_BIGENDIAN
    embryo_swap_32((unsigned int *)(&hdr.size));
 #endif
@@ -427,7 +430,7 @@ embryo_program_vm_push(Embryo_Program *ep)
        return;
      }
    hdr = (Embryo_Header *)ep->code;
-   ep->base = malloc(hdr->stp);
+   ep->base = calloc(1, hdr->stp);
    if (!ep->base)
      {
        ep->pushes = 0;