} GwionData;
ANN GwionData* new_gwiondata(MemPool);
+ANN GwionData* cpy_gwiondata(MemPool, const GwionData*);
ANN void free_gwiondata(const struct Gwion_*);
+ANN void free_gwiondata_cpy(const MemPool, GwionData*);
#endif
#include "compile.h"
#include "object.h" // fork_clean
#include "pass.h" // fork_clean
-#include "specialid.h" // fork_clean
#include "shreduler_private.h"
ANN static void driver_arg(const Gwion gwion, Driver *di) {
compile_filename(gwion, (m_str)vector_at(v, i));
}
+ANN static void gwion_cleaner(const Gwion gwion) {
+ if(!gwion->type[et_shred])
+ return;
+ const VM_Code code = new_vm_code(gwion->mp, NULL, 0, ae_flag_builtin, "in code dtor");
+ gwion->vm->cleaner_shred = new_vm_shred(gwion->mp, code);
+ vm_add_shred(gwion->vm, gwion->vm->cleaner_shred);
+}
+
ANN VM* gwion_cpy(const VM* src) {
const Gwion gwion = mp_calloc(src->gwion->mp, Gwion);
gwion->vm = new_vm(src->gwion->mp, 0);
gwion->vm->bbq->si = soundinfo_cpy(src->gwion->mp, src->bbq->si);
gwion->emit = src->gwion->emit;
gwion->env = src->gwion->env;
- gwion->data = src->gwion->data;
+ gwion->data = cpy_gwiondata(src->gwion->mp, src->gwion->data);
gwion->st = src->gwion->st;
gwion->mp = src->gwion->mp;
gwion->type = src->gwion->type;
vm->bbq->driver->run(vm, vm->bbq);
}
-ANN static void fork_clean2(const Vector v) {
+ANN static void gwion_end_child(const VM_Shred shred, const Gwion gwion);
+
+ANN static inline void free_gwion_cpy(const Gwion gwion, const VM_Shred shred) {
+ gwion_end_child(shred, gwion);
+ free_vm(gwion->vm);
+ free_gwiondata_cpy(gwion->mp, gwion->data);
+ mp_free(gwion->mp, Gwion, gwion);
+}
+
+ANN static void fork_clean2(const VM_Shred shred, const Vector v) {
for(m_uint i = 0; i < vector_size(v); ++i) {
VM* vm = (VM*)vector_at(v, i);
- const Gwion gwion = vm->gwion;
- free_vm(vm);
- mp_free(gwion->mp, Gwion, gwion);
+ free_gwion_cpy(vm->gwion, shred);
}
vector_release(v);
}
-ANN static void gwion_end_child(const Gwion gwion) {
+ANN static void gwion_end_child(const VM_Shred shred, const Gwion gwion) {
MUTEX_LOCK(gwion->vm->shreduler->mutex);
if(gwion->data->child.ptr)
- fork_clean(gwion->vm->cleaner_shred, &gwion->data->child);
+ fork_clean(shred, &gwion->data->child);
if(gwion->data->child2.ptr)
- fork_clean2(&gwion->data->child2);
+ fork_clean2(shred, &gwion->data->child2);
MUTEX_UNLOCK(gwion->vm->shreduler->mutex);
}
-ANN static void gwion_cleaner(const Gwion gwion) {
- if(!gwion->type[et_shred])
- return;
- const VM_Code code = new_vm_code(gwion->mp, NULL, 0, ae_flag_builtin, "in code dtor");
- gwion->vm->cleaner_shred = new_vm_shred(gwion->mp, code);
- vm_add_shred(gwion->vm, gwion->vm->cleaner_shred);
-}
-
ANN void gwion_end(const Gwion gwion) {
gwion_cleaner(gwion);
- gwion_end_child(gwion);
+ gwion_end_child(gwion->vm->cleaner_shred, gwion);
free_env(gwion->env);
if(gwion->vm->cleaner_shred)
free_vm_shred(gwion->vm->cleaner_shred);
#include "specialid.h"
#include "pass.h"
-ANN GwionData* new_gwiondata(MemPool mp) {
+ANN static inline GwionData* gwiondata(MemPool mp) {
struct GwionData_ *data = mp_calloc(mp, GwionData);
+ MUTEX_SETUP(data->mutex);
+ return data;
+}
+
+ANN GwionData* new_gwiondata(MemPool mp) {
+ GwionData *data = gwiondata(mp);
map_init(&data->freearg);
map_init(&data->id);
vector_init(&data->reserved);
data->passes = new_passes(mp);
- MUTEX_SETUP(data->mutex);
return data;
}
+ANN GwionData* cpy_gwiondata(MemPool mp, const GwionData* src) {
+ GwionData *data = gwiondata(mp);
+ data->freearg = src->freearg;
+ data->id = src->id;
+ data->reserved = src->reserved;
+ data->plug = src->plug;
+ data->passes = src->passes;
+ return data;
+}
+
+ANN void free_gwiondata_cpy(const MemPool mp, GwionData *data) {
+ MUTEX_CLEANUP(data->mutex);
+ mp_free(mp, GwionData, data);
+}
+
ANN void free_gwiondata(const struct Gwion_ *gwion) {
- struct GwionData_ *data = gwion->data;
+ GwionData *data = gwion->data;
map_release(&data->freearg);
for(m_uint i = 0; i < map_size(&data->id); ++i)
mp_free(gwion->mp, SpecialId, (struct SpecialId_*)map_at(&data->id, i));
free_passes(data->passes);
if(data->plug)
free_plug(gwion);
- MUTEX_CLEANUP(data->mutex);
- mp_free(gwion->mp, GwionData, data);
+ free_gwiondata_cpy(gwion->mp, data);
}
describe_path_and_dir(_code, s->code->name)
static DTOR(shred_dtor) {
- free_vm_shred(ME(o));
+ if(ME(o))
+ free_vm_shred(ME(o));
}
static MFUN(shred_lock) {
static DTOR(fork_dtor) {
THREAD_JOIN(FORK_THREAD(o));
+ const VM *vm = FORK_ORIG(o);
if(*(m_int*)(o->data + o_fork_done)) {
- vector_rem2(&FORK_ORIG(o)->gwion->data->child, (vtype)o);
- vector_add(&FORK_ORIG(o)->gwion->data->child2, (vtype)ME(o)->info->vm);
+ vector_rem2(&vm->gwion->data->child, (vtype)o);
+ if(!vm->gwion->data->child2.ptr)
+ vector_init(&vm->gwion->data->child2);
+ vector_add(&vm->gwion->data->child2, (vtype)ME(o)->info->vm);
}
}
ANN void fork_launch(const VM* vm, const M_Object o, const m_uint sz) {
o->ref += 1;
- if(!vm->gwion->data->child.ptr) {
+ if(!vm->gwion->data->child.ptr)
vector_init(&vm->gwion->data->child);
- vector_init(&vm->gwion->data->child2);
- }
vector_add(&vm->gwion->data->child, (vtype)o);
FORK_ORIG(o) = (VM*)vm;
FORK_RETSIZE(o) = sz;
THREAD_CREATE(FORK_THREAD(o), fork_run, o);
}
-
ANN void fork_clean(const VM_Shred shred, const Vector v) {
for(m_uint i = 0; i < vector_size(v); ++i) {
const M_Object o = (M_Object)vector_at(v, i);
--- /dev/null
+op_already_imported.gw ==964533== Memcheck, a memory error detector
+==964533== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
+==964533== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
+==964533== Command: ./../../gwion -p. -m dummy -d dummy op_already_imported.gw
+==964533== Parent PID: 963027
+==964533==
+==964533==
+==964533== HEAP SUMMARY:
+==964533== in use at exit: 0 bytes in 0 blocks
+==964533== total heap usage: 869 allocs, 869 frees, 17,602,040 bytes allocated
+==964533==
+==964533== All heap blocks were freed -- no leaks are possible
+==964533==
+==964533== For lists of detected and suppressed errors, rerun with: -s
+==964533== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
-[1,2,3] @=> auto i;
-i[1:2];
-i[:2];
-i[2: -1];
+<<< [1,2,3] @=> auto i >>>;
+<<< i[1:2] >>>;
+<<< i[:2] >>>;
+<<< i[2: -1] >>>;