Skip to content

Commit 0681323

Browse files
committed
i think i fixed it
1 parent 6970ba4 commit 0681323

File tree

16 files changed

+277
-144
lines changed

16 files changed

+277
-144
lines changed

docs/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Reference
22

33
<!-- prettier-ignore -->
4+
::: pointers.constants
45
::: pointers.base_pointers
56
::: pointers.c_pointer
67
::: pointers.decay

gen.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ def ctp(data: str) -> str:
3232
WCHAR = ctc("wchar")
3333
DOUBLE_QUOTE: str = '"'
3434
TRIPLE_QUOTE: str = '"""'
35+
SSIZE = ctc("ssize_t")
3536

3637
C_TYPES = {
3738
"void": "None",
3839
"PyObject*": ct("py_object"),
3940
"int": ctc("int"),
4041
"void*": VOID_P,
41-
"Py_ssize_t": ctc("ssize_t"),
42+
"Py_ssize_t": SSIZE,
4243
"char": ctc("char"),
4344
"char*": CHAR_P,
4445
"const char*": CHAR_P,
@@ -57,13 +58,19 @@ def ctp(data: str) -> str:
5758
"w_char*": WCHAR_P,
5859
"va_list": VOID_P,
5960
"wchar_t": WCHAR,
60-
"const wchar_t": WCHAR,
6161
"PyTypeObject": "PyTypeObject",
6262
"Py_UCS4": "Py_UCS4",
6363
"PyThreadState": "PyThreadState",
6464
"PyVarObject": "PyVarObject",
6565
"PyFrameObject": "PyFrameObject",
6666
"PyInterpreterState": "PyInterpreterState",
67+
"PyType_Spec": "PyType_Spec",
68+
"Py_tss_t": "Py_tss_t",
69+
"Py_hash_t": SSIZE,
70+
"Py_buffer": "Py_buffer",
71+
"PyOS_sighandler_t": VOID_P,
72+
"PyGILState_STATE": VOID_P,
73+
"PyModuleDef": "PyModuleDef",
6774
}
6875

