Commit 04ac810
fix(metacall): implement metacall_error_last/clear with thread-local store
metacall_error_last() and metacall_error_clear() were stubs that returned
1 and did nothing. Any caller that checked the last error after a failed
metacall received no information, making the published API unusable.
Implement a thread-local value* (metacall_error_last_v) in metacall_error.c
using the PORTABILITY_THREAD_LOCAL macro so the per-thread last-error slot
works on GCC/Clang (__thread) and MSVC (__declspec(thread)) without changes
to the calling code.
metacall_error_last() now delegates to metacall_error_from_value() on the
stored copy. metacall_error_clear() destroys the stored value and resets
the slot. metacall_error_set_last() is the new internal entry point that
saves a deep copy (via value_type_copy, which increments the exception
reference count) so the caller retains ownership of the original.
In metacallfv_s, after function_call returns, detect TYPE_THROWABLE via
type_id_throwable() and call metacall_error_set_last(). This covers the
common call path reached by metacallv/metacallv_s/metacallfv/metacallfv_s.
The copy approach means the returned value and the internal slot are
independent; destroying one does not invalidate the other.
The existing metacall_python_exception_test already exercises
metacall_error_from_value() directly. With this change, metacall_error_last()
becomes available as an errno-style alternative for callers that do not
inspect return values.
Fixes #141
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 44c62f9 commit 04ac810
3 files changed
Lines changed: 48 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
109 | 121 | | |
110 | 122 | | |
111 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1144 | 1144 | | |
1145 | 1145 | | |
1146 | 1146 | | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
1147 | 1152 | | |
1148 | 1153 | | |
1149 | 1154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| |||
92 | 98 | | |
93 | 99 | | |
94 | 100 | | |
95 | | - | |
96 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
97 | 105 | | |
98 | | - | |
| 106 | + | |
99 | 107 | | |
100 | 108 | | |
101 | 109 | | |
102 | 110 | | |
103 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
104 | 131 | | |
0 commit comments