Build fails due to offsetof parsing error

Hello,

I am building gobject-introspection on QNX, and have run into what appears to be a parsing problem on the following code in dirent.h:

/**
 * Calculate the full size of a dirent structure.
 * @param   len The length of the name field, including the terminating NUL
 * @return  The aligned length of the entry
 */
static inline _Sizet
dirent_calc_reclen(_Sizet const __len)
{
    _Sizet const align = sizeof(_Uint64t) - 1UL;
    return ((offsetof(struct dirent, d_name) + __len) + align) & ~align;
}

The error is

/data/sdp/usr/include/dirent.h:239: syntax error, unexpected STRUCT in '    return ((__builtin_offsetof(struct dirent,d_name) + __len) + align) & ~align;' at 'struct'                                                       
Traceback (most recent call last):                                         
  File "/home/elahav/src/gtk/gobject-introspection/build/tools/g-ir-scanner", line 99, in <module>
    sys.exit(scanner_main(sys.argv))                                       
             ^^^^^^^^^^^^^^^^^^^^^^                                        
  File "/home/elahav/src/gtk/gobject-introspection/build/giscanner/scannermain.py", line 608, in scanner_main
    shlibs = create_binary(transformer, options, args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/elahav/src/gtk/gobject-introspection/build/giscanner/scannermain.py", line 434, in create_binary
    shlibs = resolve_shlibs(options, binary, options.libraries)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^         
  File "/home/elahav/src/gtk/gobject-introspection/build/giscanner/shlibs.py", line 170, in resolve_shlibs
    _resolve_non_libtool(options, binary, non_libtool))                   
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                  
  File "/home/elahav/src/gtk/gobject-introspection/build/giscanner/shlibs.py", line 106, in _resolve_non_libtool
    output = subprocess.check_output(args)                      
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/system/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/system/lib/python3.11/subprocess.py", line 548, in run         
    with Popen(*popenargs, **kwargs) as process:                                                                                                      
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                       
  File "/system/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,                                                                                      
  File "/system/lib/python3.11/subprocess.py", line 1901, in _execute_child                              
    raise child_exception_type(errno_num, err_msg, err_filename)

Is this a limitation of the scanner?

Thanks,
–Elad

Yes; the introspection scanner is not a full C parser, it only understands declarations and static inlines tend to confuse it.

Thanks for the quick response. Any workaround? Is there perhaps a symbol that I can wrap around these (#ifndef GOBJECT_INROSPECTION or some such) so that the scanner skips the functions?

Yes, you can use:

#ifndef __GI_SCANNER__

// symbol to hide when running the introspection scanner

#endif
1 Like

That worked, thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.