6976
CT_TYPES = {
@@ -306,7 +313,7 @@ def main():
306313
return
307314
break
308315

309-
out: str = """raise Exception('autogenerating some things is too complicated or not possible! please manually go through and update the rest. you may delete this error when finished\n')"""
316+
out: str = """raise Exception('autogenerating some things is too complicated or not possible! please manually go through and update the rest. you may delete this error when finished')\n"""
310317
from src.pointers._pyapi import API_FUNCS
311318

312319
funcs: dict[str, list[str]] = {}
@@ -370,6 +377,7 @@ def {name}({', '.join(fparams)}) -> {map_type(restype)}:
370377
"""
371378

372379
_write_autogen("api_bindings.py", out)
380+
print("success!")
373381

374382

375383
if __name__ == "__main__":

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ classifiers = [
2323
dependencies = [
2424
"typing_extensions",
2525
]
26-
version = "2.2.0-a2"
26+
version = "2.2.0-a3"

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
if __name__ == "__main__":
77
setup(
88
name="pointers.py",
9-
version="2.0.0",
109
author="ZeroIntensity",
1110
author_email="<zintensitydev@gmail.com>",
1211
description="Bringing the hell of pointers to Python.",

src/pointers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
from .std_structs import DivT, Lconv, LDivT, Tm
2828
from .structure import Struct, StructPointer
2929

30-
__version__ = "2.2.0-a2"
30+
__version__ = "2.2.0-a3"

src/pointers/_pyapi.py

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ class PyType_Spec(ctypes.Structure):
7171
]
7272

7373

74+
class Py_tss_t(ctypes.Structure):
75+
pass
76+
77+
78+
class Py_buffer(ctypes.Structure):
79+
_fields_ = [
80+
("buf", ctypes.c_void_p),
81+
("obj", ctypes.c_void_p),
82+
("len", ctypes.c_ssize_t),
83+
("readonly", ctypes.c_int),
84+
("itemsize", ctypes.c_ssize_t),
85+
("format", ctypes.c_char_p),
86+
("ndim", ctypes.c_int),
87+
("shape", ctypes.POINTER(ctypes.c_ssize_t)),
88+
("strides", ctypes.POINTER(ctypes.c_ssize_t)),
89+
("suboffsets", ctypes.POINTER(ctypes.c_ssize_t)),
90+
("internal", ctypes.c_void_p),
91+
]
92+
93+
94+
class PyModuleDef(ctypes.Structure):
95+
_fields_ = [
96+
("m_base", ctypes.c_char_p),
97+
("pfunc", ctypes.c_void_p),
98+
]
99+
100+
74101
Py_UCS4 = ctypes.c_uint32
75102

76103

@@ -131,6 +158,7 @@ class PyType_Spec(ctypes.Structure):
131158
"PyBuffer_FillInfo",
132159
ctypes.c_int,
133160
(
161+
ctypes.POINTER(Py_buffer),
134162
ctypes.py_object,
135163
ctypes.c_void_p,
136164
ctypes.c_ssize_t,
@@ -143,17 +171,32 @@ class PyType_Spec(ctypes.Structure):
143171
"PyBuffer_FromContiguous",
144172
ctypes.c_int,
145173
(
174+
ctypes.POINTER(Py_buffer),
146175
ctypes.c_void_p,
147176
ctypes.c_ssize_t,
148177
ctypes.c_char,
149178
),
150179
)
151180
# void* PyBuffer_GetPointer(const Py_buffer* view, const Py_ssize_t* indices)
152-
_register("PyBuffer_GetPointer", ctypes.c_void_p, (ctypes.POINTER(ctypes.c_ssize_t),))
181+
_register(
182+
"PyBuffer_GetPointer",
183+
ctypes.c_void_p,
184+
(
185+
ctypes.POINTER(Py_buffer),
186+
ctypes.POINTER(ctypes.c_ssize_t),
187+
),
188+
)
153189
# int PyBuffer_IsContiguous(const Py_buffer* view, char order)
154-
_register("PyBuffer_IsContiguous", ctypes.c_int, (ctypes.c_char,))
190+
_register(
191+
"PyBuffer_IsContiguous",
192+
ctypes.c_int,
193+
(
194+
ctypes.POINTER(Py_buffer),
195+
ctypes.c_char,
196+
),
197+
)
155198
# void PyBuffer_Release(Py_buffer* view)
156-
_register("PyBuffer_Release", None, ())
199+
_register("PyBuffer_Release", None, (ctypes.POINTER(Py_buffer),))
157200
# Py_ssize_t PyBuffer_SizeFromFormat(const char* format)
158201
_register(
159202
"PyBuffer_SizeFromFormat",
@@ -167,6 +210,7 @@ class PyType_Spec(ctypes.Structure):
167210
ctypes.c_int,
168211
(
169212
ctypes.c_void_p,
213+
ctypes.POINTER(Py_buffer),
170214
ctypes.c_ssize_t,
171215
ctypes.c_char,
172216
),
@@ -1450,7 +1494,7 @@ class PyType_Spec(ctypes.Structure):
14501494
),
14511495
)
14521496
# PyObject* PyMemoryView_FromBuffer(const Py_buffer* view)
1453-
_register("PyMemoryView_FromBuffer", ctypes.py_object, ())
1497+
_register("PyMemoryView_FromBuffer", ctypes.py_object, (ctypes.POINTER(Py_buffer),))
14541498
# PyObject* PyMemoryView_FromMemory(char* mem, Py_ssize_t size, int flags)
14551499
_register(
14561500
"PyMemoryView_FromMemory",
@@ -2034,7 +2078,14 @@ class PyType_Spec(ctypes.Structure):
20342078
# int PyObject_CheckReadBuffer(PyObject* o)
20352079
_register("PyObject_CheckReadBuffer", ctypes.c_int, (ctypes.py_object,))
20362080
# int PyObject_CopyData(Py_buffer* dest, Py_buffer* src)
2037-
_register("PyObject_CopyData", ctypes.c_int, ())
2081+
_register(
2082+
"PyObject_CopyData",
2083+
ctypes.c_int,
2084+
(
2085+
ctypes.POINTER(Py_buffer),
2086+
ctypes.POINTER(Py_buffer),
2087+
),
2088+
)
20382089
# int PyObject_DelItem(PyObject* o, PyObject* key)
20392090
_register(
20402091
"PyObject_DelItem",
@@ -2139,6 +2190,7 @@ class PyType_Spec(ctypes.Structure):
21392190
ctypes.c_int,
21402191
(
21412192
ctypes.py_object,
2193+
ctypes.POINTER(Py_buffer),
21422194
ctypes.c_int,
21432195
),
21442196
)
@@ -2171,6 +2223,10 @@ class PyType_Spec(ctypes.Structure):
21712223
ctypes.c_char_p,
21722224
),
21732225
)
2226+
# Py_hash_t PyObject_Hash(PyObject* o)
2227+
_register("PyObject_Hash", ctypes.c_ssize_t, (ctypes.py_object,))
2228+
# Py_hash_t PyObject_HashNotImplemented(PyObject* o)
2229+
_register("PyObject_HashNotImplemented", ctypes.c_ssize_t, (ctypes.py_object,))
21742230
# PyObject* PyObject_Init(PyObject* op, PyTypeObject* type)
21752231
_register(
21762232
"PyObject_Init",
@@ -2697,18 +2753,27 @@ class PyType_Spec(ctypes.Structure):
26972753
ctypes.c_void_p,
26982754
),
26992755
)
2756+
# Py_tss_t* PyThread_tss_alloc()
2757+
_register("PyThread_tss_alloc", ctypes.POINTER(Py_tss_t), ())
27002758
# int PyThread_tss_create(Py_tss_t* key)
2701-
_register("PyThread_tss_create", ctypes.c_int, ())
2759+
_register("PyThread_tss_create", ctypes.c_int, (ctypes.POINTER(Py_tss_t),))
27022760
# void PyThread_tss_delete(Py_tss_t* key)
2703-
_register("PyThread_tss_delete", None, ())
2761+
_register("PyThread_tss_delete", None, (ctypes.POINTER(Py_tss_t),))
27042762
# void PyThread_tss_free(Py_tss_t* key)
2705-
_register("PyThread_tss_free", None, ())
2763+
_register("PyThread_tss_free", None, (ctypes.POINTER(Py_tss_t),))
27062764
# void* PyThread_tss_get(Py_tss_t* key)
2707-
_register("PyThread_tss_get", ctypes.c_void_p, ())
2765+
_register("PyThread_tss_get", ctypes.c_void_p, (ctypes.POINTER(Py_tss_t),))
27082766
# int PyThread_tss_is_created(Py_tss_t* key)
2709-
_register("PyThread_tss_is_created", ctypes.c_int, ())
2767+
_register("PyThread_tss_is_created", ctypes.c_int, (ctypes.POINTER(Py_tss_t),))
27102768
# int PyThread_tss_set(Py_tss_t* key, void* value)
2711-
_register("PyThread_tss_set", ctypes.c_int, (ctypes.c_void_p,))
2769+
_register(
2770+
"PyThread_tss_set",
2771+
ctypes.c_int,
2772+
(
2773+
ctypes.POINTER(Py_tss_t),
2774+
ctypes.c_void_p,
2775+
),
2776+
)
27122777
# PyObject* PyTuple_GetItem(PyObject* p, Py_ssize_t pos)
27132778
_register(
27142779
"PyTuple_GetItem",
@@ -2752,17 +2817,21 @@ class PyType_Spec(ctypes.Structure):
27522817
ctypes.py_object,
27532818
(
27542819
ctypes.py_object,
2820+
ctypes.POINTER(PyType_Spec),
27552821
ctypes.py_object,
27562822
),
27572823
minver="3.9",
27582824
)
27592825
# PyObject* PyType_FromSpec(PyType_Spec* spec)
2760-
_register("PyType_FromSpec", ctypes.py_object, ())
2826+
_register("PyType_FromSpec", ctypes.py_object, (ctypes.POINTER(PyType_Spec),))
27612827
# PyObject* PyType_FromSpecWithBases(PyType_Spec* spec, PyObject* bases)
27622828
_register(
27632829
"PyType_FromSpecWithBases",
27642830
ctypes.py_object,
2765-
(ctypes.py_object,),
2831+
(
2832+
ctypes.POINTER(PyType_Spec),
2833+
ctypes.py_object,
2834+
),
27662835
minver="3.3",
27672836
)
27682837
# PyObject* PyType_GenericAlloc(PyTypeObject* type, Py_ssize_t nitems)

0 commit comments

Comments
 (0)