PyCyBase 0.1.8.post4__cp313-cp313-win_amd64.whl
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.
- cbase/__infra__.pxd +6 -0
- cbase/__init__.pxd +6 -0
- cbase/__init__.py +28 -0
- cbase/allocator_protocol/__infra__.pxd +58 -0
- cbase/allocator_protocol/__init__.pxd +58 -0
- cbase/allocator_protocol/__init__.py +45 -0
- cbase/allocator_protocol/c_allocator_protocol.c +31818 -0
- cbase/allocator_protocol/c_allocator_protocol.cp313-win_amd64.pyd +0 -0
- cbase/allocator_protocol/c_allocator_protocol.h +352 -0
- cbase/allocator_protocol/c_allocator_protocol.pxd +64 -0
- cbase/allocator_protocol/c_allocator_protocol.pyi +144 -0
- cbase/allocator_protocol/c_allocator_protocol.pyx +209 -0
- cbase/allocator_protocol/c_heap_allocator.c +38144 -0
- cbase/allocator_protocol/c_heap_allocator.cp313-win_amd64.pyd +0 -0
- cbase/allocator_protocol/c_heap_allocator.h +444 -0
- cbase/allocator_protocol/c_heap_allocator.pxd +97 -0
- cbase/allocator_protocol/c_heap_allocator.pyi +161 -0
- cbase/allocator_protocol/c_heap_allocator.pyx +300 -0
- cbase/allocator_protocol/c_nt_shm_allocator.c +33399 -0
- cbase/allocator_protocol/c_nt_shm_allocator.cp313-win_amd64.pyd +0 -0
- cbase/allocator_protocol/c_nt_shm_allocator.h +996 -0
- cbase/allocator_protocol/c_nt_shm_allocator.pxd +102 -0
- cbase/allocator_protocol/c_nt_shm_allocator.pyx +223 -0
- cbase/allocator_protocol/c_shm_allocator.h +1168 -0
- cbase/allocator_protocol/c_shm_allocator.pxd +142 -0
- cbase/allocator_protocol/c_shm_allocator.pyi +299 -0
- cbase/allocator_protocol/c_shm_allocator.pyx +442 -0
- cbase/allocator_protocol/c_shm_comp.c +4643 -0
- cbase/allocator_protocol/c_shm_comp.cp313-win_amd64.pyd +0 -0
- cbase/allocator_protocol/c_shm_comp.h +49 -0
- cbase/allocator_protocol/c_shm_comp.pxd +38 -0
- cbase/allocator_protocol/c_shm_comp.pyx +1 -0
- cbase/backports/__infra__.pxd +17 -0
- cbase/backports/__init__.pxd +17 -0
- cbase/backports/__init__.py +9 -0
- cbase/backports/pydict.h +55 -0
- cbase/backports/pydict.pxd +5 -0
- cbase/backports/pylong.c +9946 -0
- cbase/backports/pylong.cp313-win_amd64.pyd +0 -0
- cbase/backports/pylong.h +79 -0
- cbase/backports/pylong.pxd +23 -0
- cbase/backports/pylong.pyx +61 -0
- cbase/bytemap/__infra__.pxd +42 -0
- cbase/bytemap/__init__.pxd +42 -0
- cbase/bytemap/__init__.py +21 -0
- cbase/bytemap/c_bytemap.c +52076 -0
- cbase/bytemap/c_bytemap.cp313-win_amd64.pyd +0 -0
- cbase/bytemap/c_bytemap.h +867 -0
- cbase/bytemap/c_bytemap.pxd +370 -0
- cbase/bytemap/c_bytemap.pyx +1758 -0
- cbase/bytemap/xxh3.h +55 -0
- cbase/bytemap/xxhash.c +42 -0
- cbase/bytemap/xxhash.h +7487 -0
- cbase/env.c +11109 -0
- cbase/env.cp313-win_amd64.pyd +0 -0
- cbase/env.pxd +8 -0
- cbase/env.pyi +48 -0
- cbase/env.pyx +46 -0
- cbase/includes/cbase/allocator_protocol/c_allocator_protocol.c +31818 -0
- cbase/includes/cbase/allocator_protocol/c_allocator_protocol.h +352 -0
- cbase/includes/cbase/allocator_protocol/c_heap_allocator.c +38144 -0
- cbase/includes/cbase/allocator_protocol/c_heap_allocator.h +444 -0
- cbase/includes/cbase/allocator_protocol/c_nt_shm_allocator.c +33399 -0
- cbase/includes/cbase/allocator_protocol/c_nt_shm_allocator.h +996 -0
- cbase/includes/cbase/allocator_protocol/c_shm_allocator.h +1168 -0
- cbase/includes/cbase/allocator_protocol/c_shm_comp.c +4643 -0
- cbase/includes/cbase/allocator_protocol/c_shm_comp.h +49 -0
- cbase/includes/cbase/backports/pydict.h +55 -0
- cbase/includes/cbase/backports/pylong.c +9946 -0
- cbase/includes/cbase/backports/pylong.h +79 -0
- cbase/includes/cbase/bytemap/c_bytemap.c +52076 -0
- cbase/includes/cbase/bytemap/c_bytemap.h +867 -0
- cbase/includes/cbase/bytemap/xxh3.h +55 -0
- cbase/includes/cbase/bytemap/xxhash.c +42 -0
- cbase/includes/cbase/bytemap/xxhash.h +7487 -0
- cbase/includes/cbase/env.c +11109 -0
- cbase/includes/cbase/int128.h +81 -0
- cbase/includes/cbase/intern_string/c_intern_string.c +28081 -0
- cbase/includes/cbase/intern_string/c_intern_string.h +614 -0
- cbase/includes/cbase/nt/pthread_nt_compat.h +102 -0
- cbase/includes/cbase/nt/regex_nt_compat.h +133 -0
- cbase/includes/cbase/nt/time_sched_nt_compat.h +32 -0
- cbase/int128.h +81 -0
- cbase/int128.pxd +15 -0
- cbase/intern_string/BENCHMARK.md +157 -0
- cbase/intern_string/__infra__.pxd +11 -0
- cbase/intern_string/__init__.pxd +11 -0
- cbase/intern_string/__init__.py +19 -0
- cbase/intern_string/c_intern_string.c +28081 -0
- cbase/intern_string/c_intern_string.cp313-win_amd64.pyd +0 -0
- cbase/intern_string/c_intern_string.h +614 -0
- cbase/intern_string/c_intern_string.pxd +118 -0
- cbase/intern_string/c_intern_string.pyi +376 -0
- cbase/intern_string/c_intern_string.pyx +765 -0
- cbase/nt/pthread_nt_compat.h +102 -0
- cbase/nt/regex_nt_compat.h +133 -0
- cbase/nt/time_sched_nt_compat.h +32 -0
- pycybase-0.1.8.post4.dist-info/METADATA +180 -0
- pycybase-0.1.8.post4.dist-info/RECORD +101 -0
- pycybase-0.1.8.post4.dist-info/WHEEL +5 -0
- pycybase-0.1.8.post4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
from libc.errno cimport errno
|
|
2
|
+
from libc.stdint cimport uintptr_t
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
cdef class HeapMemoryPage:
|
|
6
|
+
def __cinit__(self, uintptr_t page_addr=0):
|
|
7
|
+
self.page = <heap_page*> page_addr if page_addr else NULL
|
|
8
|
+
|
|
9
|
+
@staticmethod
|
|
10
|
+
cdef inline HeapMemoryPage c_from_header(heap_page* header):
|
|
11
|
+
cdef HeapMemoryPage instance = HeapMemoryPage.__new__(HeapMemoryPage, 0)
|
|
12
|
+
instance.page = header
|
|
13
|
+
return instance
|
|
14
|
+
|
|
15
|
+
def __repr__(self):
|
|
16
|
+
if self.page:
|
|
17
|
+
return f"<{self.__class__.__name__}>(capacity={self.capacity:,}, occupied={self.occupied:,})"
|
|
18
|
+
return f"<{self.__class__.__name__}>(uninitialized)"
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def from_buffer(cls, uintptr_t buffer_addr) -> HeapMemoryPage:
|
|
22
|
+
cdef HeapMemoryPage instance = cls.__new__(cls, 0)
|
|
23
|
+
instance.page = <heap_page*> (<char*> buffer_addr - sizeof(heap_page))
|
|
24
|
+
return instance
|
|
25
|
+
|
|
26
|
+
def allocated(self):
|
|
27
|
+
if not self.page:
|
|
28
|
+
return
|
|
29
|
+
cdef heap_memory_block* block = self.page.allocated
|
|
30
|
+
while block:
|
|
31
|
+
yield HeapMemoryBlock.c_from_header(block, False)
|
|
32
|
+
block = block.next_allocated
|
|
33
|
+
|
|
34
|
+
cpdef void reclaim(self):
|
|
35
|
+
if not self.page:
|
|
36
|
+
raise RuntimeError(f"Uninitialized <{self.__class__.__name__}>")
|
|
37
|
+
c_heap_page_reclaim(self.page.allocator, self.page)
|
|
38
|
+
|
|
39
|
+
property capacity:
|
|
40
|
+
def __get__(self):
|
|
41
|
+
if self.page:
|
|
42
|
+
return <size_t> self.page.capacity
|
|
43
|
+
return 0
|
|
44
|
+
|
|
45
|
+
property occupied:
|
|
46
|
+
def __get__(self):
|
|
47
|
+
if self.page:
|
|
48
|
+
return <size_t> self.page.occupied
|
|
49
|
+
return 0
|
|
50
|
+
|
|
51
|
+
property allocator:
|
|
52
|
+
def __get__(self):
|
|
53
|
+
if not self.page:
|
|
54
|
+
return None
|
|
55
|
+
return HeapAllocator.c_from_header(self.page.allocator, False)
|
|
56
|
+
|
|
57
|
+
property address:
|
|
58
|
+
def __get__(self):
|
|
59
|
+
if not self.page:
|
|
60
|
+
return None
|
|
61
|
+
return f"{<uintptr_t> self.page.buffer:#0x}"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
cdef class HeapMemoryBlock:
|
|
65
|
+
def __cinit__(self, uintptr_t block=0, bint owner=False):
|
|
66
|
+
self.block = <heap_memory_block*> block if block else NULL
|
|
67
|
+
self.owner = owner
|
|
68
|
+
|
|
69
|
+
def __dealloc__(self):
|
|
70
|
+
if not self.owner:
|
|
71
|
+
return
|
|
72
|
+
|
|
73
|
+
if self.block:
|
|
74
|
+
c_heap_free(self.block.buffer, &self.block.parent_page.allocator.lock)
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
cdef inline HeapMemoryBlock c_from_header(heap_memory_block* header, bint owner=False):
|
|
78
|
+
cdef HeapMemoryBlock instance = HeapMemoryBlock.__new__(HeapMemoryBlock, 0, owner)
|
|
79
|
+
instance.block = header
|
|
80
|
+
return instance
|
|
81
|
+
|
|
82
|
+
def __repr__(self):
|
|
83
|
+
if self.block:
|
|
84
|
+
return f"<{self.__class__.__name__}>(size={self.block.size}, capacity={self.block.capacity})"
|
|
85
|
+
return f"<{self.__class__.__name__}>(uninitialized)"
|
|
86
|
+
|
|
87
|
+
property size:
|
|
88
|
+
def __get__(self):
|
|
89
|
+
if not self.block:
|
|
90
|
+
return -1
|
|
91
|
+
return <size_t> self.block.size
|
|
92
|
+
|
|
93
|
+
property capacity:
|
|
94
|
+
def __get__(self):
|
|
95
|
+
if not self.block:
|
|
96
|
+
return -1
|
|
97
|
+
return <size_t> self.block.capacity
|
|
98
|
+
|
|
99
|
+
property next_free:
|
|
100
|
+
def __get__(self):
|
|
101
|
+
if self.block and self.block.next_free:
|
|
102
|
+
return HeapMemoryBlock.c_from_header(self.block.next_free, False)
|
|
103
|
+
return None
|
|
104
|
+
|
|
105
|
+
property next_allocated:
|
|
106
|
+
def __get__(self):
|
|
107
|
+
if self.block and self.block.next_allocated:
|
|
108
|
+
return HeapMemoryBlock.c_from_header(self.block.next_allocated, False)
|
|
109
|
+
return None
|
|
110
|
+
|
|
111
|
+
property parent_page:
|
|
112
|
+
def __get__(self):
|
|
113
|
+
if not self.block:
|
|
114
|
+
return None
|
|
115
|
+
return HeapMemoryPage.c_from_header(self.block.parent_page)
|
|
116
|
+
|
|
117
|
+
property buffer:
|
|
118
|
+
def __get__(self):
|
|
119
|
+
if not self.block:
|
|
120
|
+
return None
|
|
121
|
+
cdef size_t size = self.block.size
|
|
122
|
+
return <char[:size]> self.block.buffer
|
|
123
|
+
|
|
124
|
+
property address:
|
|
125
|
+
def __get__(self):
|
|
126
|
+
if not self.block:
|
|
127
|
+
return None
|
|
128
|
+
return f"{<uintptr_t> self.block.buffer:#0x}"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
cdef class HeapAllocator:
|
|
132
|
+
def __init__(self):
|
|
133
|
+
self.allocator = c_heap_allocator_new()
|
|
134
|
+
if not self.allocator:
|
|
135
|
+
raise OSError(errno, "Initialize heap allocator failed")
|
|
136
|
+
self.owner = True
|
|
137
|
+
|
|
138
|
+
def __dealloc__(self):
|
|
139
|
+
if not self.owner:
|
|
140
|
+
return
|
|
141
|
+
|
|
142
|
+
if self.allocator:
|
|
143
|
+
c_heap_allocator_free(self.allocator)
|
|
144
|
+
|
|
145
|
+
@staticmethod
|
|
146
|
+
cdef HeapAllocator c_from_header(heap_allocator* header, bint owner=False):
|
|
147
|
+
cdef HeapAllocator instance = HeapAllocator.__new__(HeapAllocator)
|
|
148
|
+
instance.allocator = header
|
|
149
|
+
instance.owner = owner
|
|
150
|
+
return instance
|
|
151
|
+
|
|
152
|
+
cdef inline heap_page* c_extend(self, size_t capacity=0, pthread_mutex_t* lock=NULL):
|
|
153
|
+
if not self.allocator:
|
|
154
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
155
|
+
return c_heap_allocator_extend(self.allocator, capacity, lock)
|
|
156
|
+
|
|
157
|
+
cdef inline void* c_calloc(self, size_t size, pthread_mutex_t* lock=NULL):
|
|
158
|
+
if not self.allocator:
|
|
159
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
160
|
+
return c_heap_calloc(self.allocator, size, lock)
|
|
161
|
+
|
|
162
|
+
cdef inline void* c_request(self, size_t size, int scan_all_pages=1, pthread_mutex_t* lock=NULL):
|
|
163
|
+
if not self.allocator:
|
|
164
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
165
|
+
return c_heap_request(self.allocator, size, scan_all_pages, lock)
|
|
166
|
+
|
|
167
|
+
cdef inline void c_free(self, void* ptr, pthread_mutex_t* lock=NULL):
|
|
168
|
+
if not self.allocator:
|
|
169
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
170
|
+
c_heap_free(ptr, lock)
|
|
171
|
+
|
|
172
|
+
cpdef HeapMemoryPage extend(self, size_t capacity=0, bint with_lock=True):
|
|
173
|
+
if not self.allocator:
|
|
174
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
175
|
+
cdef pthread_mutex_t* lock = &self.allocator.lock if with_lock else NULL
|
|
176
|
+
cdef heap_page* page = c_heap_allocator_extend(self.allocator, capacity, lock)
|
|
177
|
+
if not page:
|
|
178
|
+
raise OSError(errno, f'<{self.__class__.__name__}> failed to extend new page')
|
|
179
|
+
return HeapMemoryPage.c_from_header(page)
|
|
180
|
+
|
|
181
|
+
cpdef HeapMemoryBlock calloc(self, size_t size, bint with_lock=True):
|
|
182
|
+
if not self.allocator:
|
|
183
|
+
raise RuntimeError(f"Uninitialized <{self.__class__.__name__}>")
|
|
184
|
+
cdef pthread_mutex_t* lock = &self.allocator.lock if with_lock else NULL
|
|
185
|
+
cdef void* p = c_heap_calloc(self.allocator, size, lock)
|
|
186
|
+
if not p:
|
|
187
|
+
raise OSError(errno, f"<{self.__class__.__name__}> failed to calloc new buffer")
|
|
188
|
+
cdef heap_memory_block* block = <heap_memory_block*> (<char*> p - sizeof(heap_memory_block))
|
|
189
|
+
return HeapMemoryBlock.c_from_header(block, True)
|
|
190
|
+
|
|
191
|
+
cpdef HeapMemoryBlock request(self, size_t size, bint with_lock=True, bint scan_all_pages=True):
|
|
192
|
+
if not self.allocator:
|
|
193
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
194
|
+
cdef pthread_mutex_t* lock = &self.allocator.lock if with_lock else NULL
|
|
195
|
+
cdef void* p = c_heap_request(self.allocator, size, <int> scan_all_pages, lock)
|
|
196
|
+
if not p:
|
|
197
|
+
raise OSError(errno, f'<{self.__class__.__name__}> failed to request new buffer')
|
|
198
|
+
cdef heap_memory_block* block = <heap_memory_block*> (<char*> p - sizeof(heap_memory_block))
|
|
199
|
+
return HeapMemoryBlock.c_from_header(block, True)
|
|
200
|
+
|
|
201
|
+
cpdef void free(self, HeapMemoryBlock buffer, bint with_lock=True):
|
|
202
|
+
if not self.allocator:
|
|
203
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
204
|
+
if not buffer or not buffer.block:
|
|
205
|
+
return
|
|
206
|
+
cdef pthread_mutex_t* lock = &buffer.block.parent_page.allocator.lock if with_lock else NULL
|
|
207
|
+
c_heap_free(<void*> buffer.block.buffer, lock)
|
|
208
|
+
buffer.owner = False
|
|
209
|
+
buffer.block = NULL
|
|
210
|
+
|
|
211
|
+
cpdef void reclaim(self, bint with_lock=True):
|
|
212
|
+
if not self.allocator:
|
|
213
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
214
|
+
cdef pthread_mutex_t* lock = &self.allocator.lock if with_lock else NULL
|
|
215
|
+
c_heap_reclaim(self.allocator, lock)
|
|
216
|
+
|
|
217
|
+
def pages(self):
|
|
218
|
+
if not self.allocator:
|
|
219
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
220
|
+
cdef heap_page* page = self.allocator.active_page
|
|
221
|
+
while page:
|
|
222
|
+
yield HeapMemoryPage.c_from_header(page)
|
|
223
|
+
page = page.prev
|
|
224
|
+
|
|
225
|
+
def allocated(self):
|
|
226
|
+
if not self.allocator:
|
|
227
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
228
|
+
cdef heap_page* page = self.allocator.active_page
|
|
229
|
+
cdef heap_memory_block* block
|
|
230
|
+
while page:
|
|
231
|
+
block = page.allocated
|
|
232
|
+
while block:
|
|
233
|
+
yield HeapMemoryBlock.c_from_header(block, False)
|
|
234
|
+
block = block.next_allocated
|
|
235
|
+
page = page.prev
|
|
236
|
+
|
|
237
|
+
def free_list(self):
|
|
238
|
+
if not self.allocator:
|
|
239
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
240
|
+
cdef heap_memory_block* block = self.allocator.free_list
|
|
241
|
+
while block:
|
|
242
|
+
yield HeapMemoryBlock.c_from_header(block, False)
|
|
243
|
+
block = block.next_free
|
|
244
|
+
|
|
245
|
+
property mapped_pages:
|
|
246
|
+
def __get__(self):
|
|
247
|
+
if not self.allocator:
|
|
248
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
249
|
+
return <size_t> self.allocator.mapped_pages
|
|
250
|
+
|
|
251
|
+
property active_page:
|
|
252
|
+
def __get__(self):
|
|
253
|
+
if not self.allocator:
|
|
254
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}> or no active page')
|
|
255
|
+
elif not self.allocator.active_page:
|
|
256
|
+
return None
|
|
257
|
+
return HeapMemoryPage.c_from_header(self.allocator.active_page)
|
|
258
|
+
|
|
259
|
+
property autopage_capacity:
|
|
260
|
+
def __get__(self):
|
|
261
|
+
if not self.allocator:
|
|
262
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
263
|
+
return <size_t> self.allocator.autopage_capacity
|
|
264
|
+
|
|
265
|
+
def __set__(self, size_t value):
|
|
266
|
+
if not self.allocator:
|
|
267
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
268
|
+
self.allocator.autopage_capacity = value
|
|
269
|
+
|
|
270
|
+
property autopage_capacity_max:
|
|
271
|
+
def __get__(self):
|
|
272
|
+
if not self.allocator:
|
|
273
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
274
|
+
return <size_t> self.allocator.autopage_capacity_max
|
|
275
|
+
|
|
276
|
+
def __set__(self, size_t value):
|
|
277
|
+
if not self.allocator:
|
|
278
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
279
|
+
self.allocator.autopage_capacity_max = value
|
|
280
|
+
|
|
281
|
+
property autopage_alignment:
|
|
282
|
+
def __get__(self):
|
|
283
|
+
if not self.allocator:
|
|
284
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
285
|
+
return <size_t> self.allocator.autopage_alignment
|
|
286
|
+
|
|
287
|
+
def __set__(self, size_t value):
|
|
288
|
+
if not self.allocator:
|
|
289
|
+
raise RuntimeError(f'Uninitialized <{self.__class__.__name__}>')
|
|
290
|
+
self.allocator.autopage_alignment = value
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
cdef HeapAllocator ALLOCATOR = HeapAllocator()
|
|
294
|
+
ALLOCATOR.owner = False
|
|
295
|
+
cdef heap_allocator* C_ALLOCATOR = ALLOCATOR.allocator
|
|
296
|
+
|
|
297
|
+
globals()['ALLOCATOR'] = ALLOCATOR
|
|
298
|
+
globals()['DEFAULT_AUTOPAGE_CAPACITY'] = AP_HEAP_AUTOPAGE_CAPACITY
|
|
299
|
+
globals()['MAX_AUTOPAGE_CAPACITY'] = AP_HEAP_AUTOPAGE_CAPACITY_MAX
|
|
300
|
+
globals()['DEFAULT_AUTOPAGE_ALIGNMENT'] = AP_HEAP_AUTOPAGE_ALIGNMENT
|