Skip to content

Commit 112935f

Browse files
committed
C warnigs as errors take 2
1 parent 7e3c3f7 commit 112935f

File tree

14 files changed

+28
-35
lines changed

14 files changed

+28
-35
lines changed

graalpython/com.oracle.graal.python.cext/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#
2929
cmake_minimum_required(VERSION 3.22)
3030
project(com.oracle.graal.python.cext)
31-
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
3231

3332
function(require_var var)
3433
if (NOT DEFINED ${var})
@@ -61,7 +60,11 @@ set(TARGET_LIBPYTHON "python-${LLVM_MODE}")
6160
# common variables and compile/link options (for all build targets)
6261
######################################################################
6362

64-
set(CFLAGS_WARNINGS -Wno-int-to-pointer-cast -Wno-int-conversion -Wno-void-pointer-to-int-cast
63+
set(CFLAGS_WARNINGS -Wall -Werror -Wno-unused-function -Wno-unused-variable -Wno-unused-const-variable
64+
-Wno-tautological-constant-out-of-range-compare # fileutils.c: wchar_t > MAX_UNICODE is always false on Windows
65+
-Wno-unused-but-set-variable # sqlite.c: BOOL bRc
66+
-Wno-ignored-pragmas # sre.c: #pragma optimize("agtw", on)
67+
-Wno-int-to-pointer-cast -Wno-int-conversion -Wno-void-pointer-to-int-cast
6568
-Wno-incompatible-pointer-types-discards-qualifiers -Wno-pointer-type-mismatch
6669
-Wno-braced-scalar-init -Wno-deprecated-declarations)
6770

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ static inline int get_method_flags_wrapper(int flags) {
254254
return JWRAPPER_UNSUPPORTED;
255255
}
256256

257-
void register_native_slots(PyTypeObject* managed_class, PyGetSetDef* getsets, PyMemberDef* members);
257+
// looked up by NFI, so exported
258+
PyAPI_FUNC(void) register_native_slots(PyTypeObject* managed_class, PyGetSetDef* getsets, PyMemberDef* members);
258259

259260
// export the SizeT arg parse functions, because we use them in contrast to cpython on windows for core modules that we link dynamically
260261
PyAPI_FUNC(int) _PyArg_Parse_SizeT(PyObject *, const char *, ...);

graalpython/com.oracle.graal.python.cext/src/import.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,10 @@ static struct PyModuleDef imp_module = {
25512551
PyMODINIT_FUNC
25522552
PyInit__imp(void)
25532553
{
2554-
return PyModuleDef_Init(&imp_module);
2554+
// GraalPy change: we intrinsify this module in Java, no one should call this directly,
2555+
// so to be safe we bail out
2556+
printf("Function PyInit__imp not implemented in GraalPy. The _imp module is available, but not implemented as extension.\n");
2557+
exit(-1);
25552558
}
25562559

25572560

graalpython/com.oracle.graal.python.cext/src/longobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,10 @@ PyLong_FromString(const char *str, char **pend, int base)
19811981
overflow = 1;
19821982
}
19831983

1984-
if (overflow) {
1984+
if (overflow || (error_if_nonzero && value != 0)) {
1985+
if (error_if_nonzero) {
1986+
base = 0;
1987+
}
19851988
PyObject* string = PyUnicode_FromStringAndSize(numberStart, digits);
19861989
PyObject* result = GraalPyTruffleLong_FromString(string, base, negative);
19871990
Py_DecRef(string);

graalpython/com.oracle.graal.python.cext/src/memoryobject.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ PyObject *
754754
PyMemoryView_FromBuffer(const Py_buffer *info)
755755
{
756756
// GraalPy change: different implementation
757-
Py_ssize_t ndim = info->ndim;
758757
if (info->buf == NULL) {
759758
PyErr_SetString(PyExc_ValueError,
760759
"PyMemoryView_FromBuffer(): info->buf must not be NULL");
@@ -3334,7 +3333,6 @@ PyTruffle_MemoryViewFromObject(PyObject *v, int flags)
33343333
if (PyObject_GetBuffer(v, buffer, flags) < 0) {
33353334
return NULL;
33363335
}
3337-
Py_ssize_t ndim = buffer->ndim;
33383336
int needs_release = 0;
33393337
if (buffer->obj != NULL) {
33403338
PyBufferProcs *pb;

graalpython/com.oracle.graal.python.cext/src/obmalloc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ int PyTruffle_AllocMemory(size_t size) {
8484
PyTruffle_Log(PY_TRUFFLE_LOG_CONFIG, "PyTruffle_AllocMemory: exceeding PyTruffle_NativeMemoryGCBarrier (%lu) with allocation of size %lu, current PyTruffle_AllocatedMemory: %lu\n", PyTruffle_NativeMemoryGCBarrier, size, PyTruffle_AllocatedMemory);
8585

8686
size_t delay = 0;
87-
int iteration = 0;
8887
for (int iteration = 0; iteration < MAX_COLLECTION_RETRIES; iteration++) {
8988
GraalPyTruffle_TriggerGC(delay);
9089
delay += COLLECTION_DELAY_INCREMENT;

graalpython/com.oracle.graal.python.cext/src/structseq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ _PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc,
532532
#endif // GraalPy change
533533

534534
if (PyType_Ready(type) < 0) {
535-
PyMem_Free(members);
535+
// GraalPy change: not initialized
536+
// PyMem_Free(members);
536537
return -1;
537538
}
538539
Py_INCREF(type);

graalpython/com.oracle.graal.python.cext/src/tupleobject.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ PyTuple_GetItem(PyObject *op, Py_ssize_t i) {
114114
PyErr_BadInternalCall();
115115
return NULL;
116116
}
117-
PyObject *res;
118117
PyObject **ob_item;
119118
if (points_to_py_handle_space(op)) {
120119
const PyObject *ptr = pointer_to_stub((PyObject *) op);
@@ -1363,7 +1362,6 @@ PyTruffleTuple_GetItems(PyObject *op)
13631362
#ifdef GRAALVM_PYTHON_LLVM_MANAGED
13641363
return GraalPy_get_PyTupleObject_ob_item((PyTupleObject*) op);
13651364
#else /* GRAALVM_PYTHON_LLVM_MANAGED */
1366-
PyObject *res;
13671365
PyObject **ob_item;
13681366
if (points_to_py_handle_space(op)) {
13691367
GraalPyVarObject *ptr = (GraalPyVarObject *) pointer_to_stub(op);

graalpython/com.oracle.graal.python.cext/src/typeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5721,7 +5721,7 @@ type_add_members(PyTypeObject *type)
57215721
PyObject *dict = type->tp_dict;
57225722
for (; memb->name != NULL; memb++) {
57235723
// GraalPy change
5724-
if (GraalPyTruffleType_AddMember(type, type->tp_dict, memb->name, memb->type, memb->offset, (memb->flags & READONLY) == 0, memb->doc) < 0)
5724+
if (GraalPyTruffleType_AddMember(type, dict, memb->name, memb->type, memb->offset, (memb->flags & READONLY) == 0, memb->doc) < 0)
57255725
return -1;
57265726
}
57275727
return 0;
@@ -5740,7 +5740,7 @@ type_add_getset(PyTypeObject *type)
57405740
for (; gsp->name != NULL; gsp++) {
57415741
// GraalPy change
57425742
if (GraalPyTruffleType_AddGetSet(type,
5743-
type->tp_dict,
5743+
dict,
57445744
gsp->name,
57455745
gsp->get,
57465746
gsp->set,

graalpython/com.oracle.graal.python.hpy.llvm/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#
2929
cmake_minimum_required(VERSION 3.22)
3030
project(com.oracle.graal.python.hpy.llvm)
31-
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
3231

3332
function(require_var var)
3433
if (NOT DEFINED ${var})

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_long.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ class TestPyLong(CPyExtTestCase):
359359
test_PyLong_FromString = CPyExtFunction(
360360
lambda args: int(args[0], args[1]),
361361
lambda: (
362+
("00", 0),
363+
("03", 0),
362364
(" 12 ", 10),
363365
(" 12abg13 ", 22),
364366
("12", 0),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,9 @@ public final class CApiFunction {
770770
@CApiBuiltin(name = "PyImport_ImportFrozenModule", ret = Int, args = {ConstCharPtrAsTruffleString}, call = NotImplemented)
771771
@CApiBuiltin(name = "PyImport_ImportFrozenModuleObject", ret = Int, args = {PyObject}, call = NotImplemented)
772772
@CApiBuiltin(name = "PyImport_ReloadModule", ret = PyObject, args = {PyObject}, call = NotImplemented)
773-
@CApiBuiltin(name = "PyInit__imp", ret = PyObject, args = {}, call = NotImplemented)
773+
// Not implemented, we just use handwritten stub (in import.c) to preserve the C attributes
774+
// (PyMODINIT_FUNC vs PyAPI_FUNC)
775+
@CApiBuiltin(name = "PyInit__imp", ret = PyObject, args = {}, call = Ignored)
774776
@CApiBuiltin(name = "PyInterpreterState_Clear", ret = Void, args = {PyInterpreterState}, call = NotImplemented)
775777
@CApiBuiltin(name = "PyInterpreterState_Delete", ret = Void, args = {PyInterpreterState}, call = NotImplemented)
776778
@CApiBuiltin(name = "PyInterpreterState_Get", ret = PyInterpreterState, args = {}, call = NotImplemented)

graalpython/python-liblzma/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ target_compile_definitions(${TARGET_LZMASUPPORT} PRIVATE NDEBUG)
8080

8181
if(WIN32)
8282
target_compile_options(${TARGET_LZMA} PRIVATE /Z7 /O2)
83-
target_compile_options(${TARGET_LZMASUPPORT} PRIVATE /Z7 /O2 /WX)
83+
target_compile_options(${TARGET_LZMASUPPORT} PRIVATE /Z7 /O2 /W3 /WX)
8484
else()
8585
target_compile_options(${TARGET_LZMA} PRIVATE -fPIC -DPIC -g -O2)
8686
target_compile_definitions(${TARGET_LZMA} PRIVATE PIC)
8787

88-
target_compile_options(${TARGET_LZMASUPPORT} PRIVATE -g -O3)
88+
target_compile_options(${TARGET_LZMASUPPORT} PRIVATE -g -O3 -Wall -Werror)
8989
endif()
9090

9191
# don't install into the system but into the MX project's output dir

graalpython/python-liblzma/src/lzma.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -298,14 +298,6 @@ static off_heap_buffer* lzma_allocate_buffer(size_t items)
298298
return o;
299299
}
300300

301-
static off_heap_buffer* lzma_create_copy_buffer(Byte *src, ssize_t len) {
302-
off_heap_buffer *dest = lzma_allocate_buffer(len);
303-
if (dest && len > 0) {
304-
memcpy(dest->buf, src, len);
305-
}
306-
return dest;
307-
}
308-
309301
static void lzma_release_buffer(off_heap_buffer *o) {
310302
if (!o) {
311303
return;
@@ -329,14 +321,6 @@ static void lzma_release_buffer(off_heap_buffer *o) {
329321
free(o);
330322
}
331323

332-
static off_heap_buffer* lzma_get_ref(off_heap_buffer* o) {
333-
if (o) {
334-
LOG_FINEST("off_heap_buffer(ref_count: %zu + 1)\n", o->ref_count);
335-
o->ref_count++;
336-
}
337-
return o;
338-
}
339-
340324
// nfi_function: name('createStream') map('lzmast_stream*', 'POINTER')
341325
lzmast_stream *lzma_create_lzmast_stream() {
342326
lzmast_stream *lzmast = (lzmast_stream *) calloc(1, sizeof(lzmast_stream));
@@ -621,7 +605,7 @@ int lzma_set_filter_spec_bcj(lzmast_stream *lzmast, int fidx, int64_t* opts) {
621605

622606
// nfi_function: name('encodeFilter') map('lzmast_stream*', 'POINTER')
623607
int lzma_encode_filter_spec(lzmast_stream *lzmast, int64_t* opts) {
624-
lzma_ret lzret;
608+
lzma_ret lzret = LZMA_PROG_ERROR;
625609
uint32_t encoded_size;
626610
lzma_filter filter;
627611

0 commit comments

Comments
 (0)