Skip to content

Commit 0f99514

Browse files
committed
[WIP] Treat compiler warnings as errors in our C projects.
PullRequest: graalpython/3425
2 parents 212943c + fa86ce5 commit 0f99514

File tree

14 files changed

+35
-47
lines changed

14 files changed

+35
-47
lines changed

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

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

3233
function(require_var var)
3334
if (NOT DEFINED ${var})

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ PyAPI_FUNC(void) mmap_init_bufferprotocol(PyObject* mmap_type) {
251251
(getbufferproc)mmap_getbuffer,
252252
(releasebufferproc)NULL,
253253
};
254-
GraalPy_set_PyTypeObject_tp_as_buffer(mmap_type, &mmap_as_buffer);
254+
GraalPy_set_PyTypeObject_tp_as_buffer((PyTypeObject *) mmap_type, &mmap_as_buffer);
255255
((PyTypeObject*) mmap_type)->tp_as_buffer = &mmap_as_buffer;
256256
}
257257

@@ -268,7 +268,7 @@ PyAPI_FUNC(void) PyTruffleCData_InitBufferProtocol(PyObject* type) {
268268
cdata_getbuffer,
269269
cdata_releasebuffer,
270270
};
271-
GraalPy_set_PyTypeObject_tp_as_buffer(type, &cdata_as_buffer);
271+
GraalPy_set_PyTypeObject_tp_as_buffer(((PyTypeObject*) type), &cdata_as_buffer);
272272
((PyTypeObject*) type)->tp_as_buffer = &cdata_as_buffer;
273273
}
274274

@@ -309,7 +309,7 @@ void memory_releasebuf(PyMemoryViewObject *self, Py_buffer *view);
309309
static int
310310
picklebuf_getbuf(PyPickleBufferObject *self, Py_buffer *view, int flags)
311311
{
312-
PyObject *self_view_obj = GraalPyTruffle_PickleBuffer_viewobj(self);
312+
PyObject *self_view_obj = GraalPyTruffle_PickleBuffer_viewobj((PyObject*) self);
313313
return PyObject_GetBuffer(self_view_obj, view, flags);
314314
}
315315

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

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

3233
function(require_var var)
3334
if (NOT DEFINED ${var})

