enhanced module handling

This commit is contained in:
hyung-hwan 2012-11-02 14:08:46 +00:00
parent 86463296e4
commit 7557b22cb8
14 changed files with 193 additions and 113 deletions

View File

@ -3,8 +3,15 @@ AUTOMAKE_OPTIONS = nostdinc
AM_CPPFLAGS = \
-I$(top_builddir)/include \
-I$(top_srcdir)/include \
-I$(includedir) \
-DDEFAULT_MODDIR=\"$(libdir)/qse\" $(LTDLINCL)
-I$(includedir) $(LTDLINCL)
if WIN32
# you must adjust the value of DEFAULT_MODPOSTFIX according to
# -version-info in ../../mod/awk/Makefile.am
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\"
else
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\"
endif
#####################################################################3

View File

@ -34,8 +34,13 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
# you must adjust the value of DEFAULT_MODPOSTFIX according to
# -version-info in ../../mod/awk/Makefile.am
@WIN32_TRUE@am__append_1 = -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\"
@WIN32_FALSE@am__append_2 = -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\"
bin_PROGRAMS = qseawk$(EXEEXT)
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
@WCHAR_TRUE@@WIN32_TRUE@am__append_3 = $(UNICOWS_LIBS)
subdir = cmd/awk
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -252,15 +257,11 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = nostdinc
AM_CPPFLAGS = \
-I$(top_builddir)/include \
-I$(top_srcdir)/include \
-I$(includedir) \
-DDEFAULT_MODDIR=\"$(libdir)/qse\" $(LTDLINCL)
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
-I$(includedir) $(LTDLINCL) $(am__append_1) $(am__append_2)
qseawk_SOURCES = awk.c
qseawk_LDFLAGS = -L../../lib/awk -L../../lib/cmn -L$(libdir)
qseawk_LDADD = -lqseawk -lqsecmn $(LIBM) $(LIBLTDL) $(am__append_1)
qseawk_LDADD = -lqseawk -lqsecmn $(LIBM) $(LIBLTDL) $(am__append_3)
all: all-am
.SUFFIXES:

View File

@ -1172,7 +1172,7 @@ static void open_mpi (mpi_t* mpi, int argc, qse_achar_t* argv[])
goto oops;
}
mpi->h = lt_dlopenadvise (DEFAULT_MODDIR "/libawkmpi", adv);
mpi->h = lt_dlopenadvise (DEFAULT_MODPREFIX "mpi" DEFAULT_MODPOSTFIX, adv);
lt_dladvise_destroy (&adv);
if (mpi->h)

View File

@ -84,6 +84,8 @@ public:
typedef qse_awk_fnc_info_t fnc_info_t;
typedef qse_awk_mod_info_t mod_info_t;
class Run;
friend class Run;
@ -1224,7 +1226,7 @@ protected:
virtual flt_t exp (flt_t x) = 0;
virtual flt_t sqrt (flt_t x) = 0;
virtual void* modopen (const char_t* dir, const char_t* name) = 0;
virtual void* modopen (const mod_info_t* info) = 0;
virtual void modclose (void* handle) = 0;
virtual void* modsym (void* handle, const char_t* name) = 0;
@ -1263,7 +1265,7 @@ protected:
static flt_t exp (awk_t* awk, flt_t x);
static flt_t sqrt (awk_t* awk, flt_t x);
static void* modopen (awk_t* awk, const char_t* dir, const char_t* name);
static void* modopen (awk_t* awk, const mod_info_t* info);
static void modclose (awk_t* awk, void* handle);
static void* modsym (awk_t* awk, void* handle, const char_t* name);

View File

@ -200,7 +200,7 @@ protected:
flt_t exp (flt_t x);
flt_t sqrt (flt_t x);
void* modopen (const char_t* dir, const char_t* name);
void* modopen (const mod_info_t* info);
void modclose (void* handle);
void* modsym (void* handle, const char_t* name);

View File

