[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] m4: support to load modules on OS/2
From: |
KO Myung-Hun |
Subject: |
[PATCH 2/5] m4: support to load modules on OS/2 |
Date: |
Thu, 20 Nov 2014 13:55:20 +0900 |
* m4/modue.c (SYMBOL_PREFIX): New macro for a symbol prefix.
(m4_module_import): Prepend SYMBOL_PREFIX.
(m4__module_open): Add .dll to suffixes for shared libraries.
Truncate a module name up to 8 characters.
Use a system path if m4_path_search() failed.
* m4/path.c (PATH_SEPARATOR): New macro for a PATH separator.
(FILE_SUFFIXES): Add .dll to search module with .dll extension.
(search_path_env_init): Use PATH_SEPARATOR to distinguish a path.
---
m4/module.c | 31 ++++++++++++++++++++++++++++---
m4/path.c | 9 ++++++++-
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/m4/module.c b/m4/module.c
index 6f2a2a9..a4351c3 100644
--- a/m4/module.c
+++ b/m4/module.c
@@ -67,6 +67,12 @@
#define MODULE_SELF_NAME "!myself!"
+#if OS2
+# define SYMBOL_PREFIX "_"
+#else
+# define SYMBOL_PREFIX ""
+#endif
+
static const char* module_dlerror (void);
static void install_builtin_table (m4*, m4_module *);
@@ -97,7 +103,9 @@ m4_module_import (m4 *context, const char *module_name,
if (module)
{
- symbol_address = dlsym (module->handle, symbol_name);
+ char *import_name = xasprintf (SYMBOL_PREFIX "%s", symbol_name);
+ symbol_address = dlsym (module->handle, import_name);
+ free (import_name);
if (!symbol_address)
m4_error (context, 0, 0, NULL,
@@ -265,14 +273,31 @@ compare_builtin_CB (const void *a, const void *b)
m4_module *
m4__module_open (m4 *context, const char *name, m4_obstack *obs)
{
- static const char * suffixes[] = { "", ".so", NULL };
+ static const char * suffixes[] = { "", ".so", ".dll", NULL };
m4_module * module = NULL;
assert (context);
+#if OS2
+ const char *saved_name = name;
+
+ /* OS/2 does not allow a module name longer than 8 characters. So truncate
+ a module name up to 8 characters. */
+ char os2name[8 + 1] = {'\0', };
+ name = strncpy (os2name, name, sizeof (os2name) - 1);
+#endif
+
char *filepath = m4_path_search (context, name, suffixes);
void *handle = NULL;
+#if OS2
+ /* if m4_path_search () fails, then use a system path. */
+ if (!filepath)
+ filepath = xstrdup (name);
+
+ name = saved_name;
+#endif
+
if (filepath)
{
handle = dlopen (filepath, RTLD_NOW|RTLD_GLOBAL);
@@ -296,7 +321,7 @@ m4__module_open (m4 *context, const char *name, m4_obstack
*obs)
/* Find and run any initializing function in the opened module,
the first time the module is opened. */
- char *entry_point = xasprintf ("include_%s", name);
+ char *entry_point = xasprintf (SYMBOL_PREFIX "include_%s", name);
m4_module_init_func *init_func =
(m4_module_init_func *) dlsym (handle, entry_point);
free (entry_point);
diff --git a/m4/path.c b/m4/path.c
index 3a93289..3f89951 100644
--- a/m4/path.c
+++ b/m4/path.c
@@ -37,11 +37,18 @@
/* Define this to see runtime debug info. Implied by DEBUG. */
/*#define DEBUG_INCL */
+#if OS2
+# define PATH_SEPARATOR ';'
+#else
+# define PATH_SEPARATOR ':'
+#endif
+
static const char *FILE_SUFFIXES[] = {
"",
".m4f",
".m4",
".so",
+ ".dll",
NULL
};
@@ -100,7 +107,7 @@ search_path_env_init (m4__search_path_info *info, char
*path, bool isabs)
do
{
- path_end = strchr (path, ':');
+ path_end = strchr (path, PATH_SEPARATOR);
if (path_end)
*path_end = '\0';
if (!isabs || *path == '/')
--
1.8.5.2
- [PATCH] OS/2 patches for master branch, try 2, KO Myung-Hun, 2014/11/19
- [PATCH 1/5] configury: support DLLs on OS/2, KO Myung-Hun, 2014/11/19
- [PATCH 4/5] configury: add -Zargs-resp to LDFLAGS on OS/2., KO Myung-Hun, 2014/11/19
- [PATCH 2/5] m4: support to load modules on OS/2,
KO Myung-Hun <=
- [PATCH 3/5] configury: append $EXEEXT suffix to the executable, /bin/sh, KO Myung-Hun, 2014/11/19
- Re: [PATCH] OS/2 patches for master branch, try 2, Gary V. Vaughan, 2014/11/20