[CM] Weirdness with s7_load_c_string_with_environment, xxd fun

Christos Vagias chris.actondev at gmail.com
Fri Jul 9 12:53:55 PDT 2021


Thanks Bil!

I thought that since you have to pass the string size, that'd be enough.
Tried to go through the code but didn't get far. I guess TOKEN_EOF
isn't emitted and the reader tries to read one more byte (garbage)?

The other issueI had found is if I pass s7_rootlet(sc); to the
s7_load_with_environment,
it crashes (segmentation fault). It happens also with the corrected
version (with the null
terminated string).

As for the xxd behavior & null terminated strings, I found a trick here:
https://stackoverflow.com/questions/410980/include-a-text-file-in-a-c-program-as-a-char#comment236032_411000

xxd -i < scheme_file.scm > scheme_file.xxd; echo ", 0x00" >>  scheme_file.xxd
and scheme_file.xxd will look like

  0x01, 0x02, 0xAA,.....
, 0x00

And then in code
  const char main_scm[] = {
#include "./resources/main_scm.xxd"
  };

Or, to just add that byte termination to existing xxd files:
sed -i -e 's/};/,0x00};/' ./resources/*scm.h
for the files produced by xxd

On Fri, 9 Jul 2021 at 15:39, <bil at ccrma.stanford.edu> wrote:
>
> It's unfortunate that C (as opposed to C++) does not let
> you include a string, as opposed to an array of bytes.
> Or something like that -- it was awhile ago and I'm
> forgetting the distinction -- I vaguely remember that the
> xxd trick was not necessary in C++.
>


More information about the Cmdist mailing list