c-std-porting.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* cffi.FFI.cdef and implicit function declarations
@ 2023-02-08 10:10 Florian Weimer
  2023-02-08 12:12 ` [python-cffi] " Armin Rigo
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2023-02-08 10:10 UTC (permalink / raw)
  To: python-cffi; +Cc: c-std-porting

We are trying to build Fedora with a compiler that does not support
implicit function declarations:


Gentoo is doing something simlar:


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()

prints this on x86 32-bit:


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?


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-08 13:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08 10:10 cffi.FFI.cdef and implicit function declarations Florian Weimer
2023-02-08 12:12 ` [python-cffi] " Armin Rigo
2023-02-08 12:18   ` Armin Rigo
2023-02-08 13:57     ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).