python-cffi / cffi

A Foreign Function Interface package for calling C libraries from Python.
https://cffi.readthedocs.io/en/latest/
Other
114 stars 41 forks source link

avoid null-pointer-subtraction error #78

Closed nitzmahone closed 4 months ago

nitzmahone commented 4 months ago

Newer compilers generate warnings/errors about null pointer subtractions being an undefined behavior. Use matching non-zero offsets (as suggested by arigo) to avoid the error.

nekopsykose commented 3 months ago

is there any reason to not make this offsetof(%s, %s) instead?

arigo commented 3 months ago

We can't in this case, because we have the name of the pointer type, and not the struct name type. See the next line after the else: for the case where we have the struct name and can just emit offsetof.

nekopsykose commented 3 months ago

that makes sense, thanks :)