allowed to use dynamic loader even if QSE_ENABLE_STATIC_MODULE is defined

This commit is contained in:
hyung-hwan 2014-11-14 02:31:47 +00:00
parent 206781ce27
commit 3db3396955
4 changed files with 64 additions and 76 deletions

View File

@ -356,20 +356,31 @@ static void on_statement (qse_awk_rtx_t* rtx, qse_awk_nde_t* nde)
static void print_version (void) static void print_version (void)
{ {
qse_fprintf (QSE_STDOUT, QSE_T("QSEAWK %hs\n"), QSE_PACKAGE_VERSION); qse_sio_putstrf (QSE_STDOUT, QSE_T("QSEAWK %hs\n"), QSE_PACKAGE_VERSION);
qse_fprintf (QSE_STDOUT, QSE_T("Copyright 2006-2014 Chung, Hyung-Hwan\n")); qse_sio_putstrf (QSE_STDOUT, QSE_T("Copyright 2006-2014 Chung, Hyung-Hwan\n"));
} }
static void print_error (const qse_char_t* fmt, ...) static void print_error (const qse_char_t* fmt, ...)
{ {
va_list va; va_list va;
qse_fprintf (QSE_STDERR, QSE_T("ERROR: ")); qse_sio_putstr (QSE_STDERR, QSE_T("ERROR: "));
va_start (va, fmt); va_start (va, fmt);
qse_sio_putstrvf (QSE_STDERR, fmt, va); qse_sio_putstrvf (QSE_STDERR, fmt, va);
va_end (va); va_end (va);
} }
static void print_warning (const qse_char_t* fmt, ...)
{
va_list va;
qse_sio_putstr (QSE_STDERR, QSE_T("WARNING: "));
va_start (va, fmt);
qse_sio_putstrvf (QSE_STDERR, fmt, va);
va_end (va);
}
struct opttab_t struct opttab_t
{ {
const qse_char_t* name; const qse_char_t* name;
@ -1282,7 +1293,7 @@ int qse_main (int argc, qse_achar_t* argv[])
/* TODO: add an option to skip watt-32 */ /* TODO: add an option to skip watt-32 */
_watt_do_exit = 0; /* prevent sock_init from exiting upon failure */ _watt_do_exit = 0; /* prevent sock_init from exiting upon failure */
if (sock_init() != 0) if (sock_init() != 0)
print_error (QSE_T("Failed to initialize watt-32\n")); print_warning (QSE_T("Failed to initialize watt-32\n"));
else sock_inited = 1; else sock_inited = 1;
#endif #endif

View File

@ -6697,7 +6697,6 @@ static qse_awk_mod_t* query_module (
QSE_ASSERT (nsegs == 2); QSE_ASSERT (nsegs == 2);
pair = qse_rbt_search (awk->modtab, segs[0].ptr, segs[0].len); pair = qse_rbt_search (awk->modtab, segs[0].ptr, segs[0].len);
if (pair) if (pair)
{ {
@ -6706,7 +6705,7 @@ static qse_awk_mod_t* query_module (
else else
{ {
qse_awk_mod_data_t md; qse_awk_mod_data_t md;
qse_awk_mod_load_t load; qse_awk_mod_load_t load = QSE_NULL;
qse_awk_mod_spec_t spec; qse_awk_mod_spec_t spec;
qse_size_t buflen; qse_size_t buflen;
/*qse_char_t buf[64 + 15] = QSE_T("_qse_awk_mod_");*/ /*qse_char_t buf[64 + 15] = QSE_T("_qse_awk_mod_");*/
@ -6738,6 +6737,8 @@ static qse_awk_mod_t* query_module (
} }
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(QSE_ENABLE_STATIC_MODULE)
/* attempt to find a statically linked module */
/* TODO: binary search ... */ /* TODO: binary search ... */
for (n = 0; n < QSE_COUNTOF(static_modtab); n++) for (n = 0; n < QSE_COUNTOF(static_modtab); n++)
{ {
@ -6748,15 +6749,21 @@ static qse_awk_mod_t* query_module (
} }
} }
if (n >= QSE_COUNTOF(static_modtab)) /*if (n >= QSE_COUNTOF(static_modtab))
{ {
ea.ptr = segs[0].ptr; ea.ptr = segs[0].ptr;
ea.len = segs[0].len; ea.len = segs[0].len;
qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL); qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }*/
if (load)
{
/* found the module in the staic module table */
QSE_MEMSET (&md, 0, QSE_SIZEOF(md)); QSE_MEMSET (&md, 0, QSE_SIZEOF(md));
/* Note md.handle is QSE_NULL for a static module */
/* i copy-insert 'md' into the table before calling 'load'. /* i copy-insert 'md' into the table before calling 'load'.
* to pass the same address to load(), query(), etc */ * to pass the same address to load(), query(), etc */
@ -6774,8 +6781,11 @@ static qse_awk_mod_t* query_module (
return QSE_NULL; return QSE_NULL;
} }
#else goto done;
}
#endif
/* attempt to find an external module */
QSE_MEMSET (&spec, 0, QSE_SIZEOF(spec)); QSE_MEMSET (&spec, 0, QSE_SIZEOF(spec));
if (awk->opt.mod[0].len > 0) if (awk->opt.mod[0].len > 0)
@ -6844,9 +6854,9 @@ static qse_awk_mod_t* query_module (
awk->prm.modclose (awk, mdp->handle); awk->prm.modclose (awk, mdp->handle);
return QSE_NULL; return QSE_NULL;
} }
#endif
} }
done:
n = mdp->mod.query (&mdp->mod, awk, segs[1].ptr, sym); n = mdp->mod.query (&mdp->mod, awk, segs[1].ptr, sym);
return (n <= -1)? QSE_NULL: &mdp->mod; return (n <= -1)? QSE_NULL: &mdp->mod;
} }

