Skip to content

Commit 144a3b0

Browse files
committed
Avoid compiler warnings
1 parent 7cbe57c commit 144a3b0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Include/pyport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,25 @@ extern "C" {
288288
#define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push")
289289
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
290290
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
291+
#define _Py_COMP_DIAG_IGNORE_TYPE_LIMITS
291292
#define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop")
292293
#elif defined(__GNUC__) \
293294
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
294295
#define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push")
295296
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
296297
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
298+
#define _Py_COMP_DIAG_IGNORE_TYPE_LIMITS \
299+
_Pragma("GCC diagnostic ignored \"-Wtype-limits\"")
297300
#define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
298301
#elif defined(_MSC_VER)
299302
#define _Py_COMP_DIAG_PUSH __pragma(warning(push))
300303
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
304+
#define _Py_COMP_DIAG_IGNORE_TYPE_LIMITS
301305
#define _Py_COMP_DIAG_POP __pragma(warning(pop))
302306
#else
303307
#define _Py_COMP_DIAG_PUSH
304308
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
309+
#define _Py_COMP_DIAG_IGNORE_TYPE_LIMITS
305310
#define _Py_COMP_DIAG_POP
306311
#endif
307312

Modules/_ctypes/cfield.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Py_ssize_t NUM_BITS(Py_ssize_t bitsize) {
385385
(PyLongObject *)value); \
386386
} \
387387
else { \
388-
int res = PyLong_AsNativeBytes( \
388+
Py_ssize_t res = PyLong_AsNativeBytes( \
389389
value, &val, (NBITS) / 8, \
390390
Py_ASNATIVEBYTES_NATIVE_ENDIAN \
391391
| Py_ASNATIVEBYTES_ALLOW_INDEX); \
@@ -1283,7 +1283,12 @@ for nbytes in 8, 16, 32, 64:
12831283
Py_UNREACHABLE();
12841284
}
12851285

1286-
/* Macro to call _ctypes_fixint_fielddesc for a given C type */
1286+
/* Macro to call _ctypes_fixint_fielddesc for a given C type.
1287+
* The signedness check expands an expression that's always true or false;
1288+
* we silence the GCC warning '-Wtype-limits' for this.
1289+
*/
1290+
_Py_COMP_DIAG_PUSH
1291+
_Py_COMP_DIAG_IGNORE_TYPE_LIMITS
12871292
#define FIXINT_FIELDDESC_FOR(C_TYPE) \
12881293
_ctypes_fixint_fielddesc(sizeof(C_TYPE), (C_TYPE)-1 < 0)
12891294

@@ -1443,6 +1448,7 @@ for base_code, base_c_type in [
14431448
formattable.fmt_bool.getfunc = bool_get;
14441449
}
14451450
#undef FIXINT_FIELDDESC_FOR
1451+
_Py_COMP_DIAG_POP
14461452

14471453
struct fielddesc *
14481454
_ctypes_get_fielddesc(const char *fmt)

0 commit comments

Comments
 (0)