Commit 64d809b8 authored by Hanspeter Portner's avatar Hanspeter Portner

add missing try_locks for lua state in moony_in.

* add missing try_locks for lua state in moony_in.
* reference atom_ser buffer as LV2_Atom only after filling (realloc etc.)
parent 6d6cab74
......@@ -383,15 +383,14 @@ _stash(lua_State *L)
if(ser.buf)
{
LV2_Atom *atom = (LV2_Atom *)ser.buf;
atom->type = 0;
atom->size = 0;
memset(ser.buf, 0x0, sizeof(LV2_Atom));
lv2_atom_forge_set_sink(lframe->forge, _sink, _deref, &ser);
lua_call(L, 1, 0);
if(moony->stash_atom)
moony_free(moony, moony->stash_atom, moony->stash_size);
LV2_Atom *atom = (LV2_Atom *)ser.buf;
moony->stash_atom = atom;
moony->stash_size = ser.size;
}
......@@ -472,9 +471,7 @@ _state_save(LV2_Handle instance, LV2_State_Store_Function store,
if(ser.buf)
{
LV2_Atom *atom = (LV2_Atom *)ser.buf;
atom->type = 0;
atom->size = 0;
memset(ser.buf, 0x0, sizeof(LV2_Atom));
lv2_atom_forge_set_sink(&moony->state_forge, _sink, _deref, &ser);
......@@ -494,6 +491,7 @@ _state_save(LV2_Handle instance, LV2_State_Store_Function store,
_unlock(&moony->lock.state);
LV2_Atom *atom = (LV2_Atom *)ser.buf;
if( (atom->type) && (atom->size) )
{
status = store(
......@@ -1514,63 +1512,76 @@ moony_in(moony_t *moony, const LV2_Atom_Sequence *control, LV2_Atom_Sequence *no
{
if(property->body == moony->uris.moony_code)
{
// stash
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_STASH);
if(lua_pcall(L, 0, 0, 0))
moony_error(moony);
lua_gc(L, LUA_GCSTEP, 0);
// load chunk
const char *str = LV2_ATOM_BODY_CONST(value);
if(luaL_dostring(L, str)) // failed loading chunk
{
moony_error(moony);
}
else // succeeded loading chunk
if(_try_lock(&moony->lock.state))
{
_spin_lock(&moony->lock.chunk);
strncpy(moony->chunk, str, value->size);
_unlock(&moony->lock.chunk);
// stash
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_STASH);
if(lua_pcall(L, 0, 0, 0))
moony_error(moony);
lua_gc(L, LUA_GCSTEP, 0);
moony->error[0] = 0x0; // reset error flag
// load chunk
const char *str = LV2_ATOM_BODY_CONST(value);
if(luaL_dostring(L, str)) // failed loading chunk
{
moony_error(moony);
}
else // succeeded loading chunk
{
if(_try_lock(&moony->lock.chunk))
{
strncpy(moony->chunk, str, value->size);
_unlock(&moony->lock.chunk);
} //FIXME else
moony->error[0] = 0x0; // reset error flag
if(moony->state_atom)
{
// restore Lua defined properties
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_RESTORE);
if(lua_pcall(L, 0, 0, 0))
moony_error(moony);
lua_gc(L, LUA_GCSTEP, 0);
}
}
if(moony->state_atom)
// apply stash
if(moony->stash_atom) // something has been stashed previously
{
// restore Lua defined properties
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_RESTORE);
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_APPLY);
if(lua_pcall(L, 0, 0, 0))
moony_error(moony);
lua_gc(L, LUA_GCSTEP, 0);
}
}
// apply stash
if(moony->stash_atom) // something has been stashed previously
{
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_APPLY);
if(lua_pcall(L, 0, 0, 0))
moony_error(moony);
lua_gc(L, LUA_GCSTEP, 0);
moony_free(moony, moony->stash_atom, moony->stash_size);
moony->stash_atom = NULL;
moony->stash_size = 0;
}
moony_free(moony, moony->stash_atom, moony->stash_size);
moony->stash_atom = NULL;
moony->stash_size = 0;
}
_unlock(&moony->lock.state);
} //FIXME else
}
else if(property->body == moony->uris.moony_selection)
{
// we do not do any stash, apply and restore for selections
// load chunk
const char *str = LV2_ATOM_BODY_CONST(value);
if(luaL_dostring(L, str)) // failed loading chunk
{
moony_error(moony);
}
else // succeeded loading chunk
if(_try_lock(&moony->lock.state))
{
moony->error[0] = 0x0; // reset error flag
}
// load chunk
const char *str = LV2_ATOM_BODY_CONST(value);
if(luaL_dostring(L, str)) // failed loading chunk
{
moony_error(moony);
}
else // succeeded loading chunk
{
moony->error[0] = 0x0; // reset error flag
}
_unlock(&moony->lock.state);
} //FIXME else
}
}
}
......@@ -1617,15 +1628,16 @@ moony_in(moony_t *moony, const LV2_Atom_Sequence *control, LV2_Atom_Sequence *no
if(moony->dirty_out)
{
_spin_lock(&moony->lock.chunk);
uint32_t len = strlen(moony->chunk);
if(ref)
ref = lv2_atom_forge_frame_time(forge, 0);
if(ref)
ref = _moony_patch(&moony->uris.patch, forge, moony->uris.moony_code, moony->chunk, len);
if(_try_lock(&moony->lock.chunk))
{
uint32_t len = strlen(moony->chunk);
if(ref)
ref = lv2_atom_forge_frame_time(forge, 0);
if(ref)
ref = _moony_patch(&moony->uris.patch, forge, moony->uris.moony_code, moony->chunk, len);
_unlock(&moony->lock.chunk);
_unlock(&moony->lock.chunk);
} //FIXME else
moony->dirty_out = 0; // reset flag
}
......
......@@ -38,20 +38,34 @@ _log_mem(moony_t *moony, void *ptr, size_t osize, size_t nsize)
moony_vm_t *vm = &moony->vm;
if(moony->log)
{
char suffix = ' ';
char suffix0 = ' ';
size_t space = vm->space;
if(space >= 1024)
{
suffix0 = 'K';
space >>= 10;
}
if(space >= 1024)
{
suffix0 = 'M';
space >>= 10;
}
char suffix1 = ' ';
size_t used = vm->used;
if(used >= 1024)
{
suffix = 'K';
suffix1 = 'K';
used >>= 10;
}
if(used >= 1024)
{
suffix = 'M';
suffix1 = 'M';
used >>= 10;
}
lv2_log_trace(&moony->logger, "used: %4zu%c, old: %4zu, new: %4zu, data: %p",
used, suffix, osize, nsize, ptr);
lv2_log_trace(&moony->logger, "space: %4zu%c, used: %4zu%c, old: %4zu, new: %4zu, data: %p",
space, suffix0, used, suffix1, osize, nsize, ptr);
}
}
#endif
......
......@@ -162,7 +162,7 @@ run(LV2_Handle instance, uint32_t nsamples)
lua_gc(L, LUA_GCSTEP, 0);
_unlock(&handle->moony.lock.state);
}
} //FIXME else
for(unsigned i=0; i<handle->max_val; i++)
if(&frame[i] != handle->forge[i].stack) // intercept assert
......
......@@ -174,7 +174,7 @@ run(LV2_Handle instance, uint32_t nsamples)
lua_gc(L, LUA_GCSTEP, 0);
_unlock(&handle->moony.lock.state);
}
} //FIXME else
if(&frame != handle->forge.stack) // intercept assert
moony_err(&handle->moony, "forge frame mismatch");
......
......@@ -145,7 +145,7 @@ run(LV2_Handle instance, uint32_t nsamples)
lua_gc(L, LUA_GCSTEP, 0);
_unlock(&handle->moony.lock.state);
}
} //FIXME else
// clear output ports upon error
if(moony_bypass(&handle->moony))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment