SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Hi, I want to make a wrapper around notmuch.h from Debian Sid's libnotmuch-dev 0.34.3-1. For this, I run
holger@holger:~/src/nim$ c2nim --version
0.9.18
holger@holger:~/src/nim$ c2nim --debug --nep1 notmuch.c2nim /usr/include/notmuch.h
No stack traceback available
/usr/include/notmuch.h(2853, 7) Warning: expected ';' [SyntaxError]
No stack traceback available
/usr/include/notmuch.h(2853, 7) Warning: expected ';' [SyntaxError]
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault
The notmuch.c2nim file is just this:
holger@holger:~/src/nim$ cat notmuch.c2nim
#ifdef C2NIM
# dynlib notmuchll
# cdecl
# if defined(windows)
# define notmuchll "notmuch.dll"
# elif defined(macosx)
# define notmuchll "libnotmuch.dylib"
# else
# define notmuchll "libnotmuch.so"
# endif
#endif
#assumedef __DOXYGEN__
#def NOTMUCH_DEPRECATED(major, minor)
So I now have two issues:
- the SIGSEGV
- somehow the c2nim parser wants a ; after the final "#endif" directive of the file
Hmm, GitHub doesn't allow me to attach the notmuch.h file for your convenience --- or I am too dumb. So I uploaded it to 0x0.st instead. Here is the link: http://0x0.st/o-If.h
The weird filename is from the pastebin site 0x0.st, not from me.
I'm getting the same issue but seems to only happen when running on a header in a directory owned by root eg all the headers in /usr/include.
Seems to be an issue with c2nim trying to create the output in a directory owned by root. Running c2nim with a copy of the header in a directory owned by my local user or specifying --out:output.nim seems to work.
I guess there's missing error check when opening the output file which causes the seg fault. Would be better to exit with a useful error instead.
I am facing this problem with the header in a directory not owned by root. In my case, it occurs with file: https://github.com/FFmpeg/FFmpeg/blob/release/6.1/libavformat/avformat.h
I use ffmpeg.c2nim:
#ifdef C2NIM
#def av_const
#def av_always_inline
#def av_pure
#pp AV_HAVE_BIGENDIAN
#def attribute_deprecated
#def av_warn_unused_result
#def AV_PIX_FMT_NE
#endif
#def FF_API_R_FRAME_RATE TRUE
#ifdef C2NIM
#@
template AV_PIX_FMT_NE*(be, le: untyped):untyped =
`AV_PIX_FMT le`
@#
#endif
If I use the following command:
c2nim --strict --skipinclude --dynlib:libavformat --header --skipcomments --out:avformat/avformat.nim ffmpeg.c2nim ../FFmpeg-release-6.1/libavformat/avformat.h
it complains about line 2831:
FFmpeg-release-6.1/libavformat/avformat.h(2831, 1) Error: did not expect #
If execute the same line without --strict:
[warning] preprocessor ignoring option: endif
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
[1] 4858 segmentation fault (core dumped) c2nim --skipinclude --dynlib:libavformat --header --skipcomments ffmpeg.c2ni
In my case, it looks like the issue is related with trying to create output file in an unexisting folder.
So by just doing:
mkdir avformat
the problem was solved.