summaryrefslogtreecommitdiff
path: root/ext/dl/handle.c
diff options
context:
space:
mode:
authorttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-07 09:45:02 +0000
committerttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-07 09:45:02 +0000
commit7bcc13550437e1c4198fbf6212abc8e7672e1adb (patch)
treecf1236e58aba577543c8788adbca32293d2d4ad4 /ext/dl/handle.c
parent48a86f5ffafb2744fac609714fee74f1872df84b (diff)
Improved DL::Handle#sym.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/handle.c')
-rw-r--r--ext/dl/handle.c125
1 files changed, 85 insertions, 40 deletions
diff --git a/ext/dl/handle.c b/ext/dl/handle.c
index 7f5ce121685..d30105169c9 100644
--- a/ext/dl/handle.c
+++ b/ext/dl/handle.c
@@ -125,64 +125,109 @@ rb_dlhandle_to_i(VALUE self)
VALUE
rb_dlhandle_sym(VALUE self, VALUE sym)
{
- void (*func)();
- struct sym_data *data;
- struct dl_handle *dlhandle;
- void *handle;
- const char *name;
- const char *err;
+ void (*func)();
+ struct sym_data *data;
+ struct dl_handle *dlhandle;
+ void *handle;
+ const char *name;
+ const char *err;
- rb_secure(2);
+ rb_secure(2);
- if( sym == Qnil ){
+ if( sym == Qnil ){
#if defined(RTLD_NEXT)
- name = RTLD_NEXT;
+ name = RTLD_NEXT;
#else
- name = NULL;
+ name = NULL;
#endif
- }
- else{
- name = StringValuePtr(sym);
- }
+ }
+ else{
+ name = StringValuePtr(sym);
+ }
- Data_Get_Struct(self, struct dl_handle, dlhandle);
- if( ! dlhandle->open ){
- rb_raise(rb_eDLError, "Closed handle.");
- }
- handle = dlhandle->ptr;
+ Data_Get_Struct(self, struct dl_handle, dlhandle);
+ if( ! dlhandle->open ){
+ rb_raise(rb_eDLError, "Closed handle.");
+ }
+ handle = dlhandle->ptr;
- func = dlsym(handle, name);
+ func = dlsym(handle, name);
#if defined(HAVE_DLERROR)
- if( !func && (err = dlerror()) )
+ if( !func && (err = dlerror()) )
#else
- if( !func )
+ if( !func )
#endif
- {
-#if defined(__CYGWIN__) || defined(WIN32) || defined(__MINGW32__)
{
- int len = strlen(name);
- char *name_a = (char*)xmalloc(len+2);
- strcpy(name_a, name);
- name_a[len] = 'A';
- name_a[len+1] = '\0';
- func = dlsym(handle, name_a);
- xfree(name_a);
+#if defined(__CYGWIN__) || defined(WIN32) || defined(__MINGW32__)
+ {
+ int len = strlen(name);
+ int i;
+ char *name_a = (char*)xmalloc(len+2);
+ strcpy(name_a, name);
+ name_a[len] = 'A';
+ name_a[len+1] = '\0';
+ func = dlsym(handle, name_a);
+ xfree(name_a);
#if defined(HAVE_DLERROR)
- if( !func && (err = dlerror()) )
+ if( !func && (err = dlerror()) )
#else
- if( !func )
+ if( !func )
#endif
- {
- rb_raise(rb_eDLError, "Unknown symbol \"%sA\".", name);
- }
- }
+ {
+ for( i = 0; i < 256; i += 4 ){
+ int len = strlen(name);
+ char *name_n = (char*)xmalloc(len+5);
+ sprintf(name_n, "%s@%d%c", name, i, 0);
+ func = dlsym(handle, name_n);
+ xfree(name_n);
+#if defined(HAVE_DLERROR)
+ if( func || !(err = dlerror()) )
#else
- rb_raise(rb_eDLError, "Unknown symbol \"%s\".", name);
+ if( func )
#endif
- }
+ {
+ break;
+ }
+ }
+#if defined(HAVE_DLERROR)
+ if( !func && (err = dlerror()) )
+#else
+ if( !func )
+#endif
+ {
+ rb_raise(rb_eDLError, "Unknown symbol \"%s\".", name);
+ }
+ }
+ }
+#else
+ for( i = 0; i < 256; i += 4 ){
+ int len = strlen(name);
+ char *name_n = (char*)xmalloc(len+4);
+ sprintf(name_n, "%s@%d", name, i);
+ func = dlsym(handle, name_n);
+ xfree(name_n);
+#if defined(HAVE_DLERROR)
+ if( func || !(err = dlerror()) )
+#else
+ if( func )
+#endif
+ {
+ break;
+ }
+ }
+#if defined(HAVE_DLERROR)
+ if( !func && (err = dlerror()) )
+#else
+ if( !func )
+#endif
+ {
+ rb_raise(rb_eDLError, "Unknown symbol \"%s\".", name);
+ }
+#endif
+ }
- return PTR2NUM(func);
+ return PTR2NUM(func);
}
void