We are trying to build Fedora with a compiler that does not support
implicit function declarations:
<
https://fedoraproject.org/wiki/Changes/PortingToModernC>
<
https://fedoraproject.org/wiki/Toolchain/PortingToModernC>
Gentoo is doing something simlar:
<
https://wiki.gentoo.org/wiki/Modern_C_porting
While investigating a false positive from our tester triggered by the
python-cffi testsuite, I noticed a curiousity with cdef: it does not
inject the specified prototype into the generated C stub. This means
that unless Python.h happens to include a header with a function
declaration, an implicit declaration is the result.
For example, this snippet:
“
import cffi
ffi = cffi.FFI()
ffi.cdef("int puts(const char *);")
ffi.cdef("const char *getenv(const char *);")
ffi.cdef("const char *gnu_get_libc_release(void);")
lib = ffi.verify()
lib.puts(lib.getenv(b"TERM"))
lib.puts(lib.gnu_get_libc_release())
”
prints this on x86 32-bit:
“
vt100
stable
”
But the call to gnu_get_libc_release() crashes on x86-64 64-bit because
the implicit declaration has return type int, and the pointer is clipped
to 32 bits.
This not an issue if the function returns int, though. And to support
implicit declarations, many POSIX interfaces return int anyway, so it
just works, although and ugly warning is printed on first use.
This will stop working once the compiler no longer accepts such implicit
function declarations. How common is such use of cdef? Do we need to
worry about it? Is there something we need to do as part of the new
compiler rollout?
Thanks,
Florian