Skip to content

Commit b44bec0

Browse files
committed
Set thread locals directly for last_error
1 parent 5259b90 commit b44bec0

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

‎ext/fiddle/function.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ VALUE cFiddleFunction;
1616

1717
static ID id_ptr, id_abi, id_argument_types, id_return_type, id_is_variadic,
1818
id_need_gvl, id_name, id_closure, id_aref,
19-
id_set_last_error;
19+
id_last_error;
2020
#if defined(_WIN32)
21-
static ID id_set_win32_last_error, id_set_win32_last_socket_error;
21+
static ID id_win32_last_error, id_win32_last_socket_error;
2222
#endif
2323

2424
#define MAX_ARGS (SIZE_MAX / (sizeof(void *) + sizeof(fiddle_generic)) - 1)
@@ -403,12 +403,13 @@ function_call(int argc, VALUE argv[], VALUE self)
403403
#if defined(_WIN32)
404404
DWORD error = WSAGetLastError();
405405
int socket_error = WSAGetLastError();
406-
rb_funcall(mFiddle, id_set_win32_last_error, 1,
407-
ULONG2NUM(error));
408-
rb_funcall(mFiddle, id_set_win32_last_socket_error, 1,
409-
INT2NUM(socket_error));
406+
rb_thread_local_aset(rb_thread_current(), id_win32_last_error,
407+
ULONG2NUM(error));
408+
rb_thread_local_aset(rb_thread_current(), id_win32_last_socket_error,
409+
INT2NUM(socket_error));
410410
#endif
411-
rb_funcall(mFiddle, id_set_last_error, 1, INT2NUM(errno_keep));
411+
rb_thread_local_aset(rb_thread_current(), id_last_error,
412+
INT2NUM(errno_keep));
412413
}
413414

414415
ALLOCV_END(alloc_buffer);
@@ -461,12 +462,11 @@ Init_fiddle_function(void)
461462
id_need_gvl = rb_intern_const("@need_gvl");
462463
id_name = rb_intern_const("@name");
463464
id_closure = rb_intern_const("@closure");
464-
id_Pointer = rb_intern_const("Pointer");
465465
id_aref = rb_intern_const("[]");
466-
id_set_last_error = rb_intern_const("last_error=");
466+
id_last_error = rb_intern_const("__FIDDLE_LAST_ERROR__");
467467
#if defined(_WIN32)
468-
id_set_win32_last_error = rb_intern_const("win32_last_error=");
469-
id_set_win32_last_socket_error = rb_intern_const("win32_last_socket_error=");
468+
id_win32_last_error = rb_intern_const("__FIDDLE_WIN32_LAST_ERROR__");
469+
id_win32_last_socket_error = rb_intern_const("__FIDDLE_WIN32_LAST_SOCKET_ERROR__");
470470
#endif
471471

472472
cFiddleFunction = rb_define_class_under(mFiddle, "Function", rb_cObject);

‎lib/fiddle.rb‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def self.last_error
4444

4545
# Sets the last +Error+ of the current executing +Thread+ to +error+
4646
def self.last_error= error
47-
Thread.current[:__DL2_LAST_ERROR__] = error
4847
Thread.current[:__FIDDLE_LAST_ERROR__] = error
4948
end
5049

0 commit comments

Comments
 (0)