@ -414,10 +414,18 @@ typedef qse_flt_t (*qse_awk_math2_t) (
qse_flt_t y
);
typedef struct qse_awk_mod_info_t qse_awk_mod_info_t;
struct qse_awk_mod_info_t
{
const qse_char_t* prefix;
const qse_char_t* postfix;
const qse_char_t* name;
};
typedef void* (*qse_awk_modopen_t) (
qse_awk_t* awk,
const qse_char_t* dir,
const qse_char_t* name
qse_awk_t* awk,
const qse_awk_mod_info_t* info
);
typedef void* (*qse_awk_modsym_t) (
@ -821,6 +829,7 @@ struct qse_awk_mod_sym_t
} u;
};
/* ------------------------------------------------------------------------ */
/**
@ -911,7 +920,9 @@ struct qse_awk_rtx_ecb_t
enum qse_awk_opt_t
{
QSE_AWK_TRAIT = 0,
QSE_AWK_MODDIR,
QSE_AWK_MODPREFIX,
QSE_AWK_MODPOSTFIX,
QSE_AWK_DEPTH_INCLUDE,
QSE_AWK_DEPTH_BLOCK_PARSE,

View File

@ -2012,10 +2012,10 @@ Awk::flt_t Awk::sqrt (awk_t* awk, flt_t x)
return xtn->awk->sqrt (x);
}
void* Awk::modopen (awk_t* awk, const char_t* dir, const char_t* name)
void* Awk::modopen (awk_t* awk, const mod_info_t* info)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
return xtn->awk->modopen (dir, name);
return xtn->awk->modopen (info);
}
void Awk::modclose (awk_t* awk, void* handle)

View File

@ -3,8 +3,15 @@ AUTOMAKE_OPTIONS = nostdinc
AM_CPPFLAGS = \
-I$(top_builddir)/include \
-I$(top_srcdir)/include \
-I$(includedir) \
-DDEFAULT_MODDIR=\"$(libdir)\" $(LTDLINCL)
-I$(includedir) $(LTDLINCL)
if WIN32
# you must adjust the value of DEFAULT_MODPOSTFIX according to
# -version-info in ../../mod/awk/Makefile.am
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\"
else
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\"
endif
lib_LTLIBRARIES = libqseawk.la
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c rio.c std.c awk.h err.h rio.h val.h fnc.h misc.h parse.h run.h tree.h

View File

@ -34,7 +34,12 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
@ENABLE_CXX_TRUE@am__append_1 = libqseawkxx.la
# you must adjust the value of DEFAULT_MODPOSTFIX according to
# -version-info in ../../mod/awk/Makefile.am
@WIN32_TRUE@am__append_1 = -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\"
@WIN32_FALSE@am__append_2 = -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\"
@ENABLE_CXX_TRUE@am__append_3 = libqseawkxx.la
subdir = lib/awk
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -297,13 +302,9 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = nostdinc
AM_CPPFLAGS = \
-I$(top_builddir)/include \
-I$(top_srcdir)/include \
-I$(includedir) \
-DDEFAULT_MODDIR=\"$(libdir)\" $(LTDLINCL)
lib_LTLIBRARIES = libqseawk.la $(am__append_1)
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
-I$(includedir) $(LTDLINCL) $(am__append_1) $(am__append_2)
lib_LTLIBRARIES = libqseawk.la $(am__append_3)
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c fnc.c misc.c rio.c std.c awk.h err.h rio.h val.h fnc.h misc.h parse.h run.h tree.h
libqseawk_la_LDFLAGS = -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined
libqseawk_la_LIBADD = -lqsecmn $(LIBM) $(LIBLTDL)

View File

@ -1394,22 +1394,19 @@ StdAwk::flt_t StdAwk::sqrt (flt_t x)
#endif
}
void* StdAwk::modopen (const qse_char_t* dir, const qse_char_t* name)
void* StdAwk::modopen (const mod_info_t* info)
{
#if defined(USE_LTDL)
void* h;
qse_mchar_t* modpath;
const qse_char_t* tmp[5];
int count = 0;
const qse_char_t* tmp[4];
int count;
if (dir && dir[0] != QSE_T('\0'))
{
tmp[count++] = dir;
tmp[count++] = QSE_T("/");
}
tmp[count++] = QSE_T("libqseawk-");
tmp[count++] = name;
count = 0;
if (info->prefix) tmp[count++] = info->prefix;
tmp[count++] = info->name;
if (info->postfix) tmp[count++] = info->postfix;
tmp[count] = QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR)
@ -1430,14 +1427,66 @@ void* StdAwk::modopen (const qse_char_t* dir, const qse_char_t* name)
return h;
#elif defined(_WIN32)
/*TODO: implemente this - use LoadLibrary... */
this->setError (QSE_AWK_ENOIMPL);
return QSE_NULL;
HMODULE h;
qse_char_t* path;
const qse_char_t* tmp[4];
int count;
count = 0;
if (info->prefix) tmp[count++] = info->prefix;
tmp[count++] = info->name;
if (info->postfix) tmp[count++] = info->postfix;
tmp[count] = QSE_NULL;
path = qse_stradup (tmp, QSE_NULL, this->getMmgr());
if (!path)
{
this->setError (QSE_AWK_ENOMEM);
return QSE_NULL;
}
h = LoadLibrary (path);
QSE_MMGR_FREE (awk->mmgr, path);
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h;
#elif defined(__OS2__)
/*TODO: implemente this */
this->setError (QSE_AWK_ENOIMPL);
return QSE_NULL;
void* h;
qse_mchar_t* modpath;
const qse_char_t* tmp[4];
int count;
UCHAR errbuf[CCHMAXPATH];
count = 0;
if (info->prefix) tmp[count++] = info->prefix;
tmp[count++] = info->name;
if (info->postfix) tmp[count++] = info->postfix;
tmp[count] = QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR)
modpath = qse_mbsadup (tmp, QSE_NULL, this->getMmgr());
#else
modpath = qse_wcsatombsdup (tmp, QSE_NULL, this->getMmgr());
#endif
if (!modpath)
{
this->setError (QSE_AWK_ENOMEM);
return QSE_NULL;
}
if (DosLoadModule (errbuf, QSE_COUNTOF(errbuf) - 1, modpath, &h) != NO_ERROR) h = QSE_NULL;
QSE_MMGR_FREE (awk->mmgr, modpath);
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h;
#elif defined(__DOS__)
/*TODO: implemente this */
this->setError (QSE_AWK_ENOIMPL);
return QSE_NULL;
@ -1456,7 +1505,7 @@ void StdAwk::modclose (void* handle)
#elif defined(_WIN32)
FreeLibrary ((HMODULE)handle);
#elif defined(__OS2__)
/*TODO: implemente this */
DosFreeModule ((HMODULE)handle);
#elif defined(__DOS__)
/*TODO: implemente this */
#else
@ -1469,24 +1518,23 @@ void* StdAwk::modsym (void* handle, const qse_char_t* name)
void* s;
qse_mchar_t* mname;
#if defined(QSE_CHAR_IS_MCHAR)
#if defined(QSE_CHAR_IS_MCHAR)
mname = name;
#else
#else
mname = qse_wcstombsdup (name, QSE_NULL, this->getMmgr());
if (!mname)
{
this->setError (QSE_AWK_ENOMEM);
return QSE_NULL;
}
#endif
#endif
#if defined(USE_LTDL)
s = lt_dlsym ((lt_dlhandle)handle, mname);
#elif defined(_WIN32)
s = (void*)GetProcAddress ((HMODULE)handle, mname);
#elif defined(__OS2__)
/*TODO: implemente this */
s = QSE_NULL;
if (DosQueryProcAddr ((HMODULE)handle, 0, mname, (PFN*)&s) != NO_ERROR) s = QSE_NULL;
#elif defined(__DOS__)
/*TODO: implemente this */
s = QSE_NULL;
@ -1494,11 +1542,11 @@ void* StdAwk::modsym (void* handle, const qse_char_t* name)
s = QSE_NULL;
#endif
#if defined(QSE_CHAR_IS_MCHAR)
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing to do */
#else
#else
QSE_MMGR_FREE (awk->mmgr, mname);
#endif
#endif
return s;

