File tree 1 file changed +20
-3
lines changed
1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -39,22 +39,39 @@ Alternatively, you may specify a custom pre-processor command using the `--cpp`
39
39
#### Binding against the Python API
40
40
41
41
``` bash
42
- printf " import ctypes\nPyTypeObject = ctypes.POINTER(None)\n" > overrides.py
42
+ cat > " overrides.py" << END
43
+ import ctypes
44
+
45
+ class PyTypeObject (ctypes.Structure): pass
46
+ class PyObject (ctypes.Structure): pass
47
+
48
+ def POINTER(obj):
49
+ if obj is PyObject: return ctypes.py_object
50
+ return ctypes.POINTER(obj)
51
+ END
52
+
43
53
ctypesgen -l python --dllclass pythonapi --system-headers python3.X/Python.h --all-headers -m .overrides --linkage-anchor . -o ctypes_python.py
44
54
```
45
- (substituting ` 3.X ` with your system's python version). Minimal test:
55
+ substituting ` 3.X ` with your system's python version.
56
+
57
+ Minimal test (run in python console):
46
58
``` python
47
59
from ctypes import *
48
60
from ctypes_python import *
49
61
50
62
v = Py_GetVersion()
51
63
v = cast(v, c_char_p).value.decode(" utf-8" )
52
- print (v)
64
+ v
65
+
66
+ Py_IncRef(v)
67
+ Py_DecRef(v)
53
68
```
69
+
54
70
It should yield something like
55
71
```
56
72
3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 12.3.1 20230508 (Red Hat 12.3.1-1)]
57
73
```
74
+
58
75
and the same as ` sys.version ` :
59
76
``` python
60
77
import sys
You can’t perform that action at this time.
0 commit comments