Compliant LV2 state path-mapping

lv2 state mandates that
>  The plugin MUST use this function [ absolute_path] in order to
>  actually open or otherwise use any paths loaded from plugin state.
Previously the plugin uses the value directly. Also
>  The caller is responsible for freeing the returned value with free().
is now implemented on systems other than windows (where this is not
possible, since the memory must be free()ed in the same module where it
was allocated.
This commit is contained in:
Robin Gareus 2018-12-19 22:28:40 +01:00
parent 3a5da6fdc4
commit 1528df2f5a
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
1 changed files with 22 additions and 1 deletions

View File

@ -731,6 +731,10 @@ save (LV2_Handle instance,
apath, strlen (apath) + 1,
self->atom_Path, LV2_STATE_IS_POD);
#ifndef _WIN32 // TODO need lilv_free() -- https://github.com/drobilla/lilv/issues/14
free (apath);
#endif
return LV2_STATE_SUCCESS;
}
@ -747,15 +751,32 @@ restore (LV2_Handle instance,
return LV2_STATE_ERR_UNKNOWN;
}
LV2_State_Map_Path* map_path = NULL;
for (int i = 0; features[i]; ++i) {
if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) {
map_path = (LV2_State_Map_Path*) features[i]->data;
}
}
if (!map_path) {
return LV2_STATE_ERR_NO_FEATURE;
}
size_t size;
uint32_t type;
uint32_t valflags;
const void* value = retrieve (handle, self->afs_sf2file, &size, &type, &valflags);
if (value) {
strncpy (self->queue_sf2_file_path, (const char*) value, 1023);
char* apath = map_path->absolute_path (map_path->handle, (const char*) value);
strncpy (self->queue_sf2_file_path, apath, 1023);
printf ("XXX %s -> %s\n", (const char*) value, apath);
self->queue_sf2_file_path[1023] = '\0';
self->queue_reinit = true;
#ifndef _WIN32 // TODO need lilv_free() -- https://github.com/drobilla/lilv/issues/14
free (apath);
#endif
}
return LV2_STATE_SUCCESS;
}