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)
{
qse_fprintf (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("QSEAWK %hs\n"), QSE_PACKAGE_VERSION);
qse_sio_putstrf (QSE_STDOUT, QSE_T("Copyright 2006-2014 Chung, Hyung-Hwan\n"));
}
static void print_error (const qse_char_t* fmt, ...)
{
va_list va;
qse_fprintf (QSE_STDERR, QSE_T("ERROR: "));
qse_sio_putstr (QSE_STDERR, QSE_T("ERROR: "));
va_start (va, fmt);
qse_sio_putstrvf (QSE_STDERR, fmt, 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
{
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 */
_watt_do_exit = 0; /* prevent sock_init from exiting upon failure */
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;
#endif

View File

@ -6697,7 +6697,6 @@ static qse_awk_mod_t* query_module (
QSE_ASSERT (nsegs == 2);
pair = qse_rbt_search (awk->modtab, segs[0].ptr, segs[0].len);
if (pair)
{
@ -6706,7 +6705,7 @@ static qse_awk_mod_t* query_module (
else
{
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_size_t buflen;
/*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)
/* attempt to find a statically linked module */
/* TODO: binary search ... */
for (n = 0; n < QSE_COUNTOF(static_modtab); n++)
{
@ -6748,34 +6749,43 @@ 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.len = segs[0].len;
qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL);
return QSE_NULL;
}
}*/
QSE_MEMSET (&md, 0, QSE_SIZEOF(md));
/* i copy-insert 'md' into the table before calling 'load'.
* to pass the same address to load(), query(), etc */
pair = qse_rbt_insert (awk->modtab, segs[0].ptr, segs[0].len, &md, QSE_SIZEOF(md));
if (pair == QSE_NULL)
if (load)
{
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL;
/* found the module in the staic module table */
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'.
* to pass the same address to load(), query(), etc */
pair = qse_rbt_insert (awk->modtab, segs[0].ptr, segs[0].len, &md, QSE_SIZEOF(md));
if (pair == QSE_NULL)
{
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL;
}
mdp = (qse_awk_mod_data_t*)QSE_RBT_VPTR(pair);
if (load (&mdp->mod, awk) <= -1)
{
qse_rbt_delete (awk->modtab, segs[0].ptr, segs[0].len);
return QSE_NULL;
}
goto done;
}
#endif
mdp = (qse_awk_mod_data_t*)QSE_RBT_VPTR(pair);
if (load (&mdp->mod, awk) <= -1)
{
qse_rbt_delete (awk->modtab, segs[0].ptr, segs[0].len);
return QSE_NULL;
}
#else
/* attempt to find an external module */
QSE_MEMSET (&spec, 0, QSE_SIZEOF(spec));
if (awk->opt.mod[0].len > 0)
@ -6844,9 +6854,9 @@ static qse_awk_mod_t* query_module (
awk->prm.modclose (awk, mdp->handle);
return QSE_NULL;
}
#endif
}
done:
n = mdp->mod.query (&mdp->mod, awk, segs[1].ptr, sym);
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)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
return 0;
#elif defined(USE_LTDL)
#if defined(USE_LTDL)
/* lt_dlinit() can be called more than once and
* lt_dlexit() shuts down libltdl if it's called as many times as
* 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)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
/* do nothign */
#elif defined(USE_LTDL)
#if defined(USE_LTDL)
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)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
/* 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)
#if defined(USE_LTDL)
void* h;
qse_mchar_t* modpath;
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*));
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
* 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. */
void* h;
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)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
/* this won't be called at all when modules are linked into
* the main library. */
#elif defined(USE_LTDL)
#if defined(USE_LTDL)
lt_dlclose (handle);
#elif defined(_WIN32)
FreeLibrary ((HMODULE)handle);
#elif defined(__OS2__)
DosFreeModule ((HMODULE)handle);
#elif defined(__DOS__)
#elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
FreeModule (handle);
#else
/* nothing to do */
@ -381,12 +366,7 @@ void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name)
}
#endif
#if defined(QSE_ENABLE_STATIC_MODULE)
/* this won't be called at all when modules are linked into
* the main library. */
s = QSE_NULL;
#elif defined(USE_LTDL)
#if defined(USE_LTDL)
s = lt_dlsym (handle, mname);
#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__)
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);
#else

View File

@ -8,12 +8,7 @@
static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
return QSE_NULL;
#elif defined(USE_LTDL)
#if defined(USE_LTDL)
void* h;
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*));
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
* 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. */
void* h;
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)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
/* this won't be called at all when modules are linked into
* the main library. */
#elif defined(USE_LTDL)
#if defined(USE_LTDL)
lt_dlclose (handle);
#elif defined(_WIN32)
FreeLibrary ((HMODULE)handle);
#elif defined(__OS2__)
DosFreeModule ((HMODULE)handle);
#elif defined(__DOS__)
#elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
FreeModule (handle);
#else
/* nothing to do */
@ -157,12 +149,7 @@ static void* mod_symbol (qse_httpd_t* httpd, void* handle, const qse_char_t* nam
#endif
#if defined(QSE_ENABLE_STATIC_MODULE)
/* this won't be called at all when modules are linked into
* the main library. */
s = QSE_NULL;
#elif defined(USE_LTDL)
#if defined(USE_LTDL)
s = lt_dlsym (handle, mname);
if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
#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;
}
}
#elif defined(__DOS__)
#elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE)
s = GetProcAddress (handle, mname);
if (s == QSE_NULL) qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
#else