View File

@ -269,6 +269,7 @@ oops:
int qse_awk_close (qse_awk_t* awk)
{
qse_awk_ecb_t* ecb;
int i;
if (qse_awk_clear (awk) <= -1) return -1;
/*qse_awk_clrfnc (awk);*/
@ -293,8 +294,11 @@ int qse_awk_close (qse_awk_t* awk)
fini_token (&awk->ptok);
/* destroy dynamically allocated options */
if (awk->opt.moddir.ptr)
QSE_MMGR_FREE (awk->mmgr, awk->opt.moddir.ptr);
for (i = 0; i < QSE_COUNTOF(awk->opt.mod); i++)
{
if (awk->opt.mod[i].ptr)
QSE_MMGR_FREE (awk->mmgr, awk->opt.mod[i].ptr);
}
/* QSE_AWK_ALLOC, QSE_AWK_FREE, etc can not be used
* from the next line onwards */
@ -436,10 +440,13 @@ int qse_awk_setopt (qse_awk_t* awk, qse_awk_opt_t id, const void* value)
awk->opt.trait = *(const int*)value;
return 0;
case QSE_AWK_MODDIR:
case QSE_AWK_MODPREFIX:
case QSE_AWK_MODPOSTFIX:
{
qse_xstr_t tmp;
int idx;
idx = id - QSE_AWK_MODPREFIX;
if (value)
{
tmp.ptr = qse_strdup (value, awk->mmgr);
@ -456,10 +463,10 @@ int qse_awk_setopt (qse_awk_t* awk, qse_awk_opt_t id, const void* value)
tmp.len = 0;
}
if (awk->opt.moddir.ptr)
QSE_MMGR_FREE (awk->mmgr, awk->opt.moddir.ptr);
if (awk->opt.mod[idx].ptr)
QSE_MMGR_FREE (awk->mmgr, awk->opt.mod[idx].ptr);
awk->opt.moddir = tmp;
awk->opt.mod[idx] = tmp;
return 0;
}
@ -486,11 +493,11 @@ int qse_awk_getopt (qse_awk_t* awk, qse_awk_opt_t id, void* value)
*(int*)value = awk->opt.trait;
return 0;
case QSE_AWK_MODDIR:
*(const qse_char_t**)value = awk->opt.moddir.ptr;
case QSE_AWK_MODPREFIX:
case QSE_AWK_MODPOSTFIX:
*(const qse_char_t**)value = awk->opt.mod[id - QSE_AWK_MODPREFIX].ptr;
return 0;
case QSE_AWK_DEPTH_INCLUDE:
case QSE_AWK_DEPTH_BLOCK_PARSE:
case QSE_AWK_DEPTH_BLOCK_RUN:

View File

@ -123,7 +123,7 @@ struct qse_awk_t
struct
{
int trait;
qse_xstr_t moddir;
qse_xstr_t mod[2];
union
{

View File

@ -25,9 +25,6 @@ enum tok_t
TOK_EOF,
TOK_NEWLINE,
/* special token to direct the parser to include a file specified */
TOK_INCLUDE,
/* TOK_XXX_ASSNs should be in sync with assop in assign_to_opcode.
* it also should be in the order as qse_awk_assop_type_t in run.h */
TOK_ASSN,
@ -274,7 +271,6 @@ static kwent_t kwtab[] =
{ { QSE_T("global"), 6 }, TOK_GLOBAL, QSE_AWK_EXPLICIT },
{ { QSE_T("if"), 2 }, TOK_IF, 0 },
{ { QSE_T("in"), 2 }, TOK_IN, 0 },
{ { QSE_T("include"), 7 }, TOK_INCLUDE, QSE_AWK_EXTRAKWS },
{ { QSE_T("local"), 5 }, TOK_LOCAL, QSE_AWK_EXPLICIT },
{ { QSE_T("next"), 4 }, TOK_NEXT, QSE_AWK_PABLOCK },
{ { QSE_T("nextfile"), 8 }, TOK_NEXTFILE, QSE_AWK_PABLOCK },
@ -836,7 +832,8 @@ static int parse_progunit (qse_awk_t* awk)
{
if (get_token(awk) <= -1) return -1;
if (MATCH(awk,TOK_INCLUDE)) /* TOOD: INCLUDE must not be a separate keyword... */
if (MATCH(awk,TOK_IDENT) &&
qse_strcmp (QSE_STR_PTR(awk->tok.name), QSE_T("include")) == 0)
{
if (awk->opt.depth.s.incl > 0 &&
awk->parse.depth.incl >= awk->opt.depth.s.incl)
@ -6450,25 +6447,30 @@ static qse_awk_mod_t* query_module (
else
{
qse_awk_mod_load_t load;
const qse_char_t* moddir;
qse_awk_mod_info_t info;
qse_awk_mod_data_t md;
if (awk->opt.moddir.len > 0)
{
moddir = awk->opt.moddir.ptr;
}
#if defined(DEFAULT_MODDIR)
else
{
moddir = QSE_T(DEFAULT_MODDIR);
}
QSE_MEMSET (&info, 0, QSE_SIZEOF(info));
if (awk->opt.mod[0].len > 0)
info.prefix = awk->opt.mod[0].ptr;
#if defined(DEFAULT_MODPREFIX)
else info.prefix = QSE_T(DEFAULT_MODPREFIX);
#endif
if (awk->opt.mod[1].len > 0)
info.postfix = awk->opt.mod[1].ptr;
#if defined(DEFAULT_MODPOSTFIX)
else info.postfix = QSE_T(DEFAULT_MODPOSTFIX);
#endif
QSE_MEMSET (&md, 0, QSE_SIZEOF(md));
if (awk->prm.modopen && awk->prm.modsym && awk->prm.modclose)
md.handle = awk->prm.modopen (awk, moddir, segs[0].ptr);
else
md.handle = QSE_NULL;
{
info.name = segs[0].ptr;
md.handle = awk->prm.modopen (awk, &info);
}
else md.handle = QSE_NULL;
if (!md.handle)
{

View File

@ -46,6 +46,7 @@
# endif
#elif defined(__OS2__)
# define INCL_DOSMODULEMGR
# define INCL_DOSPROCESS
# define INCL_DOSERRORS
# include <os2.h>
#elif defined(__DOS__)
@ -314,23 +315,18 @@ static int custom_awk_sprintf (
return n;
}
static void* custom_awk_modopen (
qse_awk_t* awk, const qse_char_t* dir, const qse_char_t* name)
static void* custom_awk_modopen (qse_awk_t* awk, const qse_awk_mod_info_t* info)
{
#if defined(USE_LTDL)
void* h;
qse_mchar_t* modpath;
const qse_char_t* tmp[6];
const qse_char_t* tmp[4];
int count;
count = 0;
if (dir && dir[0] != QSE_T('\0'))
{
tmp[count++] = dir;
tmp[count++] = QSE_T("/");
}
tmp[count++] = QSE_T("libqseawk-");
tmp[count++] = name;
if (info->prefix) tmp[count++] = info->prefix;
tmp[count++] = info->name;
if (info->postfix) tmp[count++] = info->postfix;
tmp[count] = QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR)
@ -351,19 +347,16 @@ static void* custom_awk_modopen (
return h;
#elif defined(_WIN32)
HMODULE h;
qse_char_t* path;
const qse_char_t* tmp[5];
int count = 0;
const qse_char_t* tmp[4];
int count;
if (dir && dir[0] != QSE_T('\0'))
{
tmp[count++] = dir;
tmp[count++] = QSE_T("/");
}
tmp[count++] = QSE_T("libqseawk-");
tmp[count++] = name;
count = 0;
if (info->prefix) tmp[count++] = info->prefix;
tmp[count++] = info->name;
if (info->postfix) tmp[count++] = info->postfix;
tmp[count] = QSE_NULL;
path = qse_stradup (tmp, QSE_NULL, awk->mmgr);
@ -377,21 +370,21 @@ static void* custom_awk_modopen (
QSE_MMGR_FREE (awk->mmgr, path);
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h;
#elif defined(__OS2__)
HMODULE h;
qse_mchar_t* modpath;
const qse_char_t* tmp[6];
const qse_char_t* tmp[4];
int count;
UCHAR errbuf[CCHMAXPATH];
count = 0;
if (dir && dir[0] != QSE_T('\0'))
{
tmp[count++] = dir;
tmp[count++] = QSE_T("/");
}
tmp[count++] = QSE_T("libqseawk-");
tmp[count++] = name;
if (info->prefix) tmp[count++] = info->prefix;
tmp[count++] = info->name;
if (info->postfix) tmp[count++] = info->postfix;
tmp[count] = QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR)
@ -405,10 +398,11 @@ static void* custom_awk_modopen (
return QSE_NULL;
}
if (DosLoadModule (errbuf, QSE_COUNTOF(errbuf), modpath, &h) != NO_ERROR) h = QSE_NULL;
if (DosLoadModule (errbuf, QSE_COUNTOF(errbuf) - 1, modpath, &h) != NO_ERROR) h = QSE_NULL;
QSE_MMGR_FREE (awk->mmgr, modpath);
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
return h;
#elif defined(__DOS__)
@ -452,7 +446,7 @@ static void* custom_awk_modsym (qse_awk_t* awk, void* handle, const qse_char_t*
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL;
}
#endif
#endif
#if defined(USE_LTDL)
s = lt_dlsym (handle, mname);