aawwaaa

Untitled

Aug 5th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 12.41 KB | None | 0 0
  1. diff --git a/src/eris.c b/src/eris.c
  2. index f217567..f5489d7 100644
  3. --- a/src/eris.c
  4. +++ b/src/eris.c
  5. @@ -109,7 +109,7 @@ static const lua_Unsigned kMaxComplexity = 10000;
  6.   * patched Lua version to be able to persist some of the library functions,
  7.   * anyway: it needs to put the continuation C functions in the perms table. */
  8.  /* ldebug.h */
  9. -#define eris_ci_func(ci)       (clLvalue(s2v((ci)->func)))
  10. +#define eris_ci_func(ci)       (clLvalue(s2v((ci)->func.p)))
  11.  /* ldo.h */
  12.  #define eris_savestack savestack
  13.  #define eris_restorestack restorestack
  14. @@ -147,8 +147,8 @@ static const lua_Unsigned kMaxComplexity = 10000;
  15.  /* These are required for cross-platform support, since the size of TValue may
  16.   * differ, so the byte offset used by savestack/restorestack in Lua it is not a
  17.   * valid measure. */
  18. -#define eris_savestackidx(L, p) ((p) - (L)->stack)
  19. -#define eris_restorestackidx(L, n) ((L)->stack + (n))
  20. +#define eris_savestackidx(L, ptr) ((ptr) - (L)->stack.p)
  21. +#define eris_restorestackidx(L, n) ((L)->stack.p + (n))
  22.  
  23.  /* Enabled if we have a patched version of Lua (for accessing internals). */
  24.  #if 1
  25. @@ -347,7 +347,7 @@ registerobject(Info *info) {                          /* perms reftbl ... obj */
  26.  static void
  27.  pushtstring(lua_State* L, TString *ts) {                               /* ... */
  28.    if (ts) {
  29. -    eris_setsvalue2n(L, L->top, ts);
  30. +    eris_setsvalue2n(L, &(L->top.p)->val, ts);
  31.      api_incr_top(L);                                              /* ... str */
  32.    }
  33.    else {
  34. @@ -1231,7 +1231,7 @@ p_proto(Info *info) {                                            /* ... proto */
  35.    pushpath(info, ".constants");
  36.    for (i = 0; i < p->sizek; ++i) {
  37.      pushpath(info, "[%d]", i);
  38. -    eris_setobj(info->L, info->L->top++, &p->k[i]);      /* ... lcl proto obj */
  39. +    eris_setobj(info->L, &(info->L->top.p++)->val, &p->k[i]);      /* ... lcl proto obj */
  40.      persist(info);                                       /* ... lcl proto obj */
  41.      lua_pop(info->L, 1);                                     /* ... lcl proto */
  42.      poppath(info);
  43. @@ -1345,7 +1345,7 @@ u_proto(Info *info) {                                            /* ... proto */
  44.    for (i = 0, n = p->sizek; i < n; ++i) {
  45.      pushpath(info, "[%d]", i);
  46.      unpersist(info);                                         /* ... proto obj */
  47. -    eris_setobj(info->L, &p->k[i], info->L->top - 1);
  48. +    eris_setobj(info->L, &p->k[i], &(info->L->top.p - 1)->val);
  49.      lua_pop(info->L, 1);                                         /* ... proto */
  50.      poppath(info);
  51.    }
  52. @@ -1483,13 +1483,13 @@ static void
  53.  p_closure(Info *info) {                              /* perms reftbl ... func */
  54.    int nup;
  55.    eris_checkstack(info->L, 2);
  56. -  switch (eris_ttypetag(s2v(info->L->top - 1))) {
  57. +  switch (eris_ttypetag(s2v(info->L->top.p - 1))) {
  58.      case LUA_VLCF: /* light C function */
  59.        /* We cannot persist these, they have to be handled via the permtable. */
  60.        eris_error(info, ERIS_ERR_CFUNC, lua_tocfunction(info->L, -1));
  61.        return; /* not reached */
  62.      case LUA_VCCL: /* C closure */ {                  /* perms reftbl ... ccl */
  63. -      CClosure *cl = clCvalue(s2v(info->L->top - 1));
  64. +      CClosure *cl = clCvalue(s2v(info->L->top.p - 1));
  65.        /* Mark it as a C closure. */
  66.        WRITE_VALUE(true, uint8_t);
  67.        /* Write the upvalue count first, since we have to know it when creating
  68. @@ -1518,7 +1518,7 @@ p_closure(Info *info) {                              /* perms reftbl ... func */
  69.        break;
  70.      }
  71.      case LUA_VLCL: /* Lua function */ {               /* perms reftbl ... lcl */
  72. -      LClosure *cl = eris_clLvalue(s2v(info->L->top - 1));
  73. +      LClosure *cl = eris_clLvalue(s2v(info->L->top.p - 1));
  74.        /* Mark it as a Lua closure. */
  75.        WRITE_VALUE(false, uint8_t);
  76.        /* Write the upvalue count first, since we have to know it when creating
  77. @@ -1613,7 +1613,7 @@ u_closure(Info *info) {                                                /* ... */
  78.  
  79.      /* Create closure and anchor it on the stack (avoid collection via GC). */
  80.      cl = eris_newLclosure(info->L, nups);
  81. -    eris_setclLvalue(info->L, info->L->top, cl);                   /* ... lcl */
  82. +    eris_setclLvalue(info->L, &(info->L->top.p)->val, cl);                   /* ... lcl */
  83.      api_incr_top(info->L);
  84.  
  85.      /* Preregister closure for handling of cycles (upvalues). */
  86. @@ -1683,7 +1683,7 @@ u_closure(Info *info) {                                                /* ... */
  87.           * even if we re-used one - if we had a cycle, it might have been
  88.           * incorrectly initialized to nil before (or rather, not yet set). */
  89.          lua_rawgeti(info->L, -1, UVTVAL);                  /* ... lcl tbl obj */
  90. -        eris_setobj(info->L, &(*uv)->u.value, info->L->top - 1);
  91. +        eris_setobj(info->L, &(*uv)->u.value, &(info->L->top.p - 1)->val);
  92.          lua_pop(info->L, 1);                                   /* ... lcl tbl */
  93.  
  94.          lua_pushinteger(info->L, nup);                     /* ... lcl tbl nup */
  95. @@ -1733,7 +1733,7 @@ u_closure(Info *info) {                                                /* ... */
  96.  static void
  97.  p_thread(Info *info) {                                          /* ... thread */
  98.    lua_State* thread = lua_tothread(info->L, -1);
  99. -  size_t level = 0, total = thread->top - thread->stack;
  100. +  size_t level = 0, total = thread->top.p - thread->stack.p;
  101.    CallInfo *ci;
  102.    UpVal *uv;
  103.  
  104. @@ -1763,7 +1763,7 @@ p_thread(Info *info) {                                          /* ... thread */
  105.     */
  106.    for (; level < total; ++level) {
  107.      pushpath(info, "[%d]", level);
  108. -    eris_setobj(info->L, info->L->top - 1, thread->stack + level);
  109. +    eris_setobj(info->L, &(info->L->top.p - 1)->val, &(thread->stack.p + level)->val);
  110.                                                              /* ... thread obj */
  111.      persist(info);                                          /* ... thread obj */
  112.      poppath(info);
  113. @@ -1809,8 +1809,8 @@ p_thread(Info *info) {                                          /* ... thread */
  114.    eris_assert(&thread->base_ci != thread->ci->next);
  115.    for (ci = &thread->base_ci; ci != thread->ci->next; ci = ci->next) {
  116.      pushpath(info, "[%d]", level++);
  117. -    WRITE_VALUE(eris_savestackidx(thread, ci->func), size_t);
  118. -    WRITE_VALUE(eris_savestackidx(thread, ci->top), size_t);
  119. +    WRITE_VALUE(eris_savestackidx(thread, ci->func.p), size_t);
  120. +    WRITE_VALUE(eris_savestackidx(thread, ci->top.p), size_t);
  121.      WRITE_VALUE(ci->nresults, int16_t);
  122.      WRITE_VALUE(ci->callstatus, uint8_t);
  123.  
  124. @@ -1872,8 +1872,8 @@ p_thread(Info *info) {                                          /* ... thread */
  125.    {
  126.      pushpath(info, "[%d]", level++);
  127.      // TODO Lua 5.4 is the StkId cast correct?
  128. -    WRITE_VALUE(eris_savestackidx(thread, ((StkId) uv->v)) + 1, size_t);
  129. -    eris_setobj(info->L, info->L->top - 1, uv->v);          /* ... thread obj */
  130. +    WRITE_VALUE(eris_savestackidx(thread, ((StkId) uv->v.p)) + 1, size_t);
  131. +    eris_setobj(info->L, &(info->L->top.p - 1)->val, uv->v.p);          /* ... thread obj */
  132.      lua_pushlightuserdata(info->L, uv);                  /* ... thread obj id */
  133.      persist_keyed(info, LUA_TUPVAL);                        /* ... thread obj */
  134.      poppath(info);
  135. @@ -1885,8 +1885,8 @@ p_thread(Info *info) {                                          /* ... thread */
  136.  
  137.  /* Used in u_thread to validate read stack positions. */
  138.  #define validate(stackpos, inclmax) \
  139. -  if ((stackpos) < thread->stack || stackpos > (inclmax)) { \
  140. -    (stackpos) = thread->stack; \
  141. +  if ((stackpos) < thread->stack.p || stackpos > (inclmax)) { \
  142. +    (stackpos) = thread->stack.p; \
  143.      eris_error(info, ERIS_ERR_STACKBOUNDS); }
  144.  
  145.  /* I had so hoped to get by without any 'hacks', but I surrender. We mark the
  146. @@ -1898,8 +1898,8 @@ p_thread(Info *info) {                                          /* ... thread */
  147.   * inbetween requires the stack field to be valid), but I prefer to keep the
  148.   * "invalid" blocks as small as possible to make it clearer. Also, locking and
  149.   * unlocking are really just variable assignments, so they're really cheap. */
  150. -#define LOCK(L) (L->stack = NULL)
  151. -#define UNLOCK(L) (L->stack = stack)
  152. +#define LOCK(L) (L->stack.p = NULL)
  153. +#define UNLOCK(L) (L->stack.p = stack)
  154.  
  155.  static void
  156.  u_thread(Info *info) {                                                 /* ... */
  157. @@ -1914,21 +1914,21 @@ u_thread(Info *info) {                                                 /* ... */
  158.  
  159.    /* Unpersist the stack. Read size first and adjust accordingly. */
  160.    eris_reallocstack(thread, READ_VALUE(int), true);
  161. -  stack = thread->stack; /* After the realloc in case the address changes. */
  162. -  thread->top = thread->stack + READ_VALUE(size_t);
  163. -  validate(thread->top, thread->stack_last);
  164. +  stack = thread->stack.p; /* After the realloc in case the address changes. */
  165. +  thread->top.p = thread->stack.p + READ_VALUE(size_t);
  166. +  validate(thread->top.p, thread->stack_last.p);
  167.  
  168.    /* Read the elements one by one. */
  169.    LOCK(thread);
  170.    pushpath(info, ".stack");
  171.    UNLOCK(thread);
  172.    level = 0;
  173. -  for (o = stack; o < thread->top; ++o) {
  174. +  for (o = stack; o < thread->top.p; ++o) {
  175.      LOCK(thread);
  176.      pushpath(info, "[%d]", level++);
  177.      unpersist(info);                                        /* ... thread obj */
  178.      UNLOCK(thread);
  179. -    eris_setobj(thread, o, info->L->top - 1);
  180. +    eris_setobj(thread, &(o->val), &(info->L->top.p - 1)->val);
  181.      lua_pop(info->L, 1);                                        /* ... thread */
  182.      LOCK(thread);
  183.      poppath(info);
  184. @@ -1945,7 +1945,7 @@ u_thread(Info *info) {                                                 /* ... */
  185.    eris_assert(thread->hook == NULL);
  186.  
  187.    /* See comment in persist. */
  188. -  thread->oldpc = NULL;
  189. +  thread->oldpc = (int)NULL;
  190.  
  191.    /* Read general information. */
  192.    thread->status = READ_VALUE(uint8_t);
  193. @@ -1953,7 +1953,7 @@ u_thread(Info *info) {                                                 /* ... */
  194.      eris_restorestackidx(thread, READ_VALUE(size_t)));
  195.    if (thread->errfunc) {
  196.      o = eris_restorestack(thread, thread->errfunc);
  197. -    validate(o, thread->top);
  198. +    validate(o, thread->top.p);
  199.      if (eris_ttype(s2v(o)) != LUA_TFUNCTION) {
  200.        eris_error(info, ERIS_ERR_THREADERRF);
  201.      }
  202. @@ -1978,10 +1978,10 @@ u_thread(Info *info) {                                                 /* ... */
  203.      LOCK(thread);
  204.      pushpath(info, "[%d]", level++);
  205.      UNLOCK(thread);
  206. -    thread->ci->func = eris_restorestackidx(thread, READ_VALUE(size_t));
  207. -    validate(thread->ci->func, thread->top - 1);
  208. -    thread->ci->top = eris_restorestackidx(thread, READ_VALUE(size_t));
  209. -    validate(thread->ci->top, thread->stack_last);
  210. +    thread->ci->func.p = eris_restorestackidx(thread, READ_VALUE(size_t));
  211. +    validate(thread->ci->func.p, thread->top.p - 1);
  212. +    thread->ci->top.p = eris_restorestackidx(thread, READ_VALUE(size_t));
  213. +    validate(thread->ci->top.p, thread->stack_last.p);
  214.      thread->ci->nresults = READ_VALUE(int16_t);
  215.      thread->ci->callstatus = READ_VALUE(uint8_t);
  216.  
  217. @@ -1990,7 +1990,7 @@ u_thread(Info *info) {                                                 /* ... */
  218.        thread->ci->u2.funcidx = eris_savestack(thread,
  219.          eris_restorestackidx(thread, READ_VALUE(int)));
  220.        o = eris_restorestack(thread, thread->ci->u2.funcidx);
  221. -      validate(o, thread->top);
  222. +      validate(o, thread->top.p);
  223.        if (eris_ttype(s2v(o)) != LUA_TFUNCTION) {
  224.          eris_error(info, ERIS_ERR_THREADCI);
  225.        }
  226. @@ -2083,7 +2083,7 @@ u_thread(Info *info) {                                                 /* ... */
  227.      pushpath(info, "[%d]", level);
  228.      UNLOCK(thread);
  229.      stk = eris_restorestackidx(thread, offset - 1);
  230. -    validate(stk, thread->top - 1);
  231. +    validate(stk, thread->top.p - 1);
  232.      LOCK(thread);
  233.      unpersist(info);                                        /* ... thread tbl */
  234.      UNLOCK(thread);
  235. @@ -2107,7 +2107,7 @@ u_thread(Info *info) {                                                 /* ... */
  236.          LClosure *cl;
  237.          int nup;
  238.          lua_rawgeti(info->L, -1, i);                    /* ... thread tbl lcl */
  239. -        cl = eris_clLvalue(s2v(info->L->top - 1));
  240. +        cl = eris_clLvalue(s2v(info->L->top.p - 1));
  241.          lua_pop(info->L, 1);                                /* ... thread tbl */
  242.          lua_rawgeti(info->L, -1, i + 1);                /* ... thread tbl nup */
  243.          nup = lua_tointeger(info->L, -1);
  244.  
Advertisement
Add Comment
Please, Sign In to add comment