summaryrefslogtreecommitdiff
path: root/ext/dl
diff options
context:
space:
mode:
Diffstat (limited to 'ext/dl')
-rw-r--r--ext/dl/cfunc.c6
-rw-r--r--ext/dl/cptr.c4
-rw-r--r--ext/dl/dl.c9
-rw-r--r--ext/dl/mkcallback.rb7
4 files changed, 18 insertions, 8 deletions
diff --git a/ext/dl/cfunc.c b/ext/dl/cfunc.c
index 6dcca5c6db..2e5a35d278 100644
--- a/ext/dl/cfunc.c
+++ b/ext/dl/cfunc.c
@@ -225,6 +225,8 @@ rb_dlcfunc_inspect(VALUE self)
#if defined(__GNUC__)
# define DECL_FUNC(f,ret,args,calltype) ret (__attribute__((calltype)) *f)(args)
/* # define DECL_FUNC(f,ret,args,calltype) ret (*f)(args) */
+#elif defined(_MSC_VER)
+# define DECL_FUNC(f,ret,args,calltype) ret (__##calltype *f)(args)
#else
# error "unsupported compiler."
#endif
@@ -331,7 +333,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary)
#if HAVE_LONG_LONG /* used in ruby.h */
case DLTYPE_LONG_LONG:
#define CASE(n) case n: { \
- DECL_FUNC(f,long long,DLSTACK_PROTO,cdecl) = cfunc->ptr; \
+ DECL_FUNC(f,LONG_LONG,DLSTACK_PROTO,cdecl) = cfunc->ptr; \
LONG_LONG ret; \
ret = f(DLSTACK_ARGS(stack)); \
result = LL2NUM(ret); \
@@ -429,7 +431,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary)
#if HAVE_LONG_LONG /* used in ruby.h */
case DLTYPE_LONG_LONG:
#define CASE(n) case n: { \
- DECL_FUNC(f,long long,DLSTACK_PROTO,stdcall) = cfunc->ptr; \
+ DECL_FUNC(f,LONG_LONG,DLSTACK_PROTO,stdcall) = cfunc->ptr; \
LONG_LONG ret; \
ret = f(DLSTACK_ARGS(stack)); \
result = LL2NUM(ret); \
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
index 88897ccc86..18df5c8a38 100644
--- a/ext/dl/cptr.c
+++ b/ext/dl/cptr.c
@@ -360,7 +360,7 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
defualt:
rb_bug("rb_dlptr_aset()");
}
- return rb_tainted_str_new(RPTR_DATA(self)->ptr + offset, len);
+ return rb_tainted_str_new((char *)RPTR_DATA(self)->ptr + offset, len);
}
VALUE
@@ -392,7 +392,7 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
defualt:
rb_bug("rb_dlptr_aset()");
}
- memcpy(RPTR_DATA(self)->ptr + offset, mem, len);
+ memcpy((char *)RPTR_DATA(self)->ptr + offset, mem, len);
return Qnil;
}
diff --git a/ext/dl/dl.c b/ext/dl/dl.c
index ed46c0ef33..d63777e6c5 100644
--- a/ext/dl/dl.c
+++ b/ext/dl/dl.c
@@ -58,6 +58,15 @@ rb_dl_value2ptr(VALUE self, VALUE val)
#if defined(__GNUC__)
# define PRE_DECL_CDECL __attribute__((cdecl))
# define PRE_DECL_STDCALL __attribute__((stdcall))
+# define MIDST_DECL_CDECL
+# define MIDST_DECL_STDCALL
+# define POST_DECL_CDECL
+# define POST_DECL_STDCALL
+#elif defined(_MSC_VER)
+# define PRE_DECL_CDECL
+# define PRE_DECL_STDCALL
+# define MIDST_DECL_CDECL __cdecl
+# define MIDST_DECL_STDCALL __stdcall
# define POST_DECL_CDECL
# define POST_DECL_STDCALL
#else
diff --git a/ext/dl/mkcallback.rb b/ext/dl/mkcallback.rb
index 0b071d4caa..b5a6889743 100644
--- a/ext/dl/mkcallback.rb
+++ b/ext/dl/mkcallback.rb
@@ -111,18 +111,17 @@ for calltype in CALLTYPES
for n in 0..(MAX_CALLBACK-1)
$out << (<<-EOS)
-PRE_DECL_#{calltype.upcase} static #{DLTYPE[ty][:type]}
+PRE_DECL_#{calltype.upcase} static #{DLTYPE[ty][:type]} MIDST_DECL_#{calltype.upcase}
#{func_name(ty,argc,n,calltype)}(#{(0...argc).collect{|i| "DLSTACK_TYPE stack" + i.to_s}.join(", ")}) POST_DECL_#{calltype.upcase}
{
- VALUE args[#{argc}];
- VALUE ret, cb;
+ VALUE ret, cb#{argc > 0 ? ", args[#{argc}]" : ""};
#{
(0...argc).collect{|i|
" args[%d] = LONG2NUM(stack%d);" % [i,i]
}.join("\n")
}
cb = rb_ary_entry(rb_ary_entry(#{proc_entry}, #{ty}), #{(n * DLSTACK_SIZE) + argc});
- ret = rb_funcall2(cb, cb_call, #{argc}, args);
+ ret = rb_funcall2(cb, cb_call, #{argc}, #{argc > 0 ? 'args' : 'NULL'});
return #{DLTYPE[ty][:conv] ? DLTYPE[ty][:conv] % "ret" : ""};
}