libcyaml: Ability to have NULL pointers in arrays of pointers

there are cases that I have fixed-size arrays that always have N pointers, and if any of those is NULL cyaml fails to serialize them.

a use case is I have a mixer that always has N slots, and when the slot is supposed to be empty I simply set array[x] to NULL.

right now I am doing a workaround where I aggregate the non-NULL elements of the array into another array before serializing, and putting them back where they belong after deserializing.

I found this which says that ~ or null can be used for null values https://stackoverflow.com/a/34089604

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments

Okay, thanks, I’ll make tests and do a v1.0.1 in the next few days.

Thanks for the report!

The CYAML_FLAG_ALLOW_NULL_PTR should be on the value definition for array elements, alongside the CYAML_FLAG_POINTER, rather than on the array/sequence definition.

oh sweet, that worked! this is after saving and reloading:

(gdb) p zrythm->project->tracklist->tracks[3]->channel ->plugins
$4 = {0x555556e1ef60, 0x0, 0x0, 0x555556f8bc80, 0x0, 0x0, 0x0, 0x0, 0x0}
(gdb) p zrythm->project->tracklist->tracks[3]->channel ->plugins[0]->descr->name
$7 = 0x555556a47fb0 "Dexed"
(gdb) p zrythm->project->tracklist->tracks[3]->channel ->plugins[3]->descr->name
$8 = 0x555556a31c60 "BassUp"

looks fine

You need to set the CYAML_FLAG_ALLOW_NULL_PTR flag on any values you want to be treated like this.

See: https://github.com/tlsa/libcyaml/blob/tlsa/allow-null-pointer-values/include/cyaml/cyaml.h#L137

The documentation above should explain how it behaves.

sure, i’ll try it later today

Interesting. I’ll look into this soon.