Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ target_include_directories(cppjit PRIVATE
)

target_compile_options(cppjit PRIVATE
-Wall -Wno-strict-aliasing -Wno-register
-Wall -Wextra -Wno-strict-aliasing -Wno-register
)

if(CMAKE_COMPILER_IS_GNUCXX)
Expand Down
6 changes: 3 additions & 3 deletions src/cpyrt/CPPEnum.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static PyTypeObject* GetCTypesType(const std::string& cppname) {
return (PyTypeObject*)PyObject_GetAttrString(ctmod, nn->second.c_str());
}

static PyObject* enum_ctype(PyObject* cls, PyObject* args, PyObject* kwds) {
static PyObject* enum_ctype(PyObject* cls, PyObject* args) {
PyObject* pyres = PyObject_GetAttr(cls, cpyrt::PyStrings::gUnderlying);
if (!pyres)
PyErr_Clear();
Expand All @@ -149,7 +149,7 @@ static PyObject* enum_ctype(PyObject* cls, PyObject* args, PyObject* kwds) {
if (!ct)
return nullptr;

return PyType_Type.tp_call((PyObject*)ct, args, kwds);
return PyType_Type.tp_call((PyObject*)ct, args, nullptr);
}

//- creation -----------------------------------------------------------------
Expand Down Expand Up @@ -213,7 +213,7 @@ cpyrt::CPPEnum* cpyrt::CPPEnum_New(const std::string& name,

// add pythonizations
Utility::AddToClass((PyObject*)Py_TYPE(pyenum), "__ctype__",
(PyCFunction)enum_ctype, METH_VARARGS | METH_KEYWORDS);
enum_ctype, METH_VARARGS);
((PyTypeObject*)pyenum)->tp_repr = enum_repr;
((PyTypeObject*)pyenum)->tp_str = ((PyTypeObject*)pyside_type)->tp_repr;

Expand Down
33 changes: 17 additions & 16 deletions src/cpyrt/CPPInstance.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,17 @@ static int op_nonzero(CPPInstance* self) {
}

//= cpyrt object explicit destruction =====================================
static PyObject* op_destruct(CPPInstance* self) {
static PyObject* op_destruct(PyObject* self, PyObject* /*args*/) {
// User access to force deletion of the object. Needed in case of a true
// garbage collector (like in PyPy), to allow the user control over when
// the C++ destructor is called. This method requires that the C++ object
// is owned (no-op otherwise).
op_dealloc_nofree(self);
op_dealloc_nofree((CPPInstance*)self);
Py_RETURN_NONE;
}

//= cpyrt object dispatch support =========================================
static PyObject* op_dispatch(PyObject* self, PyObject* args,
PyObject* /* kdws */) {
static PyObject* op_dispatch(PyObject* self, PyObject* args) {
// User-side __dispatch__ method to allow selection of a specific overloaded
// method. The actual selection is in the __overload__() method of
// CPPOverload.
Expand Down Expand Up @@ -312,13 +311,14 @@ static PyObject* op_dispatch(PyObject* self, PyObject* args,
}

//= cpyrt smart pointer support ===========================================
static PyObject* op_get_smartptr(CPPInstance* self) {
if (!self->IsSmart()) {
static PyObject* op_get_smartptr(PyObject* self, PyObject* /*args*/) {
CPPInstance* inst = (CPPInstance*)self;
if (!inst->IsSmart()) {
// TODO: more likely should raise
Py_RETURN_NONE;
}

return cpyrt::BindCppObjectNoCast(self->GetSmartObject(), SMART_TYPE(self),
return cpyrt::BindCppObjectNoCast(inst->GetSmartObject(), SMART_TYPE(inst),
CPPInstance::kNoWrapConv);
}

Expand All @@ -335,7 +335,8 @@ Py_ssize_t cpyrt::CPPInstance::ArrayLength() {
return (Py_ssize_t)ARRAY_SIZE(this);
}

static PyObject* op_reshape(CPPInstance* self, PyObject* shape) {
static PyObject* op_reshape(PyObject* self, PyObject* shape) {
CPPInstance* inst = (CPPInstance*)self;
// Allow the user to fix up the actual (type-strided) size of the buffer.
if (!PyTuple_Check(shape) || PyTuple_GET_SIZE(shape) != 1) {
PyErr_SetString(PyExc_TypeError, "tuple object of size 1 expected");
Expand All @@ -348,7 +349,7 @@ static PyObject* op_reshape(CPPInstance* self, PyObject* shape) {
return nullptr;
}

self->CastToArray(sz);
inst->CastToArray(sz);

Py_RETURN_NONE;
}
Expand Down Expand Up @@ -417,26 +418,26 @@ PyCFunction& CPPInstance::ReduceMethod() {
return reducer;
}

PyObject* op_reduce(PyObject* self, PyObject* args) {
PyObject* op_reduce(PyObject* self, PyObject* /*args*/) {
auto& reducer = CPPInstance::ReduceMethod();
if (!reducer) {
PyErr_SetString(PyExc_NotImplementedError, "");
return nullptr;
}
return reducer(self, args);
return reducer(self, nullptr);
}

//----------------------------------------------------------------------------
static PyMethodDef op_methods[] = {
{(char*)"__destruct__", (PyCFunction)op_destruct, METH_NOARGS,
{(char*)"__destruct__", op_destruct, METH_NOARGS,
(char*)"call the C++ destructor"},
{(char*)"__dispatch__", (PyCFunction)op_dispatch, METH_VARARGS,
{(char*)"__dispatch__", op_dispatch, METH_VARARGS,
(char*)"dispatch to selected overload"},
{(char*)"__smartptr__", (PyCFunction)op_get_smartptr, METH_NOARGS,
{(char*)"__smartptr__", op_get_smartptr, METH_NOARGS,
(char*)"get associated smart pointer, if any"},
{(char*)"__reduce__", (PyCFunction)op_reduce, METH_NOARGS,
{(char*)"__reduce__", op_reduce, METH_NOARGS,
(char*)"reduce method for serialization"},
{(char*)"__reshape__", (PyCFunction)op_reshape, METH_O,
{(char*)"__reshape__", op_reshape, METH_O,
(char*)"cast pointer to 1D array type"},
{(char*)nullptr, nullptr, 0, nullptr}};

Expand Down
52 changes: 32 additions & 20 deletions src/cpyrt/CPPOverload.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,20 @@ static inline PyObject* HandleReturn(CPPOverload* pymeth, CPPInstance* im_self,
}

//= cpyrt method proxy object behaviour ===================================
static PyObject* mp_name(CPPOverload* pymeth, void*) {
static PyObject* mp_name(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
return cpyrt_PyText_FromString(pymeth->GetName().c_str());
}

//----------------------------------------------------------------------------
static PyObject* mp_module(CPPOverload* /* pymeth */, void*) {
static PyObject* mp_module(PyObject*, void*) {
Py_INCREF(PyStrings::gThisModule);
return PyStrings::gThisModule;
}

//----------------------------------------------------------------------------
static PyObject* mp_doc(CPPOverload* pymeth, void*) {
static PyObject* mp_doc(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
if (pymeth->fMethodInfo->fDoc) {
Py_INCREF(pymeth->fMethodInfo->fDoc);
return pymeth->fMethodInfo->fDoc;
Expand Down Expand Up @@ -259,7 +261,8 @@ static PyObject* mp_doc(CPPOverload* pymeth, void*) {
return doc;
}

static int mp_doc_set(CPPOverload* pymeth, PyObject* val, void*) {
static int mp_doc_set(PyObject* self, PyObject* val, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
Py_XDECREF(pymeth->fMethodInfo->fDoc);
Py_INCREF(val);
pymeth->fMethodInfo->fDoc = val;
Expand All @@ -276,8 +279,8 @@ static int mp_doc_set(CPPOverload* pymeth, PyObject* val, void*) {
* 'int ::foo(int a)': ('a',),
* 'int ::foo(int a, float b)': ('a', 'b')}
*/
static PyObject* mp_func_overloads_names(CPPOverload* pymeth) {

static PyObject* mp_func_overloads_names(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
const CPPOverload::Methods_t& methods = pymeth->fMethodInfo->fMethods;

PyObject* overloads_names_dict = PyDict_New();
Expand All @@ -301,8 +304,8 @@ static PyObject* mp_func_overloads_names(CPPOverload* pymeth) {
* ('int',), 'return_type': 'int'}, 'int ::foo(int a, float b)': {'input_types':
* ('int', 'float'), 'return_type': 'int'}}
*/
static PyObject* mp_func_overloads_types(CPPOverload* pymeth) {

static PyObject* mp_func_overloads_types(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
const CPPOverload::Methods_t& methods = pymeth->fMethodInfo->fMethods;

PyObject* overloads_types_dict = PyDict_New();
Expand All @@ -316,7 +319,8 @@ static PyObject* mp_func_overloads_types(CPPOverload* pymeth) {
}

//----------------------------------------------------------------------------
static PyObject* mp_meth_func(CPPOverload* pymeth, void*) {
static PyObject* mp_meth_func(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
// Create a new method proxy to be returned.
CPPOverload* newPyMeth =
(CPPOverload*)CPPOverload_Type.tp_alloc(&CPPOverload_Type, 0);
Expand All @@ -333,7 +337,8 @@ static PyObject* mp_meth_func(CPPOverload* pymeth, void*) {
}

//----------------------------------------------------------------------------
static PyObject* mp_meth_self(CPPOverload* pymeth, void*) {
static PyObject* mp_meth_self(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
// Return the bound self, if any; in case of pseudo-function role, pretend
// that the data member im_self does not exist.
if (IsPseudoFunc(pymeth)) {
Expand All @@ -350,7 +355,8 @@ static PyObject* mp_meth_self(CPPOverload* pymeth, void*) {
}

//----------------------------------------------------------------------------
static PyObject* mp_meth_class(CPPOverload* pymeth, void*) {
static PyObject* mp_meth_class(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
// Return scoping class; in case of pseudo-function role, pretend that there
// is no encompassing class (i.e. global scope).
if (!IsPseudoFunc(pymeth) && pymeth->fMethodInfo->fMethods.size()) {
Expand All @@ -366,21 +372,22 @@ static PyObject* mp_meth_class(CPPOverload* pymeth, void*) {
}

//----------------------------------------------------------------------------
static PyObject* mp_func_closure(CPPOverload* /* pymeth */, void*) {
static PyObject* mp_func_closure(PyObject*, void*) {
// Stub only, to fill out the python function interface.
Py_RETURN_NONE;
}

//----------------------------------------------------------------------------
static PyObject* mp_func_code(CPPOverload*, void*) {
static PyObject* mp_func_code(PyObject*, void*) {
// Code details are used in module inspect to fill out interactive help()
// not important for functioning of most code, so not implemented for p3 for
// now (TODO)
Py_RETURN_NONE;
}

//----------------------------------------------------------------------------
static PyObject* mp_func_defaults(CPPOverload* pymeth, void*) {
static PyObject* mp_func_defaults(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
// Create a tuple of default values, if there is only one method (otherwise
// leave undefined: this is only used by inspect for interactive help())
CPPOverload::Methods_t& methods = pymeth->fMethodInfo->fMethods;
Expand All @@ -406,7 +413,7 @@ static PyObject* mp_func_defaults(CPPOverload* pymeth, void*) {
}

//----------------------------------------------------------------------------
static PyObject* mp_func_globals(CPPOverload* /* pymeth */, void*) {
static PyObject* mp_func_globals(PyObject*, void*) {
// Return this function's global dict (hard-wired to be the cppjit module);
// used for lookup of names from co_code indexing into co_names.
PyObject* pyglobal = PyModule_GetDict(PyImport_AddModule((char*)"cppjit"));
Expand Down Expand Up @@ -438,19 +445,22 @@ static inline int set_flag(CPPOverload* pymeth, PyObject* value,
}

//----------------------------------------------------------------------------
static PyObject* mp_getcreates(CPPOverload* pymeth, void*) {
static PyObject* mp_getcreates(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
// Get '__creates__' boolean, which determines ownership of return values.
return PyInt_FromLong((long)IsCreator(pymeth->fMethodInfo->fFlags));
}

//----------------------------------------------------------------------------
static int mp_setcreates(CPPOverload* pymeth, PyObject* value, void*) {
static int mp_setcreates(PyObject* self, PyObject* value, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
// Set '__creates__' boolean, which determines ownership of return values.
return set_flag(pymeth, value, CallContext::kIsCreator, "__creates__");
}

//----------------------------------------------------------------------------
static PyObject* mp_getmempolicy(CPPOverload* pymeth, void*) {
static PyObject* mp_getmempolicy(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
// Get '_mempolicy' enum, which determines ownership of call arguments.
if (pymeth->fMethodInfo->fFlags & CallContext::kUseHeuristics)
return PyInt_FromLong(CallContext::kUseHeuristics);
Expand All @@ -462,7 +472,8 @@ static PyObject* mp_getmempolicy(CPPOverload* pymeth, void*) {
}

//----------------------------------------------------------------------------
static int mp_setmempolicy(CPPOverload* pymeth, PyObject* value, void*) {
static int mp_setmempolicy(PyObject* self, PyObject* value, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
// Set '_mempolicy' enum, which determines ownership of call arguments.
long mempolicy = PyLong_AsLong(value);
if (mempolicy == CallContext::kUseHeuristics) {
Expand Down Expand Up @@ -501,7 +512,8 @@ CPPJIT_BOOLEAN_PROPERTY(useffi, CallContext::kUseFFI, "__useffi__")
CPPJIT_BOOLEAN_PROPERTY(sig2exc, CallContext::kProtected, "__sig2exc__")
// clang-format on

static PyObject* mp_getcppname(CPPOverload* pymeth, void*) {
static PyObject* mp_getcppname(PyObject* self, void*) {
CPPOverload* pymeth = (CPPOverload*)self;
if ((void*)pymeth == (void*)&CPPOverload_Type)
return cpyrt_PyText_FromString("CPPOverload_Type");

Expand Down
5 changes: 3 additions & 2 deletions src/cpyrt/CPPScope.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ static PyObject* meta_reflex(CPPScope* klass, PyObject* args) {
// quite what I'd expected of it, so the following pulls in the internal code
#include "PyObjectDir27.inc"

static PyObject* meta_dir(CPPScope* klass) {
static PyObject* meta_dir(PyObject* self, PyObject*) {
CPPScope* klass = (CPPScope*)self;
// Collect a list of everything (currently) available in the namespace.
// The backend can filter by returning empty strings. Special care is
// taken for functions, which need not be unique (overloading).
Expand Down Expand Up @@ -673,7 +674,7 @@ static PyObject* meta_dir(CPPScope* klass) {
static PyMethodDef meta_methods[] = {
{(char*)"__cpp_reflex__", (PyCFunction)meta_reflex, METH_VARARGS,
(char*)"C++ datamember reflection information"},
{(char*)"__dir__", (PyCFunction)meta_dir, METH_NOARGS, nullptr},
{(char*)"__dir__", meta_dir, METH_NOARGS, nullptr},
{(char*)nullptr, nullptr, 0, nullptr}};

//-----------------------------------------------------------------------------
Expand Down
Loading
Loading