From 9a536029c699ee501d9278577a300a5ef3d147dd Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 6 Apr 2015 12:22:11 -0700 Subject: add native dlopen extension code This will get dlopen in a consistent place on all the platforms which need it. --- ext/ffi_yajl/ext/dlopen/dlopen.c | 38 ++++++++++++++++++++++++++++++++++++++ ext/ffi_yajl/ext/dlopen/extconf.rb | 15 +++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 ext/ffi_yajl/ext/dlopen/dlopen.c create mode 100644 ext/ffi_yajl/ext/dlopen/extconf.rb (limited to 'ext/ffi_yajl/ext') diff --git a/ext/ffi_yajl/ext/dlopen/dlopen.c b/ext/ffi_yajl/ext/dlopen/dlopen.c new file mode 100644 index 0000000..7330763 --- /dev/null +++ b/ext/ffi_yajl/ext/dlopen/dlopen.c @@ -0,0 +1,38 @@ +#include + +#if defined(HAVE_DLFCN_H) +# include +#ifndef RTLD_LAZY +#define RTLD_LAZY 0 +#endif +#ifndef RTLD_GLOBAL +#define RTLD_GLOBAL 0 +#endif +#ifndef RTLD_NOW +#define RTLD_NOW 0 +#endif +#else +# if defined(_WIN32) +# include +# define dlopen(name,flag) ((void*)LoadLibrary(name)) +# define dlerror() strerror(rb_w32_map_errno(GetLastError())) +# define dlsym(handle,name) ((void*)GetProcAddress((handle),(name))) +# define RTLD_LAZY -1 +# define RTLD_NOW -1 +# define RTLD_GLOBAL -1 +# endif +#endif + +static VALUE mFFI_Yajl, mDlopen, mExt; + +static VALUE mDlopen_dlopen(VALUE self, VALUE file) { + dlopen(RSTRING_PTR(file), RTLD_NOW|RTLD_GLOBAL); + return Qnil; +} + +void Init_dlopen() { + mFFI_Yajl = rb_define_module("FFI_Yajl"); + mExt = rb_define_module_under(mFFI_Yajl, "Ext"); + mDlopen = rb_define_module_under(mExt, "Dlopen"); + rb_define_method(mDlopen, "dlopen", mDlopen_dlopen, 1); +} diff --git a/ext/ffi_yajl/ext/dlopen/extconf.rb b/ext/ffi_yajl/ext/dlopen/extconf.rb new file mode 100644 index 0000000..7e18469 --- /dev/null +++ b/ext/ffi_yajl/ext/dlopen/extconf.rb @@ -0,0 +1,15 @@ +require 'mkmf' +require 'rubygems' + +RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC'] + +puts $CFLAGS +puts $LDFLAGS + +have_header("dlfcn.h") + +have_library("dl", "dlopen") + +dir_config 'dlopen' + +create_makefile 'ffi_yajl/ext/dlopen' -- cgit v1.2.1