-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'len', 'iter' support to IntArrayList
Add 'refcnt' method to Unsafe
- Loading branch information
Showing
18 changed files
with
286 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// Created by xia__mc on 2024/11/13. | ||
// | ||
|
||
#include "IntArrayListIter.h" | ||
#include "utils/PythonUtils.h" | ||
|
||
extern "C" { | ||
|
||
static PyTypeObject IntArrayListIterType = { | ||
PyVarObject_HEAD_INIT(&PyType_Type, 0) | ||
}; | ||
|
||
IntArrayListIter *IntArrayListIter_create(IntArrayList *list) { | ||
auto *instance = Py_CreateObjNoInit<IntArrayListIter>(IntArrayListIterType); | ||
|
||
Py_INCREF(list); | ||
instance->container = list; | ||
instance->index = 0; | ||
|
||
return instance; | ||
} | ||
|
||
static void IntArrayListIter_dealloc(IntArrayListIter *self) { | ||
SAFE_DECREF(self->container); | ||
Py_TYPE(self)->tp_free((PyObject *) self); | ||
} | ||
|
||
static PyObject *IntArrayListIter_next(PyObject *pySelf) { | ||
auto *self = reinterpret_cast<IntArrayListIter *>(pySelf); | ||
|
||
if (self->index >= self->container->vector.size()) { | ||
PyErr_SetNone(PyExc_StopIteration); | ||
return nullptr; | ||
} | ||
|
||
auto element = self->container->vector[self->index]; | ||
self->index++; | ||
return PyLong_FromLong(static_cast<long>(element)); | ||
} | ||
|
||
static PyObject *IntArrayListIter_iter(PyObject *pySelf) { | ||
return pySelf; | ||
} | ||
|
||
static PyMethodDef IntArrayListIter_methods[] = { | ||
{nullptr} | ||
}; | ||
|
||
static struct PyModuleDef IntArrayListIter_module = { | ||
PyModuleDef_HEAD_INIT, | ||
"__pyfastutil.IntArrayListIter", | ||
"An IntArrayListIter_module that creates an IntArrayList", | ||
-1, | ||
nullptr, nullptr, nullptr, nullptr, nullptr | ||
}; | ||
|
||
void initializeIntArrayListIterType(PyTypeObject &type) { | ||
type.tp_name = "IntArrayListIter"; | ||
type.tp_basicsize = sizeof(IntArrayListIter); | ||
type.tp_itemsize = 0; | ||
type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; | ||
type.tp_iter = IntArrayListIter_iter; | ||
type.tp_iternext = IntArrayListIter_next; | ||
type.tp_methods = IntArrayListIter_methods; | ||
type.tp_dealloc = (destructor) IntArrayListIter_dealloc; | ||
type.tp_alloc = PyType_GenericAlloc; | ||
type.tp_free = PyObject_Del; | ||
} | ||
|
||
#pragma clang diagnostic push | ||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" | ||
PyMODINIT_FUNC PyInit_IntArrayListIter() { | ||
initializeIntArrayListIterType(IntArrayListIterType); | ||
|
||
PyObject *object = PyModule_Create(&IntArrayListIter_module); | ||
if (object == nullptr) | ||
return nullptr; | ||
|
||
Py_INCREF(&IntArrayListIterType); | ||
if (PyModule_AddObject(object, "IntArrayList", (PyObject *) &IntArrayListIterType) < 0) { | ||
Py_DECREF(&IntArrayListIterType); | ||
Py_DECREF(object); | ||
return nullptr; | ||
} | ||
|
||
return object; | ||
} | ||
#pragma clang diagnostic pop | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Created by xia__mc on 2024/11/13. | ||
// | ||
|
||
#ifndef PYFASTUTIL_INTARRAYLISTITER_H | ||
#define PYFASTUTIL_INTARRAYLISTITER_H | ||
|
||
#include "utils/PythonPCH.h" | ||
#include "IntArrayList.h" | ||
|
||
extern "C" { | ||
typedef struct IntArrayListIter { | ||
PyObject_HEAD; | ||
IntArrayList *container; | ||
size_t index; | ||
} IntArrayListIter; | ||
|
||
IntArrayListIter *IntArrayListIter_create(IntArrayList *list); | ||
|
||
} | ||
|
||
PyMODINIT_FUNC PyInit_IntArrayListIter(); | ||
|
||
#endif //PYFASTUTIL_INTARRAYLISTITER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,6 @@ | |
|
||
#pragma warning(pop) | ||
|
||
#include "Compat.h" | ||
|
||
#endif //PYFASTUTIL_PYTHONPCH_H |
Oops, something went wrong.