From f58fadfffca95f1b470517a80b6296d3f5369dfb Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Jun 2022 12:11:34 -0700 Subject: [PATCH] MAINT Fix C compiler warnings in src/core (#2716) --- src/core/error_handling.h | 2 +- src/core/jsproxy.c | 5 +---- src/core/pyproxy.c | 26 +++++++------------------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/core/error_handling.h b/src/core/error_handling.h index 2f330795d..b42918fd5 100644 --- a/src/core/error_handling.h +++ b/src/core/error_handling.h @@ -12,7 +12,7 @@ typedef int errcode; #define unlikely(x) __builtin_expect((x), 0) int -error_handling_init(); +error_handling_init(PyObject* core_module); extern PyObject* internal_error; diff --git a/src/core/jsproxy.c b/src/core/jsproxy.c index 8f6bd8725..6c45367a4 100644 --- a/src/core/jsproxy.c +++ b/src/core/jsproxy.c @@ -1446,7 +1446,6 @@ Buffer_dealloc(PyObject* self) static int Buffer_GetBuffer(PyObject* obj, Py_buffer* view, int flags) { - bool success = false; Buffer* self = (Buffer*)obj; view->obj = NULL; // This gets decremented automatically by PyBuffer_Release (even though @@ -1467,9 +1466,7 @@ Buffer_GetBuffer(PyObject* obj, Py_buffer* view, int flags) view->strides = NULL; view->suboffsets = NULL; - success = true; -finally: - return success ? 0 : -1; + return 0; } static PyBufferProcs Buffer_BufferProcs = { diff --git a/src/core/pyproxy.c b/src/core/pyproxy.c index 348c77b4a..35f2b4ccf 100644 --- a/src/core/pyproxy.c +++ b/src/core/pyproxy.c @@ -218,7 +218,6 @@ _pyproxy_type(PyObject* ptrobj) int _pyproxy_hasattr(PyObject* pyobj, JsRef idkey) { - bool success = false; PyObject* pykey = NULL; int result = -1; @@ -226,7 +225,6 @@ _pyproxy_hasattr(PyObject* pyobj, JsRef idkey) FAIL_IF_NULL(pykey); result = PyObject_HasAttr(pyobj, pykey); - success = true; finally: Py_CLEAR(pykey); return result; @@ -778,7 +776,7 @@ size_t py_buffer_shape_offset = offsetof(Py_buffer, shape); /** * Convert a C array of Py_ssize_t to JavaScript. */ -EM_JS_REF(JsRef, array_to_js, (Py_ssize_t * array, int len), { +EM_JS(JsRef, array_to_js, (Py_ssize_t * array, int len), { return Hiwire.new_value( Array.from(HEAP32.subarray(array / 4, array / 4 + len))); }) @@ -839,7 +837,6 @@ _pyproxy_get_buffer(buffer_struct* target, PyObject* ptrobj) return -1; } - bool success = false; buffer_struct result = { 0 }; result.start_ptr = result.smallest_ptr = result.largest_ptr = view.buf; result.readonly = view.readonly; @@ -893,21 +890,12 @@ _pyproxy_get_buffer(buffer_struct* target, PyObject* ptrobj) result.f_contiguous = PyBuffer_IsContiguous(&view, 'F'); success: - success = true; -finally: - if (success) { - // The result.view memory will be freed when (if?) the user calls - // Py_Buffer.release(). - result.view = (Py_buffer*)PyMem_Malloc(sizeof(Py_buffer)); - *result.view = view; - *target = result; - return 0; - } else { - hiwire_CLEAR(result.shape); - hiwire_CLEAR(result.strides); - PyBuffer_Release(&view); - return -1; - } + // The result.view memory will be freed when (if?) the user calls + // Py_Buffer.release(). + result.view = (Py_buffer*)PyMem_Malloc(sizeof(Py_buffer)); + *result.view = view; + *target = result; + return 0; } EM_JS_REF(JsRef, pyproxy_new, (PyObject * ptrobj), {