[#38724] 祝日判定用メソッド — Take_tk <ggb03124@...>

たけ(tk)です

19 messages 2003/11/02

[#38756] ruby-dev summary 21730-21822 /draft — Minero Aoki <aamine@...>

青木です。

14 messages 2003/11/05

[ruby-list:38742] Re: [Win32] GetLastError() with dl.so

From: "Shirai,Kaoru" <shirai@...>
Date: 2003-11-03 08:38:34 UTC
List: ruby-list #38742
白井です。

パッチにバグ発見…rb_thread_local_asetにより値が変化する可能性を忘れて
いました。

695a696,701
>   
>   {
>     int last_errno = errno;
> #ifdef _WIN32
>     DWORD win32_last_err = GetLastError();
> #endif
697c703
<   rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLErrno, INT2NUM(errno));
---
>     rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLErrno, INT2NUM(last_errno));
699c705
<   rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLW32Error, INT2NUM(GetLastError()));
---
>     rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLW32Error, INT2NUM(win32_last_err));
700a707,708
>   }
> 

Attachments (1)

dl-sym-win32err-2.diff (2.56 KB, text/x-diff)
Index: sym.c
===================================================================
RCS file: /src/ruby/ext/dl/sym.c,v
retrieving revision 1.19
diff -u -r1.19 sym.c
--- sym.c	29 Mar 2003 02:56:18 -0000	1.19
+++ sym.c	3 Nov 2003 08:34:41 -0000
@@ -3,6 +3,7 @@
  */
 
 #include <ruby.h>
+#include <errno.h>
 #include "dl.h"
 
 VALUE rb_cDLSymbol;
@@ -316,6 +317,23 @@
   return size;
 }
 
+ID rb_dl_id_DLErrno;
+VALUE
+rb_dl_get_last_errno(VALUE self)
+{
+  return rb_thread_local_aref(rb_thread_current(), rb_dl_id_DLErrno);
+}
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+ID rb_dl_id_DLW32Error;
+VALUE
+rb_dl_win32_get_lasterror(VALUE self)
+{
+  return rb_thread_local_aref(rb_thread_current(), rb_dl_id_DLW32Error);
+}
+#endif
+
 VALUE
 rb_dlsym_call(int argc, VALUE argv[], VALUE self)
 {
@@ -675,6 +693,19 @@
       rb_raise(rb_eDLTypeError, "unknown type `%c'", sym->type[0]);
     }
   }
+  
+  {
+    int last_errno = errno;
+#ifdef _WIN32
+    DWORD win32_last_err = GetLastError();
+#endif
+
+    rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLErrno, INT2NUM(last_errno));
+#ifdef _WIN32
+    rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLW32Error, INT2NUM(win32_last_err));
+#endif
+  }
+
   }
 #else /* defined(DLSTACK) */
   switch(ftype){
@@ -835,4 +866,11 @@
   rb_define_method(rb_cDLSymbol, "to_s", rb_dlsym_cproto, 0);
   rb_define_method(rb_cDLSymbol, "to_ptr", rb_dlsym_to_ptr, 0);
   rb_define_method(rb_cDLSymbol, "to_i", rb_dlsym_to_i, 0);
+
+  rb_dl_id_DLErrno = rb_intern("DLErrno");
+  rb_define_singleton_method(rb_mDL, "last_errno", rb_dl_get_last_errno, 0);  
+#ifdef _WIN32
+  rb_dl_id_DLW32Error = rb_intern("DLW32Error");
+  rb_define_singleton_method(rb_mDL, "win32_last_error", rb_dl_win32_get_lasterror, 0);
+#endif
 }
Index: extconf.rb
===================================================================
RCS file: /src/ruby/ext/dl/extconf.rb,v
retrieving revision 1.11
diff -u -r1.11 extconf.rb
--- extconf.rb	23 Oct 2003 08:59:42 -0000	1.11
+++ extconf.rb	3 Nov 2003 08:34:42 -0000
@@ -127,6 +127,13 @@
   $dlconfig_h << "#define WITH_TYPE_VOIDP\n"
 end
 
+if( have_header("windows.h") )
+  have_library("kernel32")
+  have_func("GetLastError", "windows.h")
+  dlc_define("HAVE_WINDOWS_H")
+  have_windows_h = true
+end
+
 if( have_header("dlfcn.h") )
   dlc_define("HAVE_DLFCN_H")
   have_library("dl")
@@ -136,8 +143,7 @@
   if( have_func("dlerror") )
     dlc_define("HAVE_DLERROR")
   end
-elsif( have_header("windows.h") )
-  dlc_define("HAVE_WINDOWS_H")
+elsif ( have_windows_h )
   have_func("LoadLibrary")
   have_func("FreeLibrary")
   have_func("GetProcAddress")

In This Thread

Prev Next