View File

@ -177,10 +177,7 @@ qse_awk_flt_t qse_awk_stdmathmod (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t
int qse_awk_stdmodstartup (qse_awk_t* awk) int qse_awk_stdmodstartup (qse_awk_t* awk)
{ {
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(USE_LTDL)
return 0;
#elif defined(USE_LTDL)
/* lt_dlinit() can be called more than once and /* lt_dlinit() can be called more than once and
* lt_dlexit() shuts down libltdl if it's called as many times as * lt_dlexit() shuts down libltdl if it's called as many times as
* corresponding lt_dlinit(). so it's safe to call lt_dlinit() * corresponding lt_dlinit(). so it's safe to call lt_dlinit()
@ -195,10 +192,7 @@ int qse_awk_stdmodstartup (qse_awk_t* awk)
void qse_awk_stdmodshutdown (qse_awk_t* awk) void qse_awk_stdmodshutdown (qse_awk_t* awk)
{ {
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(USE_LTDL)
/* do nothign */
#elif defined(USE_LTDL)
lt_dlexit (); lt_dlexit ();
@ -209,13 +203,7 @@ void qse_awk_stdmodshutdown (qse_awk_t* awk)
void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec) void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
{ {
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(USE_LTDL)
/* this won't be called at all when modules are linked into
* the main library. */
qse_awk_seterrnum (awk, QSE_AWK_ENOIMPL, QSE_NULL);
return QSE_NULL;
#elif defined(USE_LTDL)
void* h; void* h;
qse_mchar_t* modpath; qse_mchar_t* modpath;
const qse_char_t* tmp[4]; const qse_char_t* tmp[4];
@ -307,10 +295,10 @@ void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*)); QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h; return h;
#elif defined(__DOS__) #elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
/* the DOS code here is not generic enough. it's for a specific /* the DOS code here is not generic enough. it's for a specific
* dos-extender only. the best is to enable QSE_ENABLE_STATIC_MODULE * dos-extender only. the best is not to use dynamic loading
* when building for DOS. */ * when building for DOS. */
void* h; void* h;
qse_mchar_t* modpath; qse_mchar_t* modpath;
@ -349,16 +337,13 @@ void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
void qse_awk_stdmodclose (qse_awk_t* awk, void* handle) void qse_awk_stdmodclose (qse_awk_t* awk, void* handle)
{ {
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(USE_LTDL)
/* this won't be called at all when modules are linked into
* the main library. */
#elif defined(USE_LTDL)
lt_dlclose (handle); lt_dlclose (handle);
#elif defined(_WIN32) #elif defined(_WIN32)
FreeLibrary ((HMODULE)handle); FreeLibrary ((HMODULE)handle);
#elif defined(__OS2__) #elif defined(__OS2__)
DosFreeModule ((HMODULE)handle); DosFreeModule ((HMODULE)handle);
#elif defined(__DOS__) #elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
FreeModule (handle); FreeModule (handle);
#else #else
/* nothing to do */ /* nothing to do */
@ -381,12 +366,7 @@ void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name)
} }
#endif #endif
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(USE_LTDL)
/* this won't be called at all when modules are linked into
* the main library. */
s = QSE_NULL;
#elif defined(USE_LTDL)
s = lt_dlsym (handle, mname); s = lt_dlsym (handle, mname);
#elif defined(_WIN32) #elif defined(_WIN32)
@ -395,7 +375,7 @@ void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name)
#elif defined(__OS2__) #elif defined(__OS2__)
if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL; if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL;
#elif defined(__DOS__) #elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
s = GetProcAddress (handle, mname); s = GetProcAddress (handle, mname);
#else #else

