diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-11-25 15:47:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-11-25 15:47:08 -0300 |
commit | 682efe2678589eebc7c982e0ed66ad4990711e5a (patch) | |
tree | aacc25a8ea053959bc457c92b0ef82730cf5370e /ldo.c | |
parent | 50c7c915ee2fa239043d5456237f5145d064089b (diff) | |
download | lua-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.
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -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; |