From 80ce6d25bb2b66fc18694a318696fb0bb63054b8 Mon Sep 17 00:00:00 2001 From: DSPOM Date: Tue, 10 May 2022 10:38:25 +0200 Subject: [PATCH] feat: implement log message callback --- src/Makefile.am | 5 ++++- src/osdi/Makefile.am | 1 + src/osdi/osdiinit.c | 40 ++++++++++++++++++++++++++++++++++++---- src/osdi/osdiload.c | 2 +- src/osdi/osdiregistry.c | 2 +- src/osdi/osdisetup.c | 2 +- 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 96170761c..a9bb994d8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -120,8 +120,10 @@ ngspice_SOURCES = \ ngspice_CPPFLAGS = $(AM_CPPFLAGS) -DSIMULATOR if WINGUI -ngspice_LDFLAGS = -municode $(AM_LDFLAGS) +ngspice_LDFLAGS = -municode $(AM_LDFLAGS) -ldl ngspice_SOURCES += winmain.c hist_info.c +else +ngspice_LDFLAGS = endif ngspice_LDADD = \ @@ -183,6 +185,7 @@ endif if OSDI_WANTED ngspice_LDADD += osdi/libosdi.la +ngspice_LDFLAGS += -Wl,--dynamic-list=$(top_srcdir)/src/osdi/exported.txt endif ngspice_LDADD += \ diff --git a/src/osdi/Makefile.am b/src/osdi/Makefile.am index 2789ccf7d..77ee8a9c5 100644 --- a/src/osdi/Makefile.am +++ b/src/osdi/Makefile.am @@ -13,6 +13,7 @@ libosdi_la_SOURCES = \ osdiregistry.c \ osdisetup.c \ osdiitf.h + exported.txt diff --git a/src/osdi/osdiinit.c b/src/osdi/osdiinit.c index d7e6028c4..dbefa4666 100644 --- a/src/osdi/osdiinit.c +++ b/src/osdi/osdiinit.c @@ -86,11 +86,11 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) { // allocate and fill instance params (and opvars) int *num_instance_para_names = TMALLOC(int, 1); for (uint32_t i = 0; i < descr->num_instance_params; i++) { - *num_instance_para_names += (int) (1 + descr->param_opvar[i].num_alias); + *num_instance_para_names += (int)(1 + descr->param_opvar[i].num_alias); } for (uint32_t i = descr->num_params; i < descr->num_opvars + descr->num_params; i++) { - *num_instance_para_names += (int) (1 + descr->param_opvar[i].num_alias); + *num_instance_para_names += (int)(1 + descr->param_opvar[i].num_alias); } if (entry->dt != UINT32_MAX) { *num_instance_para_names += 1; @@ -121,7 +121,7 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) { // allocate and fill model params int *num_model_para_names = TMALLOC(int, 1); for (uint32_t i = descr->num_instance_params; i < descr->num_params; i++) { - *num_model_para_names += (int) (1 + descr->param_opvar[i].num_alias); + *num_model_para_names += (int)(1 + descr->param_opvar[i].num_alias); } IFparm *model_para_names = TMALLOC(IFparm, *num_model_para_names); dst = model_para_names; @@ -143,7 +143,7 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) { .numModelParms = num_model_para_names, .modelParms = model_para_names, .flags = DEV_DEFAULT, - .registry_entry = (void*) entry, + .registry_entry = (void *)entry, }; size_t inst_off = entry->inst_offset; @@ -170,3 +170,35 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) { return OSDIinfo; } + +extern FILE *osdi_init_log_message(void *handle_, uint32_t lvl) { + OsdiNgspiceHandle *handle = handle_; + switch (lvl) { + case LOG_LVL_DEBUG: + fprintf(stdout, "OSDI(debug) %s: ", handle->name); + break; + case LOG_LVL_INFO: + fprintf(stdout, "OSDI(info) %s: ", handle->name); + break; + case LOG_LVL_WARN: + fprintf(stdout, "OSDI(warn) %s: ", handle->name); + break; + case LOG_LVL_ERR: + fprintf(stderr, "OSDI(err) %s: ", handle->name); + return stderr; + case LOG_LVL_FATAL: + fprintf(stderr, "OSDI(fatal) %s: ", handle->name); + return stderr; + default: + fprintf(stdout, "OSDI(unkown) %s", handle->name); + break; + } + return stdout; +} + +extern void osdi_finish_log_message(void *handle, FILE *stream, uint32_t lvl) { + + NG_IGNORE(handle); + NG_IGNORE(stream); + NG_IGNORE(lvl); +} diff --git a/src/osdi/osdiload.c b/src/osdi/osdiload.c index 09b920202..14206791b 100644 --- a/src/osdi/osdiload.c +++ b/src/osdi/osdiload.c @@ -77,7 +77,7 @@ extern int OSDIload(GENmodel *inModel, CKTcircuit *ckt) { /* hpyothetically this could run in parallel we do not write any shared data here*/ - handle = (OsdiNgspiceHandle){.kind = 2, .name = gen_inst->GENname}; + handle = (OsdiNgspiceHandle){.kind = 3, .name = gen_inst->GENname}; /* TODO initial conditions? */ uint32_t ret_flags = descr->eval(&handle, inst, model, flags, ckt->CKTrhsOld, &sim_params_); diff --git a/src/osdi/osdiregistry.c b/src/osdi/osdiregistry.c index 1c8336e2b..5c5dd7846 100644 --- a/src/osdi/osdiregistry.c +++ b/src/osdi/osdiregistry.c @@ -18,7 +18,7 @@ #if (!defined HAS_WINGUI) && (!defined __MINGW32__) && (!defined _MSC_VER) #include /* to load libraries*/ -#define OPENLIB(path) dlopen(path, RTLD_LAZY | RTLD_LOCAL) +#define OPENLIB(path) dlopen(path, RTLD_NOW | RTLD_LOCAL) #define GET_SYM(lib, sym) dlsym(lib, sym) #define FREE_DLERR_MSG(msg) diff --git a/src/osdi/osdisetup.c b/src/osdi/osdisetup.c index 747eff132..b5b197741 100644 --- a/src/osdi/osdisetup.c +++ b/src/osdi/osdisetup.c @@ -287,7 +287,7 @@ extern int OSDItemp(GENmodel *inModel, CKTcircuit *ckt) { gen_model = gen_model->GENnextModel) { void *model = osdi_model_data(gen_model); - handle = (OsdiNgspiceHandle){.kind = 1, .name = gen_model->GENmodName}; + handle = (OsdiNgspiceHandle){.kind = 4, .name = gen_model->GENmodName}; init_info = descr->setup_model((void *)&handle, model); res = handle_init_info(init_info, descr); if (res) {