diff --git a/rabbitizer/module.c b/rabbitizer/rabbitizer_Instr.c similarity index 88% rename from rabbitizer/module.c rename to rabbitizer/rabbitizer_Instr.c index dab6a71..c1f3d3b 100644 --- a/rabbitizer/module.c +++ b/rabbitizer/rabbitizer_Instr.c @@ -1,9 +1,11 @@ -#define PY_SSIZE_T_CLEAN -#include -#include "structmember.h" +/* SPDX-FileCopyrightText: © 2022 Decompollaborate */ +/* SPDX-License-Identifier: MIT */ + +#include "rabbitizer_module.h" #include "instructions/RabbitizerInstr.h" + typedef struct PyRabbitizerInstr { PyObject_HEAD //PyObject *first; /* first name */ @@ -184,7 +186,7 @@ static PyMethodDef Instr_methods[] = { {NULL} /* Sentinel */ }; -static PyTypeObject InstrType = { +PyTypeObject rabbitizer_Instr_Type = { PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "rabbitizer.Instr", .tp_doc = PyDoc_STR("Instruction"), @@ -198,31 +200,3 @@ static PyTypeObject InstrType = { .tp_methods = Instr_methods, .tp_getset = Instr_getsetters, }; - -static PyModuleDef rabbitizer_module = { - PyModuleDef_HEAD_INIT, - .m_name = "rabbitizer", - .m_doc = "", - .m_size = -1, -}; - -PyMODINIT_FUNC -PyInit_rabbitizer(void) -{ - PyObject *m; - if (PyType_Ready(&InstrType) < 0) - return NULL; - - m = PyModule_Create(&rabbitizer_module); - if (m == NULL) - return NULL; - - Py_INCREF(&InstrType); - if (PyModule_AddObject(m, "Instr", (PyObject *) &InstrType) < 0) { - Py_DECREF(&InstrType); - Py_DECREF(m); - return NULL; - } - - return m; -} diff --git a/rabbitizer/rabbitizer_module.c b/rabbitizer/rabbitizer_module.c new file mode 100644 index 0000000..55d130f --- /dev/null +++ b/rabbitizer/rabbitizer_module.c @@ -0,0 +1,33 @@ +/* SPDX-FileCopyrightText: © 2022 Decompollaborate */ +/* SPDX-License-Identifier: MIT */ + +#include "rabbitizer_module.h" + + +static PyModuleDef rabbitizer_module = { + PyModuleDef_HEAD_INIT, + .m_name = "rabbitizer", + .m_doc = "", + .m_size = -1, +}; + +PyMODINIT_FUNC +PyInit_rabbitizer(void) +{ + PyObject *m; + if (PyType_Ready(&rabbitizer_Instr_Type) < 0) + return NULL; + + m = PyModule_Create(&rabbitizer_module); + if (m == NULL) + return NULL; + + Py_INCREF(&rabbitizer_Instr_Type); + if (PyModule_AddObject(m, "Instr", (PyObject *) &rabbitizer_Instr_Type) < 0) { + Py_DECREF(&rabbitizer_Instr_Type); + Py_DECREF(m); + return NULL; + } + + return m; +} diff --git a/rabbitizer/rabbitizer_module.h b/rabbitizer/rabbitizer_module.h new file mode 100644 index 0000000..619136c --- /dev/null +++ b/rabbitizer/rabbitizer_module.h @@ -0,0 +1,8 @@ +/* SPDX-FileCopyrightText: © 2022 Decompollaborate */ +/* SPDX-License-Identifier: MIT */ + +#define PY_SSIZE_T_CLEAN +#include +#include "structmember.h" + +extern PyTypeObject rabbitizer_Instr_Type; diff --git a/setup.py b/setup.py index fd75c48..9abfd74 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: © 2022 Decompollaborate +# SPDX-License-Identifier: MIT + from setuptools import setup, find_packages, Extension @@ -10,7 +13,7 @@ setup( # the qualified name of the extension module to build 'rabbitizer', # the files to compile into our module relative to ``setup.py`` - ['rabbitizer/module.c', + ["rabbitizer/rabbitizer_module.c", "rabbitizer/rabbitizer_Instr.c", "src/instructions/RabbitizerInstr_Disassemble.c", "src/instructions/RabbitizerInstr_ProcessUniqueId.c", "src/instructions/RabbitizerInstr.c", "src/instructions/RabbitizerInstrDescriptor.c", "src/instructions/RabbitizerInstrId.c", "src/instructions/RabbitizerRegister.c", "src/common/Utils.c"],