You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When compiling Cython modules, gcc -Wall -Wextra emits many warnings for the PyInt type conversions.
$ cat warningtest.pyx
cdef extern from "stdint.h":
ctypedef long int64_t
ctypedef unsigned long uint64_t
cdef int64_t _f(int64_t x):
return x >> 1
cdef uint64_t _fu(uint64_t x):
return x >> 1
def f(x):
return _f(x)
def fu(x):
return _fu(x)
$ cython warningtest.pyx
$ gcc -fPIC -fno-strict-aliasing -g -O2 -Wall -Wextra -I/usr/include/python2.6 -shared -o warningtest.so warningtest.c
warningtest.c: In function ‘__Pyx_PyInt_from_py_uint64_t’:
warningtest.c:674: warning: comparison of unsigned expression < 0 is always false
warningtest.c:678: warning: comparison of unsigned expression < 0 is always false
warningtest.c:682: warning: comparison of unsigned expression < 0 is always false
warningtest.c:686: warning: comparison of unsigned expression < 0 is always false
warningtest.c:690: warning: comparison of unsigned expression < 0 is always false
warningtest.c: In function ‘__Pyx_PyInt_to_py_uint64_t’:
warningtest.c:708: warning: comparison of unsigned expression < 0 is always false
warningtest.c:712: warning: comparison of unsigned expression < 0 is always false
warningtest.c: In function ‘__Pyx_PyInt_AsUnsignedLong’:
warningtest.c:888: warning: comparison of unsigned expression < 0 is always false
warningtest.c:890: warning: signed and unsigned type in conditional expression
warningtest.c: In function ‘__Pyx_PyInt_AsUnsignedLongLong’:
warningtest.c:919: warning: comparison of unsigned expression < 0 is always false
warningtest.c:921: warning: signed and unsigned type in conditional expression
warningtest.c: In function ‘__Pyx_PyInt_AsLong’:
warningtest.c:952: warning: signed and unsigned type in conditional expression
warningtest.c: In function ‘__Pyx_PyInt_AsLongLong’:
warningtest.c:983: warning: signed and unsigned type in conditional expression
warningtest.c: In function ‘__Pyx_PyInt_AsSignedLong’:
warningtest.c:1014: warning: signed and unsigned type in conditional expression
warningtest.c: In function ‘__Pyx_PyInt_AsSignedLongLong’:
warningtest.c:1045: warning: signed and unsigned type in conditional expression
This is because Cython outputs code that looks like the following:
I've attached a patch that stops these warnings by creating a new temporary variable is_unsigned, and by converting the ternary operator to a normal if/else.
In my testing, it seems to work, but it would be good to get another pairs of eyes to look at this to make sure what I did was correct.
When compiling Cython modules,
gcc -Wall -Wextra
emits many warnings for thePyInt
type conversions.This is because Cython outputs code that looks like the following:
I've attached a patch that stops these warnings by creating a new temporary variable
is_unsigned
, and by converting the ternary operator to a normalif
/else
.In my testing, it seems to work, but it would be good to get another pairs of eyes to look at this to make sure what I did was correct.
At 2009-10-12T16:41:28Z @MarkLodato added attachment 0001-prevent-warnings-when-compiling-with-gcc-Wextra.patch
Migrated from http://trac.cython.org/ticket/405
The text was updated successfully, but these errors were encountered: