cbridge 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cbridge-0.2.0 → cbridge-0.2.2}/PKG-INFO +1 -4
- {cbridge-0.2.0 → cbridge-0.2.2}/README.md +0 -3
- {cbridge-0.2.0 → cbridge-0.2.2}/pyproject.toml +1 -1
- {cbridge-0.2.0 → cbridge-0.2.2}/src/cbridge/__init__.py +1 -1
- {cbridge-0.2.0 → cbridge-0.2.2}/src/cbridge/cbridge.py +22 -13
- {cbridge-0.2.0 → cbridge-0.2.2}/src/cbridge/types.py +32 -28
- {cbridge-0.2.0 → cbridge-0.2.2}/src/cbridge/cfunc.py +0 -0
- {cbridge-0.2.0 → cbridge-0.2.2}/src/cbridge/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cbridge
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Creating ctype structure like dataclass
|
|
5
5
|
Author: ZhengYu, Xu
|
|
6
6
|
Author-email: ZhengYu, Xu <zen-xu@outlook.com>
|
|
@@ -177,9 +177,6 @@ print(Config(name=b"test")) # Config(name=b'test', timeout=30, flags=[0, 1])
|
|
|
177
177
|
|
|
178
178
|
### Pointer Operations
|
|
179
179
|
|
|
180
|
-
> [!WARNING]
|
|
181
|
-
> Python 3.13 and above are currently not supported forward declarations
|
|
182
|
-
|
|
183
180
|
```python
|
|
184
181
|
from cbridge import CStruct
|
|
185
182
|
from cbridge import types
|
|
@@ -154,9 +154,6 @@ print(Config(name=b"test")) # Config(name=b'test', timeout=30, flags=[0, 1])
|
|
|
154
154
|
|
|
155
155
|
### Pointer Operations
|
|
156
156
|
|
|
157
|
-
> [!WARNING]
|
|
158
|
-
> Python 3.13 and above are currently not supported forward declarations
|
|
159
|
-
|
|
160
157
|
```python
|
|
161
158
|
from cbridge import CStruct
|
|
162
159
|
from cbridge import types
|
|
@@ -36,10 +36,24 @@ class CStructType(_CStructType):
|
|
|
36
36
|
pack: int = 0,
|
|
37
37
|
**extra,
|
|
38
38
|
):
|
|
39
|
-
if
|
|
40
|
-
attrs["
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
if pack:
|
|
40
|
+
attrs["_pack_"] = pack
|
|
41
|
+
# Python 3.14+ only allows _pack_ with the MSVC-compatible layout
|
|
42
|
+
attrs["_layout_"] = "ms"
|
|
43
|
+
return super().__new__(meta_self, name, bases, attrs)
|
|
44
|
+
|
|
45
|
+
# Since Python 3.13, ctypes initializes structure storage info in tp_init
|
|
46
|
+
# instead of tp_new, so field resolution (which may create pointers to the
|
|
47
|
+
# class itself for forward declarations) must happen after super().__init__
|
|
48
|
+
def __init__(
|
|
49
|
+
cls, # noqa: N805
|
|
50
|
+
name: str,
|
|
51
|
+
bases: tuple[type, ...],
|
|
52
|
+
attrs: dict[str, Any],
|
|
53
|
+
pack: int = 0,
|
|
54
|
+
**extra,
|
|
55
|
+
):
|
|
56
|
+
super().__init__(name, bases, attrs)
|
|
43
57
|
fields_map = {
|
|
44
58
|
f_name: f_type
|
|
45
59
|
for f_name, f_type in get_type_hints(
|
|
@@ -50,14 +64,11 @@ class CStructType(_CStructType):
|
|
|
50
64
|
fields = list(fields_map.items())
|
|
51
65
|
if fields:
|
|
52
66
|
# update fields
|
|
53
|
-
|
|
54
|
-
cls._fields_[:] = fields
|
|
55
|
-
else:
|
|
56
|
-
cls._fields_ = fields
|
|
67
|
+
cls._fields_ = fields
|
|
57
68
|
|
|
58
|
-
|
|
69
|
+
ds.dataclass(cls)
|
|
59
70
|
|
|
60
|
-
@wraps(cls.__init__)
|
|
71
|
+
@wraps(cls.__init__) # type: ignore[misc]
|
|
61
72
|
def wrapped_init(self, *args, **kwargs):
|
|
62
73
|
args = list(args)
|
|
63
74
|
|
|
@@ -86,9 +97,7 @@ class CStructType(_CStructType):
|
|
|
86
97
|
|
|
87
98
|
return ctypes.Structure.__init__(self, **kwargs)
|
|
88
99
|
|
|
89
|
-
cls.__init__ = wrapped_init
|
|
90
|
-
|
|
91
|
-
return cls
|
|
100
|
+
cls.__init__ = wrapped_init # type: ignore[misc]
|
|
92
101
|
|
|
93
102
|
|
|
94
103
|
field = ds.field
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# pyright: reportGeneralTypeIssues=false
|
|
2
|
+
import builtins
|
|
2
3
|
import ctypes
|
|
3
4
|
|
|
4
5
|
from collections.abc import Sequence
|
|
@@ -18,6 +19,10 @@ if TYPE_CHECKING:
|
|
|
18
19
|
from typing_extensions import Self
|
|
19
20
|
|
|
20
21
|
class CData(_CData, Generic[_T]):
|
|
22
|
+
def __lt__(self, other: Any) -> bool: ...
|
|
23
|
+
def __le__(self, other: Any) -> bool: ...
|
|
24
|
+
def __gt__(self, other: Any) -> bool: ...
|
|
25
|
+
def __ge__(self, other: Any) -> bool: ...
|
|
21
26
|
def __iadd__(self, other: _T) -> Self: ...
|
|
22
27
|
def __isub__(self, other: _T) -> Self: ...
|
|
23
28
|
def __imul__(self, other: _T) -> Self: ...
|
|
@@ -47,32 +52,33 @@ if TYPE_CHECKING:
|
|
|
47
52
|
def __abs__(self) -> Self: ...
|
|
48
53
|
def __invert__(self) -> Self: ...
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
_CDataType = Union[_T, CData[_T]]
|
|
56
|
+
bool = _CDataType[builtins.bool]
|
|
57
|
+
byte = _CDataType[builtins.bytes]
|
|
58
|
+
char = _CDataType[builtins.bytes]
|
|
59
|
+
double = _CDataType[builtins.float]
|
|
60
|
+
float = _CDataType[builtins.float]
|
|
61
|
+
ubyte = _CDataType[builtins.bytes]
|
|
62
|
+
int = _CDataType[builtins.int]
|
|
63
|
+
int8 = _CDataType[builtins.int]
|
|
64
|
+
int16 = _CDataType[builtins.int]
|
|
65
|
+
int32 = _CDataType[builtins.int]
|
|
66
|
+
int64 = _CDataType[builtins.int]
|
|
67
|
+
long = _CDataType[builtins.int]
|
|
68
|
+
longdouble = _CDataType[builtins.float]
|
|
69
|
+
longlong = _CDataType[builtins.float]
|
|
70
|
+
short = _CDataType[builtins.int]
|
|
71
|
+
size_t = _CDataType[builtins.int]
|
|
72
|
+
ssize_t = _CDataType[builtins.int]
|
|
73
|
+
uint = _CDataType[builtins.int]
|
|
74
|
+
uint8 = _CDataType[builtins.int]
|
|
75
|
+
uint16 = _CDataType[builtins.int]
|
|
76
|
+
uint32 = _CDataType[builtins.int]
|
|
77
|
+
uint64 = _CDataType[builtins.int]
|
|
78
|
+
ulong = _CDataType[builtins.int]
|
|
79
|
+
ulonglong = _CDataType[builtins.int]
|
|
80
|
+
ushort = _CDataType[builtins.int]
|
|
81
|
+
wchar = _CDataType[builtins.str]
|
|
76
82
|
void_ptr = Union[ctypes.c_void_p, Any]
|
|
77
83
|
|
|
78
84
|
_Len = TypeVar("_Len")
|
|
@@ -126,8 +132,6 @@ else:
|
|
|
126
132
|
char_ptr = ctypes.c_char_p
|
|
127
133
|
wchar_ptr = ctypes.c_wchar_p
|
|
128
134
|
|
|
129
|
-
import builtins
|
|
130
|
-
|
|
131
135
|
from typing import get_args
|
|
132
136
|
|
|
133
137
|
class Array:
|
|
File without changes
|
|
File without changes
|