From 9e72cb1ca3d2ba5a87e1e90a05234fb68b2b05da Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 14 Oct 2018 10:13:24 +0000 Subject: [PATCH] enhanced pfmod loading code --- Makefile.in | 9 ++-- configure | 34 ++++++++----- configure.ac | 7 +++ lib/Makefile.am | 31 ++++++++---- lib/Makefile.in | 48 +++++++++++-------- lib/hcl-s.c | 123 ++++++++++++++++++++++++++++++++++++++++++------ lib/main.c | 10 +--- mod/Makefile.am | 8 ---- mod/Makefile.in | 16 +++---- 9 files changed, 201 insertions(+), 85 deletions(-) diff --git a/Makefile.in b/Makefile.in index 86fa86e..fc7a20e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -354,7 +354,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -585,7 +584,7 @@ distdir: $(DISTFILES) ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir @@ -611,7 +610,7 @@ dist-shar: distdir @echo WARNING: "Support for shar distribution archives is" \ "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 - shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir @@ -629,7 +628,7 @@ dist dist-all: distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ @@ -639,7 +638,7 @@ distcheck: dist *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac diff --git a/configure b/configure index 32c8c68..2a3031c 100755 --- a/configure +++ b/configure @@ -677,6 +677,8 @@ PTHREAD_LIBS PTHREAD_CC ax_pthread_config LIBM +MACOSX_FALSE +MACOSX_TRUE WIN32_FALSE WIN32_TRUE LIBTOOL_DEPS @@ -782,7 +784,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -876,7 +877,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1129,15 +1129,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1275,7 +1266,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1428,7 +1419,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -17191,9 +17181,15 @@ case "$host" in *-*-mingw*|*-*-cygwin*) #CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0400" platform_win32=yes + platform_macosx=no + ;; +*-*-darwin*) + platform_win32=no + platform_macosx=yes ;; *) platform_win32=no + platform_macosx=no ;; esac if test "x${platform_win32}" = "xyes" ; then @@ -17204,6 +17200,14 @@ else WIN32_FALSE= fi + if test "x${platform_macosx}" = "xyes" ; then + MACOSX_TRUE= + MACOSX_FALSE='#' +else + MACOSX_TRUE='#' + MACOSX_FALSE= +fi + LIBM= case $host in @@ -21444,6 +21448,10 @@ if test -z "${WIN32_TRUE}" && test -z "${WIN32_FALSE}"; then as_fn_error $? "conditional \"WIN32\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${MACOSX_TRUE}" && test -z "${MACOSX_FALSE}"; then + as_fn_error $? "conditional \"MACOSX\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${ENABLE_CXX_TRUE}" && test -z "${ENABLE_CXX_FALSE}"; then as_fn_error $? "conditional \"ENABLE_CXX\" was never defined. diff --git a/configure.ac b/configure.ac index 740ce67..9d7f256 100644 --- a/configure.ac +++ b/configure.ac @@ -69,12 +69,19 @@ case "$host" in *-*-mingw*|*-*-cygwin*) #CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0400" platform_win32=yes + platform_macosx=no + ;; +*-*-darwin*) + platform_win32=no + platform_macosx=yes ;; *) platform_win32=no + platform_macosx=no ;; esac AM_CONDITIONAL(WIN32, test "x${platform_win32}" = "xyes" ) +AM_CONDITIONAL(MACOSX, test "x${platform_macosx}" = "xyes" ) dnl check the math library (check if -lm is needed) LT_LIB_M diff --git a/lib/Makefile.am b/lib/Makefile.am index fa94b22..2ea1b9a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -32,6 +32,19 @@ if ENABLE_LIBUNWIND LIBADD_LIB_COMMON += $(UNWIND_LIBS) endif +if WIN32 +# you must adjust the value of DEFAULT_MODPOSTFIX according +# to the first number in -version-info above +CPPFLAGS_PFMOD = -DHCL_DEFAULT_PFMODPREFIX=\"libmoo-\" -DHCL_DEFAULT_PFMODPOSTFIX=\"-1.dll\" +else +CPPFLAGS_PFMOD = -DHCL_DEFAULT_PFMODPREFIX=\"$(libdir)/libmoo-\" +if MACOSX +CPPFLAGS_PFMOD += -DHCL_DEFAULT_PFMODPOSTFIX=\".dylib\" +else +CPPFLAGS_PFMOD += -DHCL_DEFAULT_PFMODPOSTFIX=\".so\" +endif +endif + pkgincludedir = $(includedir) pkglibdir = $(libdir) @@ -89,8 +102,8 @@ endif bin_PROGRAMS = hcl hcl_SOURCES = main.c -hcl_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -hcl_LDFLAGS = $(LDFLAGS_LIB_COMMON) +hcl_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) +hcl_LDFLAGS = $(LDFLAGS_ALL_COMMON) hcl_LDADD = $(LIBADD_LIB_COMMON) -lhcl hcl_DEPENDENCIES = libhcl.la @@ -103,29 +116,29 @@ libhclex_la_SOURCES = \ json.c hcl-json.h \ hcl-s.c hcl-s.h \ hcl-c.c hcl-c.h -libhclex_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) +libhclex_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) $(CPPFLAGS_PFMOD) libhclex_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) libhclex_la_LIBADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl libhclex_la_DEPENDENCIES = libhcl.la bin_PROGRAMS += hcls hcls_SOURCES = main-s.c -hcls_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -hcls_LDFLAGS = $(LDFLAGS_LIB_COMMON) +hcls_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) +hcls_LDFLAGS = $(LDFLAGS_ALL_COMMON) hcls_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex hcls_DEPENDENCIES = libhclex.la bin_PROGRAMS += hclc hclc_SOURCES = main-c.c -hclc_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -hclc_LDFLAGS = $(LDFLAGS_LIB_COMMON) +hclc_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) +hclc_LDFLAGS = $(LDFLAGS_ALL_COMMON) hclc_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex hclc_DEPENDENCIES = libhclex.la bin_PROGRAMS += hclj hclj_SOURCES = main-j.c -hclj_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -hclj_LDFLAGS = $(LDFLAGS_LIB_COMMON) +hclj_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) +hclj_LDFLAGS = $(LDFLAGS_ALL_COMMON) hclj_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex hclj_DEPENDENCIES = libhclex.la endif diff --git a/lib/Makefile.in b/lib/Makefile.in index e61c5c1..c2f2751 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -91,15 +91,17 @@ host_triplet = @host@ @ENABLE_LIBLTDL_TRUE@am__append_1 = $(LTDL_LIBS) @ENABLE_LIBLTDL_FALSE@am__append_2 = $(DL_LIBS) @ENABLE_LIBUNWIND_TRUE@am__append_3 = $(UNWIND_LIBS) -@ENABLE_STATIC_MODULE_TRUE@am__append_4 = -lhcl-arr -lhcl-dic \ +@MACOSX_TRUE@@WIN32_FALSE@am__append_4 = -DHCL_DEFAULT_PFMODPOSTFIX=\".dylib\" +@MACOSX_FALSE@@WIN32_FALSE@am__append_5 = -DHCL_DEFAULT_PFMODPOSTFIX=\".so\" +@ENABLE_STATIC_MODULE_TRUE@am__append_6 = -lhcl-arr -lhcl-dic \ @ENABLE_STATIC_MODULE_TRUE@ -lhcl-str -@ENABLE_STATIC_MODULE_TRUE@am__append_5 = $(abs_builddir)/../mod/libhcl-arr.la \ +@ENABLE_STATIC_MODULE_TRUE@am__append_7 = $(abs_builddir)/../mod/libhcl-arr.la \ @ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-dic.la \ @ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-str.la bin_PROGRAMS = hcl$(EXEEXT) $(am__EXEEXT_1) -@ENABLE_HCLEX_TRUE@am__append_6 = libhclex.la -@ENABLE_HCLEX_TRUE@am__append_7 = hcl-c.h hcl-s.h hcl-tmr.h hcl-xutl.h hcl-json.h -@ENABLE_HCLEX_TRUE@am__append_8 = hcls hclc hclj +@ENABLE_HCLEX_TRUE@am__append_8 = libhclex.la +@ENABLE_HCLEX_TRUE@am__append_9 = hcl-c.h hcl-s.h hcl-tmr.h hcl-xutl.h hcl-json.h +@ENABLE_HCLEX_TRUE@am__append_10 = hcls hclc hclj subdir = lib ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -420,7 +422,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -446,9 +447,18 @@ CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined LIBADD_LIB_COMMON = $(LIBM) $(am__append_1) $(am__append_2) \ $(am__append_3) +@WIN32_FALSE@CPPFLAGS_PFMOD = \ +@WIN32_FALSE@ -DHCL_DEFAULT_PFMODPREFIX=\"$(libdir)/libmoo-\" \ +@WIN32_FALSE@ $(am__append_4) $(am__append_5) + +# you must adjust the value of DEFAULT_MODPOSTFIX according +# to the first number in -version-info above +@WIN32_TRUE@CPPFLAGS_PFMOD = -DHCL_DEFAULT_PFMODPREFIX=\"libmoo-\" \ +@WIN32_TRUE@ -DHCL_DEFAULT_PFMODPOSTFIX=\"-1.dll\" \ +@WIN32_TRUE@ $(am__append_4) $(am__append_5) pkginclude_HEADERS = hcl.h hcl-cmn.h hcl-opt.h hcl-rbt.h hcl-utl.h \ - $(am__append_7) -pkglib_LTLIBRARIES = libhcl.la $(am__append_6) + $(am__append_9) +pkglib_LTLIBRARIES = libhcl.la $(am__append_8) libhcl_la_SOURCES = \ hcl.h \ hcl-cmn.h \ @@ -482,11 +492,11 @@ libhcl_la_SOURCES = \ libhcl_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) libhcl_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) -libhcl_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_4) -libhcl_la_DEPENDENCIES = $(am__append_5) +libhcl_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_6) +libhcl_la_DEPENDENCIES = $(am__append_7) hcl_SOURCES = main.c -hcl_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -hcl_LDFLAGS = $(LDFLAGS_LIB_COMMON) +hcl_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) +hcl_LDFLAGS = $(LDFLAGS_ALL_COMMON) hcl_LDADD = $(LIBADD_LIB_COMMON) -lhcl hcl_DEPENDENCIES = libhcl.la @ENABLE_HCLEX_TRUE@libhclex_la_SOURCES = \ @@ -496,23 +506,23 @@ hcl_DEPENDENCIES = libhcl.la @ENABLE_HCLEX_TRUE@ hcl-s.c hcl-s.h \ @ENABLE_HCLEX_TRUE@ hcl-c.c hcl-c.h -@ENABLE_HCLEX_TRUE@libhclex_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) +@ENABLE_HCLEX_TRUE@libhclex_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) $(CPPFLAGS_PFMOD) @ENABLE_HCLEX_TRUE@libhclex_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) @ENABLE_HCLEX_TRUE@libhclex_la_LIBADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl @ENABLE_HCLEX_TRUE@libhclex_la_DEPENDENCIES = libhcl.la @ENABLE_HCLEX_TRUE@hcls_SOURCES = main-s.c -@ENABLE_HCLEX_TRUE@hcls_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -@ENABLE_HCLEX_TRUE@hcls_LDFLAGS = $(LDFLAGS_LIB_COMMON) +@ENABLE_HCLEX_TRUE@hcls_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) +@ENABLE_HCLEX_TRUE@hcls_LDFLAGS = $(LDFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hcls_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex @ENABLE_HCLEX_TRUE@hcls_DEPENDENCIES = libhclex.la @ENABLE_HCLEX_TRUE@hclc_SOURCES = main-c.c -@ENABLE_HCLEX_TRUE@hclc_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -@ENABLE_HCLEX_TRUE@hclc_LDFLAGS = $(LDFLAGS_LIB_COMMON) +@ENABLE_HCLEX_TRUE@hclc_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) +@ENABLE_HCLEX_TRUE@hclc_LDFLAGS = $(LDFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hclc_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex @ENABLE_HCLEX_TRUE@hclc_DEPENDENCIES = libhclex.la @ENABLE_HCLEX_TRUE@hclj_SOURCES = main-j.c -@ENABLE_HCLEX_TRUE@hclj_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -@ENABLE_HCLEX_TRUE@hclj_LDFLAGS = $(LDFLAGS_LIB_COMMON) +@ENABLE_HCLEX_TRUE@hclj_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) +@ENABLE_HCLEX_TRUE@hclj_LDFLAGS = $(LDFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hclj_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex @ENABLE_HCLEX_TRUE@hclj_DEPENDENCIES = libhclex.la all: hcl-cfg.h diff --git a/lib/hcl-s.c b/lib/hcl-s.c index 94f2fbf..2d05706 100644 --- a/lib/hcl-s.c +++ b/lib/hcl-s.c @@ -72,6 +72,14 @@ # define sys_dl_openext(x) dlopen(x,RTLD_NOW) # define sys_dl_close(x) dlclose(x) # define sys_dl_getsym(x,n) dlsym(x,n) +# elif defined(__APPLE__) || defined(__MACOSX__) +# define USE_MACH_O +# include +# define sys_dl_error() mach_dlerror() +# define sys_dl_open(x) mach_dlopen(x) +# define sys_dl_openext(x) mach_dlopen(x) +# define sys_dl_close(x) mach_dlclose(x) +# define sys_dl_getsym(x,n) mach_dlsym(x,n) # else # error UNSUPPORTED DYNAMIC LINKER # endif @@ -104,6 +112,10 @@ # include #endif +#if !defined(HCL_DEFAULT_PFMODDIR) +# define HCL_DEFAULT_PFMODDIR "" +#endif + #if !defined(HCL_DEFAULT_PFMODPREFIX) # if defined(_WIN32) # define HCL_DEFAULT_PFMODPREFIX "hcl-" @@ -126,6 +138,8 @@ # else # if defined(USE_DLFCN) # define HCL_DEFAULT_PFMODPOSTFIX ".so" +# elif defined(USE_MACH_O) +# define HCL_DEFAULT_PFMODPOSTFIX ".dylib" # else # define HCL_DEFAULT_PFMODPOSTFIX "" # endif @@ -360,6 +374,9 @@ struct hcl_server_t # define PATH_SEP_CHAR ('/') #endif +/* TODO: handle path with a drive letter or in the UNC notation */ +#define IS_PATH_ABSOLUTE(x) IS_PATH_SEP(x[0]) + static const hcl_bch_t* get_base_name (const hcl_bch_t* path) { @@ -732,10 +749,76 @@ static void syserrstrb (hcl_t* hcl, int syserr, hcl_bch_t* buf, hcl_oow_t len) } /* ========================================================================= */ +#if defined(USE_MACH_O) +static const char* mach_dlerror_str = ""; + +static void* mach_dlopen (const char* path) +{ + NSObjectFileImage image; + NSObjectFileImageReturnCode rc; + void* handle; + + mach_dlerror_str = ""; + if ((rc = NSCreateObjectFileImageFromFile(path, &image)) != NSObjectFileImageSuccess) + { + switch (rc) + { + case NSObjectFileImageFailure: + case NSObjectFileImageFormat: + mach_dlerror_str = "unable to crate object file image"; + break; + + case NSObjectFileImageInappropriateFile: + mach_dlerror_str = "inappropriate file"; + break; + + case NSObjectFileImageArch: + mach_dlerror_str = "incompatible architecture"; + break; + + case NSObjectFileImageAccess: + mach_dlerror_str = "inaccessible file"; + break; + + default: + mach_dlerror_str = "unknown error"; + break; + } + return HCL_NULL; + } + handle = (void*)NSLinkModule(image, path, NSLINKMODULE_OPTION_PRIVATE | NSLINKMODULE_OPTION_RETURN_ON_ERROR); + NSDestroyObjectFileImage (image); + return handle; +} + +static HCL_INLINE void mach_dlclose (void* handle) +{ + mach_dlerror_str = ""; + NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_NONE); +} + +static HCL_INLINE void* mach_dlsym (void* handle, const char* name) +{ + mach_dlerror_str = ""; + return (void*)NSAddressOfSymbol(NSLookupSymbolInModule(handle, name)); +} + +static const char* mach_dlerror (void) +{ + int err_no; + const char* err_file; + NSLinkEditErrors err; + + if (mach_dlerror_str[0] == '\0') + NSLinkEditError (&err, &err_no, &err_file, &mach_dlerror_str); + + return mach_dlerror_str; +} +#endif static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) { -#if defined(USE_LTDL) || defined(USE_DLFCN) +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) hcl_bch_t stabuf[128], * bufptr; hcl_oow_t ucslen, bcslen, bufcapa; void* handle; @@ -748,7 +831,7 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) #else bufcapa = hcl_count_bcstr(name); #endif - bufcapa += HCL_COUNTOF(HCL_DEFAULT_PFMODPREFIX) + HCL_COUNTOF(HCL_DEFAULT_PFMODPOSTFIX) + 1; + bufcapa += HCL_COUNTOF(HCL_DEFAULT_PFMODDIR) + HCL_COUNTOF(HCL_DEFAULT_PFMODPREFIX) + HCL_COUNTOF(HCL_DEFAULT_PFMODPOSTFIX) + 1; if (bufcapa <= HCL_COUNTOF(stabuf)) bufptr = stabuf; else @@ -759,10 +842,14 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) if (flags & HCL_VMPRIM_DLOPEN_PFMOD) { - hcl_oow_t len, i, xlen; + hcl_oow_t len, i, xlen, dlen; - /* opening a primitive function module - mostly libhcl-xxxx */ + /* opening a primitive function module - mostly libhcl-xxxx. + * if PFMODPREFIX is absolute, never use PFMODDIR */ + dlen = IS_PATH_ABSOLUTE(HCL_DEFAULT_PFMODPREFIX)? + 0: hcl_copy_bcstr(bufptr, bufcapa, HCL_DEFAULT_PFMODDIR); len = hcl_copy_bcstr(bufptr, bufcapa, HCL_DEFAULT_PFMODPREFIX); + len += dlen; bcslen = bufcapa - len; #if defined(HCL_OOCH_IS_UCH) @@ -771,7 +858,7 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) bcslen = hcl_copy_bcstr(&bufptr[len], bcslen, name); #endif - /* length including the prefix and the name. but excluding the postfix */ + /* length including the directory, the prefix and the name. but excluding the postfix */ xlen = len + bcslen; for (i = len; i < xlen; i++) @@ -787,7 +874,14 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) handle = sys_dl_openext(bufptr); if (!handle) { - HCL_DEBUG3 (hcl, "Failed to open(ext) DL %hs[%js] - %hs\n", bufptr, name, sys_dl_error()); + HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[dlen], name, sys_dl_error()); + + if (dlen > 0) + { + handle = sys_dl_openext(&bufptr[0]); + if (handle) goto pfmod_open_ok; + HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[0], name, sys_dl_error()); + } /* try without prefix and postfix */ bufptr[xlen] = '\0'; @@ -797,8 +891,8 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) hcl_bch_t* dash; const hcl_bch_t* dl_errstr; dl_errstr = sys_dl_error(); - HCL_DEBUG3 (hcl, "Failed to open(ext) DL %hs[%js] - %hs\n", &bufptr[len], name, dl_errstr); - hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open(ext) DL %js - %hs", name, dl_errstr); + HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[len], name, dl_errstr); + hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open(ext) PFMOD %js - %hs", name, dl_errstr); dash = hcl_rfind_bchar(bufptr, hcl_count_bcstr(bufptr), '-'); if (dash) @@ -813,12 +907,13 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) } else { - HCL_DEBUG3 (hcl, "Opened(ext) DL %hs[%js] handle %p\n", &bufptr[len], name, handle); + HCL_DEBUG3 (hcl, "Opened(ext) PFMOD %hs[%js] handle %p\n", &bufptr[len], name, handle); } } else { - HCL_DEBUG3 (hcl, "Opened(ext) DL %hs[%js] handle %p\n", bufptr, name, handle); + pfmod_open_ok: + HCL_DEBUG3 (hcl, "Opened(ext) PFMOD %hs[%js] handle %p\n", &bufptr[dlen], name, handle); } } else @@ -838,7 +933,7 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) { const hcl_bch_t* dl_errstr; dl_errstr = sys_dl_error(); - HCL_DEBUG2 (hcl, "Failed to open DL %hs - %hs\n", bufptr, dl_errstr); + HCL_DEBUG2 (hcl, "Unable to open DL %hs - %hs\n", bufptr, dl_errstr); hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open DL %js - %hs", name, dl_errstr); } else HCL_DEBUG2 (hcl, "Opened DL %hs handle %p\n", bufptr, handle); @@ -850,7 +945,7 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) { const hcl_bch_t* dl_errstr; dl_errstr = sys_dl_error(); - HCL_DEBUG2 (hcl, "Failed to open(ext) DL %hs - %s\n", bufptr, dl_errstr); + HCL_DEBUG2 (hcl, "Unable to open(ext) DL %hs - %s\n", bufptr, dl_errstr); hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open(ext) DL %js - %hs", name, dl_errstr); } else HCL_DEBUG2 (hcl, "Opened(ext) DL %hs handle %p\n", bufptr, handle); @@ -872,7 +967,7 @@ static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) static void dl_close (hcl_t* hcl, void* handle) { -#if defined(USE_LTDL) || defined(USE_DLFCN) +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) HCL_DEBUG1 (hcl, "Closed DL handle %p\n", handle); sys_dl_close (handle); @@ -884,7 +979,7 @@ static void dl_close (hcl_t* hcl, void* handle) static void* dl_getsym (hcl_t* hcl, void* handle, const hcl_ooch_t* name) { -#if defined(USE_LTDL) || defined(USE_DLFCN) +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) hcl_bch_t stabuf[64], * bufptr; hcl_oow_t bufcapa, ucslen, bcslen, i; const hcl_bch_t* symname; diff --git a/lib/main.c b/lib/main.c index 3a2de81..6702f20 100644 --- a/lib/main.c +++ b/lib/main.c @@ -210,6 +210,8 @@ static hcl_mmgr_t sys_mmgr = # define IS_PATH_SEP(c) ((c) == '/') #endif +/* TODO: handle path with a drive letter or in the UNC notation */ +#define IS_PATH_ABSOLUTE(x) IS_PATH_SEP(x[0]) static const hcl_bch_t* get_base_name (const hcl_bch_t* path) { @@ -843,14 +845,6 @@ static const char* mach_dlerror (void) } #endif - -#if defined(_WIN32) || defined(__DOS__) || defined(__OS2__) - /* TODO: handle drive letter and UNC notations? */ -# define IS_PATH_ABSOLUTE(x) (x[0] == '/' || x[0] == '\\') -#else -# define IS_PATH_ABSOLUTE(x) (x[0] == '/') -#endif - static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) { #if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) diff --git a/mod/Makefile.am b/mod/Makefile.am index 28cff46..2f8ade8 100644 --- a/mod/Makefile.am +++ b/mod/Makefile.am @@ -9,14 +9,6 @@ CPPFLAGS_COMMON = \ -I$(abs_srcdir)/../lib \ -I$(includedir) -if WIN32 -# you must adjust the value of DEFAULT_PFMODPOSTFIX according -# to the first number in -version-info above -CPPFLAGS_COMMON += -DHCL_DEFAULT_PFMODPREFIX=\"libhcl-\" -DHCL_DEFAULT_PFMODPOSTFIX=\"-1\" -else -CPPFLAGS_COMMON += -DHCL_DEFAULT_PFMODPREFIX=\"$(libdir)/libhcl-\" -DHCL_DEFAULT_PFMODPOSTFIX=\"\" -endif - if ENABLE_STATIC_MODULE ################################################## diff --git a/mod/Makefile.in b/mod/Makefile.in index 66c44a7..be511ee 100644 --- a/mod/Makefile.in +++ b/mod/Makefile.in @@ -88,11 +88,6 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ - -# you must adjust the value of DEFAULT_PFMODPOSTFIX according -# to the first number in -version-info above -@WIN32_TRUE@am__append_1 = -DHCL_DEFAULT_PFMODPREFIX=\"libhcl-\" -DHCL_DEFAULT_PFMODPOSTFIX=\"-1\" -@WIN32_FALSE@am__append_2 = -DHCL_DEFAULT_PFMODPREFIX=\"$(libdir)/libhcl-\" -DHCL_DEFAULT_PFMODPOSTFIX=\"\" subdir = mod ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -377,7 +372,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -387,9 +381,13 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = nostdinc -CPPFLAGS_COMMON = -I$(abs_builddir) -I$(abs_builddir)/../lib \ - -I$(abs_srcdir) -I$(abs_srcdir)/../lib -I$(includedir) \ - $(am__append_1) $(am__append_2) +CPPFLAGS_COMMON = \ + -I$(abs_builddir) \ + -I$(abs_builddir)/../lib \ + -I$(abs_srcdir) \ + -I$(abs_srcdir)/../lib \ + -I$(includedir) + ################################################## # DYNAMIC MODULES