commit 7566021d62cf314c4521b1ca70177db33b0e08d8
parent 8f143de5e6eddd352992d0a03ab587102167d7bc
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 1 Mar 2024 18:38:47 +0100
Fix parsing of external programmable sources
Once the library symbols have been loaded, it's time to create the data.
Note that to release this data, Stardis must ensure that the function
symbol used is still active. The corresponding library must therefore
not be unloaded. We therefore move the release of the external source
accordingly, i.e. before closing the various dynamically loaded
libraries.
Diffstat:
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/stardis-app.c b/src/stardis-app.c
@@ -558,6 +558,9 @@ stardis_release
str_release(&stardis->bin_green_filename);
str_release(&stardis->end_paths_filename);
str_release(&stardis->chunks_prefix);
+
+ extern_source_release(&stardis->extsrc);
+
/* release non-PROGRAM descritions first */
FOR_EACH(i, 0, darray_descriptions_size_get(&stardis->descriptions)) {
struct description* d = darray_descriptions_data_get(&stardis->descriptions) +i;
@@ -589,7 +592,6 @@ stardis_release
release_solid(stardis->dummies.stardis_solid, stardis->allocator);
}
darray_probe_boundary_release(&stardis->probe_boundary_list);
- extern_source_release(&stardis->extsrc);
}
unsigned
diff --git a/src/stardis-extern-source.c b/src/stardis-extern-source.c
@@ -171,18 +171,24 @@ void
extern_source_release(struct extern_source* src)
{
ASSERT(src);
- if(src->sdis_src) SDIS(source_ref_put(src->sdis_src));
-
if(src->type == EXTERN_SOURCE_SPHERE_PROG) {
struct spherical_source_prog* src_prog = &src->data.sphere_prog;
size_t i;
+ if(src_prog->data) {
+ ASSERT(src_prog->release);
+ src_prog->release(src_prog->data);
+ }
+
str_release(&src_prog->prog_name);
FOR_EACH(i, 0, src_prog->argc) {
MEM_RM(src_prog->allocator, src_prog->argv[i]);
}
+
MEM_RM(src_prog->allocator, src_prog->argv);
}
+
+ if(src->sdis_src) SDIS(source_ref_put(src->sdis_src));
}
res_T
diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c
@@ -2151,6 +2151,7 @@ error:
static res_T
process_spherical_source_prog(struct stardis* stardis, wordexp_t* pwordexp)
{
+ struct stardis_description_create_context ctx;
struct spherical_source_prog* src = NULL;
char* lib_name = NULL;
char* arg = NULL;
@@ -2197,6 +2198,15 @@ process_spherical_source_prog(struct stardis* stardis, wordexp_t* pwordexp)
GET_LIB_SYMBOL(src, position, stardis_spherical_source_position);
GET_LIB_SYMBOL(src, power, stardis_spherical_source_power);
+ ctx.name = "External spherical source";
+ src->data = src->create(&ctx, src->program->prog_data, src->argc, src->argv);
+ if(!src->data) {
+ logger_print(stardis->logger, LOG_ERROR,
+ "Cannot create data for the external spherical source\n");
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
res = extern_source_create_solver_source(&stardis->extsrc, stardis);
if(res != RES_OK) goto error;