View File

@ -8,12 +8,7 @@
static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname) static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
{ {
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(USE_LTDL)
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
return QSE_NULL;
#elif defined(USE_LTDL)
void* h; void* h;
qse_mchar_t* modpath; qse_mchar_t* modpath;
@ -85,10 +80,10 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*)); QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h; return h;
#elif defined(__DOS__) #elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
/* the DOS code here is not generic enough. it's for a specific /* the DOS code here is not generic enough. it's for a specific
* dos-extender only. the best is to enable QSE_ENABLE_STATIC_MODULE * dos-extender only. the best is to disable dynamic loading
* when building for DOS. */ * when building for DOS. */
void* h; void* h;
qse_mchar_t* modpath; qse_mchar_t* modpath;
@ -124,16 +119,13 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
static void mod_close (qse_httpd_t* httpd, void* handle) static void mod_close (qse_httpd_t* httpd, void* handle)
{ {
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(USE_LTDL)
/* this won't be called at all when modules are linked into
* the main library. */
#elif defined(USE_LTDL)
lt_dlclose (handle); lt_dlclose (handle);
#elif defined(_WIN32) #elif defined(_WIN32)
FreeLibrary ((HMODULE)handle); FreeLibrary ((HMODULE)handle);
#elif defined(__OS2__) #elif defined(__OS2__)
DosFreeModule ((HMODULE)handle); DosFreeModule ((HMODULE)handle);
#elif defined(__DOS__) #elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
FreeModule (handle); FreeModule (handle);
#else #else
/* nothing to do */ /* nothing to do */
@ -157,12 +149,7 @@ static void* mod_symbol (qse_httpd_t* httpd, void* handle, const qse_char_t* nam
#endif #endif
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(USE_LTDL)
/* this won't be called at all when modules are linked into
* the main library. */
s = QSE_NULL;
#elif defined(USE_LTDL)
s = lt_dlsym (handle, mname); s = lt_dlsym (handle, mname);
if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno)); if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
#elif defined(_WIN32) #elif defined(_WIN32)
@ -178,7 +165,7 @@ static void* mod_symbol (qse_httpd_t* httpd, void* handle, const qse_char_t* nam
s = QSE_NULL; s = QSE_NULL;
} }
} }
#elif defined(__DOS__) #elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
s = GetProcAddress (handle, mname); s = GetProcAddress (handle, mname);
if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno)); if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
#else #else