Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV: Illegal storage access. (Attempt to read from nil?) #234

Open
holgerschurig opened this issue Jan 16, 2022 · 4 comments
Open

SIGSEGV: Illegal storage access. (Attempt to read from nil?) #234

holgerschurig opened this issue Jan 16, 2022 · 4 comments

Comments

@holgerschurig
Copy link

holgerschurig commented Jan 16, 2022

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:

  1. the SIGSEGV
  2. somehow the c2nim parser wants a ; after the final "#endif" directive of the file
@holgerschurig
Copy link
Author

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.

@hoyon
Copy link

hoyon commented Nov 5, 2022

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.

@mantielero
Copy link

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

@mantielero
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants