aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-25 15:47:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-25 15:47:08 -0300
commit682efe2678589eebc7c982e0ed66ad4990711e5a (patch)
treeaacc25a8ea053959bc457c92b0ef82730cf5370e
parent50c7c915ee2fa239043d5456237f5145d064089b (diff)
downloadlua-682efe2678589eebc7c982e0ed66ad4990711e5a.tar.gz
lua-682efe2678589eebc7c982e0ed66ad4990711e5a.tar.bz2
lua-682efe2678589eebc7c982e0ed66ad4990711e5a.zip
Change to macro 'LUAI_TRY'
The call to 'f' is done by the macro, to give it more flexibility.
-rw-r--r--ldo.c14
-rw-r--r--testes/files.lua1
2 files changed, 7 insertions, 8 deletions
diff --git a/ldo.c b/ldo.c
index cb7e5aef..9459391f 100644
--- a/ldo.c
+++ b/ldo.c
@@ -69,22 +69,22 @@
69 69
70/* C++ exceptions */ 70/* C++ exceptions */
71#define LUAI_THROW(L,c) throw(c) 71#define LUAI_THROW(L,c) throw(c)
72#define LUAI_TRY(L,c,a) \ 72#define LUAI_TRY(L,c,f,ud) \
73 try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; } 73 try { (f)(L, ud); } catch(...) { if ((c)->status == 0) (c)->status = -1; }
74#define luai_jmpbuf int /* dummy variable */ 74#define luai_jmpbuf int /* dummy field */
75 75
76#elif defined(LUA_USE_POSIX) /* }{ */ 76#elif defined(LUA_USE_POSIX) /* }{ */
77 77
78/* in POSIX, try _longjmp/_setjmp (more efficient) */ 78/* in POSIX, try _longjmp/_setjmp (more efficient) */
79#define LUAI_THROW(L,c) _longjmp((c)->b, 1) 79#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
80#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } 80#define LUAI_TRY(L,c,f,ud) if (_setjmp((c)->b) == 0) ((f)(L, ud))
81#define luai_jmpbuf jmp_buf 81#define luai_jmpbuf jmp_buf
82 82
83#else /* }{ */ 83#else /* }{ */
84 84
85/* ISO C handling with long jumps */ 85/* ISO C handling with long jumps */
86#define LUAI_THROW(L,c) longjmp((c)->b, 1) 86#define LUAI_THROW(L,c) longjmp((c)->b, 1)
87#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } 87#define LUAI_TRY(L,c,f,ud) if (setjmp((c)->b) == 0) ((f)(L, ud))
88#define luai_jmpbuf jmp_buf 88#define luai_jmpbuf jmp_buf
89 89
90#endif /* } */ 90#endif /* } */
@@ -154,9 +154,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
154 lj.status = LUA_OK; 154 lj.status = LUA_OK;
155 lj.previous = L->errorJmp; /* chain new error handler */ 155 lj.previous = L->errorJmp; /* chain new error handler */
156 L->errorJmp = &lj; 156 L->errorJmp = &lj;
157 LUAI_TRY(L, &lj, 157 LUAI_TRY(L, &lj, f, ud); /* call 'f' catching errors */
158 (*f)(L, ud);
159 );
160 L->errorJmp = lj.previous; /* restore old error handler */ 158 L->errorJmp = lj.previous; /* restore old error handler */
161 L->nCcalls = oldnCcalls; 159 L->nCcalls = oldnCcalls;
162 return lj.status; 160 return lj.status;
diff --git a/testes/files.lua b/testes/files.lua
index 4f925f50..9bdf04d0 100644
--- a/testes/files.lua
+++ b/testes/files.lua
@@ -766,6 +766,7 @@ if not _port then
766 assert((v[3] == nil and z > 0) or v[3] == z) 766 assert((v[3] == nil and z > 0) or v[3] == z)
767 end 767 end
768 end 768 end
769 print("(done)")
769end 770end
770 771
771 772