graalpython/com.oracle.graal.python.hpy.llvm/src/autogen_c_access.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 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
@@ -61,7 +61,7 @@
6161
static int fill_c_type_sizes(int32_t *ctype_sizes)
6262
{
6363
ctype_sizes[0] = (int32_t) sizeof(HPyContext*);
64-
ctype_sizes[1] = (int32_t) sizeof(void);
64+
ctype_sizes[1] = (int32_t) 0;
6565
ctype_sizes[2] = (int32_t) sizeof(void*);
6666
ctype_sizes[3] = (int32_t) sizeof(void**);
6767
ctype_sizes[4] = (int32_t) sizeof(bool);

graalpython/com.oracle.graal.python.jni/src/ctx_call_jni.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 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
@@ -69,7 +69,7 @@ JNIEXPORT jlong JNICALL TRAMPOLINE(executeDebugKeywords)(JNIEnv *env, jclass cla
6969
}
7070
assert(nargs >= 0);
7171
assert(n_kwnames >= 0);
72-
size_t nargs_with_kw = (size_t)nargs + (size_t)n_kwnames;
72+
jlong nargs_with_kw = nargs + n_kwnames;
7373
_ARR_JLONG2DH(dctx, dh_args, args, nargs_with_kw)
7474
DHPy dh_result = f(dctx, dh_self, dh_args, (size_t)nargs, dh_kwnames);
7575
_ARR_DH_CLOSE(dctx, dh_args, nargs_with_kw)

graalpython/com.oracle.graal.python.jni/src/debug/debug_ctx.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* MIT License
22
*
3-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
3+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates.
44
* Copyright (c) 2019 pyhandle
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -31,12 +31,6 @@
3131
# include <malloc.h> /* for alloca() */
3232
#endif
3333

34-
static struct _HPyContext_s g_debug_ctx = {
35-
.name = "HPy Debug Mode ABI",
36-
._private = NULL,
37-
.abi_version = HPY_ABI_VERSION,
38-
};
39-
4034
static HPyDebugCtxInfo *init_ctx_info(HPyContext *dctx, HPyContext *uctx) {
4135
HPyDebugCtxInfo *ctx_info = (HPyDebugCtxInfo*) malloc(sizeof(HPyDebugCtxInfo));
4236
if (ctx_info == NULL) {

graalpython/com.oracle.graal.python.jni/src/hpy_jni.c

Lines changed: 1 addition & 15 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
@@ -146,20 +146,6 @@ static uint64_t get_hpy_handle_for_object(HPyContext *ctx, jobject hpyContext, j
146146
return boxHandle(next_handle);
147147
}
148148

149-
static jobject get_object_for_hpy_handle(jobject hpyContext, uint64_t bits) {
150-
jobjectArray hpy_handles = (jobjectArray)(*jniEnv)->GetObjectField(jniEnv, hpyContext, jniField_hpyHandleTable);
151-
if (hpy_handles == NULL) {
152-
LOGS("hpy handle table is NULL")
153-
return NULL;
154-
}
155-
jobject element = (*jniEnv)->GetObjectArrayElement(jniEnv, (jobjectArray)hpy_handles, (jsize)unboxHandle(bits));
156-
(*jniEnv)->DeleteLocalRef(jniEnv, hpy_handles);
157-
if (element == NULL) {
158-
LOGS("handle delegate is NULL")
159-
}
160-
return element;
161-
}
162-
163149
static jobject get_object_for_hpy_global(jobject hpyContext, uint64_t bits) {
164150
jobject hpy_globals = (*jniEnv)->GetObjectField(jniEnv, hpyContext, jniField_hpyGlobalsTable);
165151
if (hpy_globals == NULL) {

graalpython/com.oracle.graal.python.jni/src/hpy_native_fast_paths.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "hpy_native_fast_paths.h"
4545
#include "hpy_native_cache.h"
4646

47+
#include <assert.h>
4748
#include <stdint.h>
4849

4950
#define MAX_UNCLOSED_HANDLES 32
@@ -53,15 +54,20 @@ static HPy unclosedHandles[MAX_UNCLOSED_HANDLES];
5354
//*************************
5455
// BOXING
5556

57+
static_assert(sizeof(uint64_t) == sizeof(double), "Assumption necessary for NaN boxing to work");
58+
5659
static inline double unboxDouble(uint64_t value) {
57-
uint64_t doubleBits = value - NAN_BOXING_BASE;
58-
return * ((double*) &doubleBits);
60+
double result;
61+
uint64_t unboxed = value - NAN_BOXING_BASE;
62+
memcpy(&result, &unboxed, sizeof(double));
63+
return result;
5964
}
6065

6166
static inline uint64_t boxDouble(double value) {
6267
// assumes that value doesn't contain non-standard silent NaNs
63-
uint64_t doubleBits = * ((uint64_t*) &value);
64-
return doubleBits + NAN_BOXING_BASE;
68+
uint64_t unboxed;
69+
memcpy(&unboxed, &value, sizeof(double));
70+
return unboxed + NAN_BOXING_BASE;
6571
}
6672

6773
//*************************

graalpython/com.oracle.graal.python.jni/src/trace/_tracemod.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* MIT License
22
*
3-
* Copyright (c) 2023, 2023, Oracle and/or its affiliates.
3+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
44
* Copyright (c) 2019 pyhandle
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -179,7 +179,7 @@ get_optional_arg(HPyContext *ctx, const HPy *args, size_t nargs, HPy kwnames,
179179
HPy_ssize_t nkw, j;
180180
HPy h_kwname, h_item;
181181
// if given as positional arg
182-
if (i < nargs) {
182+
if (i < (HPy_ssize_t) nargs) {
183183
*out = args[i];
184184
return 0;
185185
}

graalpython/com.oracle.graal.python.jni/src/trace/trace_ctx.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* MIT License
22
*
3-
* Copyright (c) 2023, 2023, Oracle and/or its affiliates.
3+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
44
* Copyright (c) 2019 pyhandle
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,12 +25,6 @@
2525
#include "trace_internal.h"
2626
#include "autogen_trace_ctx_init.h"
2727

28-
static struct _HPyContext_s g_trace_ctx = {
29-
.name = "HPy Trace Mode ABI",
30-
._private = NULL,
31-
.abi_version = HPY_ABI_VERSION,
32-
};
33-
3428
// NOTE: at the moment this function assumes that uctx is always the
3529
// same. If/when we migrate to a system in which we can have multiple
3630
// independent contexts, this function should ensure to create a different

0 commit comments

Comments
 (0)