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.
Files changed (101) hide show
  1. cbase/__infra__.pxd +6 -0
  2. cbase/__init__.pxd +6 -0
  3. cbase/__init__.py +28 -0
  4. cbase/allocator_protocol/__infra__.pxd +58 -0
  5. cbase/allocator_protocol/__init__.pxd +58 -0
  6. cbase/allocator_protocol/__init__.py +45 -0
  7. cbase/allocator_protocol/c_allocator_protocol.c +31818 -0
  8. cbase/allocator_protocol/c_allocator_protocol.cp313-win_amd64.pyd +0 -0
  9. cbase/allocator_protocol/c_allocator_protocol.h +352 -0
  10. cbase/allocator_protocol/c_allocator_protocol.pxd +64 -0
  11. cbase/allocator_protocol/c_allocator_protocol.pyi +144 -0
  12. cbase/allocator_protocol/c_allocator_protocol.pyx +209 -0
  13. cbase/allocator_protocol/c_heap_allocator.c +38144 -0
  14. cbase/allocator_protocol/c_heap_allocator.cp313-win_amd64.pyd +0 -0
  15. cbase/allocator_protocol/c_heap_allocator.h +444 -0
  16. cbase/allocator_protocol/c_heap_allocator.pxd +97 -0
  17. cbase/allocator_protocol/c_heap_allocator.pyi +161 -0
  18. cbase/allocator_protocol/c_heap_allocator.pyx +300 -0
  19. cbase/allocator_protocol/c_nt_shm_allocator.c +33399 -0
  20. cbase/allocator_protocol/c_nt_shm_allocator.cp313-win_amd64.pyd +0 -0
  21. cbase/allocator_protocol/c_nt_shm_allocator.h +996 -0
  22. cbase/allocator_protocol/c_nt_shm_allocator.pxd +102 -0
  23. cbase/allocator_protocol/c_nt_shm_allocator.pyx +223 -0
  24. cbase/allocator_protocol/c_shm_allocator.h +1168 -0
  25. cbase/allocator_protocol/c_shm_allocator.pxd +142 -0
  26. cbase/allocator_protocol/c_shm_allocator.pyi +299 -0
  27. cbase/allocator_protocol/c_shm_allocator.pyx +442 -0
  28. cbase/allocator_protocol/c_shm_comp.c +4643 -0
  29. cbase/allocator_protocol/c_shm_comp.cp313-win_amd64.pyd +0 -0
  30. cbase/allocator_protocol/c_shm_comp.h +49 -0
  31. cbase/allocator_protocol/c_shm_comp.pxd +38 -0
  32. cbase/allocator_protocol/c_shm_comp.pyx +1 -0
  33. cbase/backports/__infra__.pxd +17 -0
  34. cbase/backports/__init__.pxd +17 -0
  35. cbase/backports/__init__.py +9 -0
  36. cbase/backports/pydict.h +55 -0
  37. cbase/backports/pydict.pxd +5 -0
  38. cbase/backports/pylong.c +9946 -0
  39. cbase/backports/pylong.cp313-win_amd64.pyd +0 -0
  40. cbase/backports/pylong.h +79 -0
  41. cbase/backports/pylong.pxd +23 -0
  42. cbase/backports/pylong.pyx +61 -0
  43. cbase/bytemap/__infra__.pxd +42 -0
  44. cbase/bytemap/__init__.pxd +42 -0
  45. cbase/bytemap/__init__.py +21 -0
  46. cbase/bytemap/c_bytemap.c +52076 -0
  47. cbase/bytemap/c_bytemap.cp313-win_amd64.pyd +0 -0
  48. cbase/bytemap/c_bytemap.h +867 -0
  49. cbase/bytemap/c_bytemap.pxd +370 -0
  50. cbase/bytemap/c_bytemap.pyx +1758 -0
  51. cbase/bytemap/xxh3.h +55 -0
  52. cbase/bytemap/xxhash.c +42 -0
  53. cbase/bytemap/xxhash.h +7487 -0
  54. cbase/env.c +11109 -0
  55. cbase/env.cp313-win_amd64.pyd +0 -0
  56. cbase/env.pxd +8 -0
  57. cbase/env.pyi +48 -0
  58. cbase/env.pyx +46 -0
  59. cbase/includes/cbase/allocator_protocol/c_allocator_protocol.c +31818 -0
  60. cbase/includes/cbase/allocator_protocol/c_allocator_protocol.h +352 -0
  61. cbase/includes/cbase/allocator_protocol/c_heap_allocator.c +38144 -0
  62. cbase/includes/cbase/allocator_protocol/c_heap_allocator.h +444 -0
  63. cbase/includes/cbase/allocator_protocol/c_nt_shm_allocator.c +33399 -0
  64. cbase/includes/cbase/allocator_protocol/c_nt_shm_allocator.h +996 -0
  65. cbase/includes/cbase/allocator_protocol/c_shm_allocator.h +1168 -0
  66. cbase/includes/cbase/allocator_protocol/c_shm_comp.c +4643 -0
  67. cbase/includes/cbase/allocator_protocol/c_shm_comp.h +49 -0
  68. cbase/includes/cbase/backports/pydict.h +55 -0
  69. cbase/includes/cbase/backports/pylong.c +9946 -0
  70. cbase/includes/cbase/backports/pylong.h +79 -0
  71. cbase/includes/cbase/bytemap/c_bytemap.c +52076 -0
  72. cbase/includes/cbase/bytemap/c_bytemap.h +867 -0
  73. cbase/includes/cbase/bytemap/xxh3.h +55 -0
  74. cbase/includes/cbase/bytemap/xxhash.c +42 -0
  75. cbase/includes/cbase/bytemap/xxhash.h +7487 -0
  76. cbase/includes/cbase/env.c +11109 -0
  77. cbase/includes/cbase/int128.h +81 -0
  78. cbase/includes/cbase/intern_string/c_intern_string.c +28081 -0
  79. cbase/includes/cbase/intern_string/c_intern_string.h +614 -0
  80. cbase/includes/cbase/nt/pthread_nt_compat.h +102 -0
  81. cbase/includes/cbase/nt/regex_nt_compat.h +133 -0
  82. cbase/includes/cbase/nt/time_sched_nt_compat.h +32 -0
  83. cbase/int128.h +81 -0
  84. cbase/int128.pxd +15 -0
  85. cbase/intern_string/BENCHMARK.md +157 -0
  86. cbase/intern_string/__infra__.pxd +11 -0
  87. cbase/intern_string/__init__.pxd +11 -0
  88. cbase/intern_string/__init__.py +19 -0
  89. cbase/intern_string/c_intern_string.c +28081 -0
  90. cbase/intern_string/c_intern_string.cp313-win_amd64.pyd +0 -0
  91. cbase/intern_string/c_intern_string.h +614 -0
  92. cbase/intern_string/c_intern_string.pxd +118 -0
  93. cbase/intern_string/c_intern_string.pyi +376 -0
  94. cbase/intern_string/c_intern_string.pyx +765 -0
  95. cbase/nt/pthread_nt_compat.h +102 -0
  96. cbase/nt/regex_nt_compat.h +133 -0
  97. cbase/nt/time_sched_nt_compat.h +32 -0
  98. pycybase-0.1.8.post4.dist-info/METADATA +180 -0
  99. pycybase-0.1.8.post4.dist-info/RECORD +101 -0
  100. pycybase-0.1.8.post4.dist-info/WHEEL +5 -0
  101. pycybase-0.1.8.post4.dist-info/top_level.txt +1 -0
@@ -0,0 +1,209 @@
1
+ from libc.stdint cimport uintptr_t
2
+ from libc.stdlib cimport calloc
3
+
4
+ from .c_heap_allocator cimport C_ALLOCATOR as HEAP_ALLOCATOR
5
+ from .c_shm_comp cimport C_SHM_COMP as SHM_ALLOCATOR
6
+
7
+
8
+ cdef class AllocatorConfigContext(EnvConfigContext):
9
+ def __init__(self, dict overrides=None, **kwargs):
10
+ super().__init__(overrides, **kwargs)
11
+ self.c_bind()
12
+
13
+ cdef void c_bind(self, allocator_protocol* schematic=NULL):
14
+ self.allocator_schematic = schematic if schematic else AP_DEFAULT_ALLOCATOR
15
+
16
+ cdef void c_activate(self):
17
+ if not self.allocator_schematic:
18
+ raise RuntimeError(f'<{self.__class__.__name__}> not bound!')
19
+
20
+ EnvConfigContext.c_activate(self)
21
+
22
+ if 'locked' in self.overrides:
23
+ self.originals['locked'] = self.allocator_schematic.with_lock
24
+ self.allocator_schematic.with_lock = self.overrides['locked']
25
+
26
+ if 'shared' in self.overrides:
27
+ self.originals['shared'] = self.allocator_schematic.with_shm
28
+ self.allocator_schematic.with_shm = self.overrides['shared']
29
+
30
+ if 'freelist' in self.overrides:
31
+ self.originals['freelist'] = self.allocator_schematic.with_freelist
32
+ self.allocator_schematic.with_freelist = self.overrides['freelist']
33
+
34
+ if 'autopage_capacity' in self.overrides:
35
+ if self.allocator_schematic.heap_allocator:
36
+ self.originals['heap.autopage_capacity'] = self.allocator_schematic.heap_allocator.autopage_capacity
37
+ self.allocator_schematic.heap_allocator.autopage_capacity = self.overrides['autopage_capacity']
38
+ if self.allocator_schematic.shm_allocator_ctx and self.allocator_schematic.shm_allocator_ctx.shm_allocator:
39
+ self.originals['shm.autopage_capacity'] = self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_capacity
40
+ self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_capacity = self.overrides['autopage_capacity']
41
+
42
+ if 'autopage_capacity_max' in self.overrides:
43
+ if self.allocator_schematic.heap_allocator:
44
+ self.originals['heap.autopage_capacity_max'] = self.allocator_schematic.heap_allocator.autopage_capacity_max
45
+ self.allocator_schematic.heap_allocator.autopage_capacity_max = self.overrides['autopage_capacity_max']
46
+ if self.allocator_schematic.shm_allocator_ctx and self.allocator_schematic.shm_allocator_ctx.shm_allocator:
47
+ self.originals['shm.autopage_capacity_max'] = self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_capacity_max
48
+ self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_capacity_max = self.overrides['autopage_capacity_max']
49
+
50
+ if 'autopage_alignment' in self.overrides:
51
+ if self.allocator_schematic.heap_allocator:
52
+ self.originals['heap.autopage_alignment'] = self.allocator_schematic.heap_allocator.autopage_alignment
53
+ self.allocator_schematic.heap_allocator.autopage_alignment = self.overrides['autopage_alignment']
54
+ if self.allocator_schematic.shm_allocator_ctx and self.allocator_schematic.shm_allocator_ctx.shm_allocator:
55
+ self.originals['shm.autopage_alignment'] = self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_alignment
56
+ self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_alignment = self.overrides['autopage_alignment']
57
+
58
+ cdef void c_deactivate(self):
59
+ if not self.allocator_schematic:
60
+ raise RuntimeError(f'<{self.__class__.__name__}> not bound!')
61
+
62
+ EnvConfigContext.c_deactivate(self)
63
+
64
+ if 'locked' in self.originals:
65
+ self.allocator_schematic.with_lock = self.originals.pop('locked')
66
+
67
+ if 'shared' in self.originals:
68
+ self.allocator_schematic.with_shm = self.originals.pop('shared')
69
+
70
+ if 'freelist' in self.originals:
71
+ self.allocator_schematic.with_freelist = self.originals.pop('freelist')
72
+
73
+ if 'heap.autopage_capacity' in self.originals:
74
+ self.allocator_schematic.heap_allocator.autopage_capacity = self.originals.pop('heap.autopage_capacity')
75
+
76
+ if 'shm.autopage_capacity' in self.originals:
77
+ self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_capacity = self.originals.pop('shm.autopage_capacity')
78
+
79
+ if 'heap.autopage_capacity_max' in self.originals:
80
+ self.allocator_schematic.heap_allocator.autopage_capacity_max = self.originals.pop('heap.autopage_capacity_max')
81
+
82
+ if 'shm.autopage_capacity_max' in self.originals:
83
+ self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_capacity_max = self.originals.pop('shm.autopage_capacity_max')
84
+
85
+ if 'heap.autopage_alignment' in self.originals:
86
+ self.allocator_schematic.heap_allocator.autopage_alignment = self.originals.pop('heap.autopage_alignment')
87
+
88
+ if 'shm.autopage_alignment' in self.originals:
89
+ self.allocator_schematic.shm_allocator_ctx.shm_allocator.autopage_alignment = self.originals.pop('shm.autopage_alignment')
90
+
91
+ def __or__(self, EnvConfigContext other):
92
+ cdef dict merged_overrides = self.overrides | other.overrides
93
+ cdef AllocatorConfigContext new_config = self.__class__(**merged_overrides)
94
+ new_config.c_bind(self.allocator_schematic)
95
+ return new_config
96
+
97
+ def __invert__(self):
98
+ cdef dict inverted_overrides = {k: not v if isinstance(v, bool) else v for k, v in self.overrides.items()}
99
+ cdef AllocatorConfigContext new_config = self.__class__(**inverted_overrides)
100
+ new_config.c_bind(self.allocator_schematic)
101
+ return new_config
102
+
103
+
104
+ cdef class AllocatorProtocol:
105
+ def __cinit__(self, size_t size):
106
+ if not size:
107
+ return
108
+
109
+ if AP_DEFAULT_ALLOCATOR.with_shm:
110
+ self.protocol = c_ap_allocator_protocol_new(size, SHM_ALLOCATOR, NULL, AP_DEFAULT_ALLOCATOR.with_lock)
111
+ elif AP_DEFAULT_ALLOCATOR.with_freelist:
112
+ self.protocol = c_ap_allocator_protocol_new(size, NULL, HEAP_ALLOCATOR, AP_DEFAULT_ALLOCATOR.with_lock)
113
+ else:
114
+ self.protocol = c_ap_allocator_protocol_new(size, NULL, NULL, 0)
115
+
116
+ if self.protocol:
117
+ c_ap_allocator_protocol_acquire_owner(self.protocol)
118
+
119
+ def __dealloc__(self):
120
+ if self.protocol:
121
+ if c_ap_allocator_protocol_release_owner(self.protocol) == 0:
122
+ c_ap_allocator_protocol_free(self.protocol)
123
+
124
+ @staticmethod
125
+ cdef AllocatorProtocol c_from_protocol(allocator_protocol* protocol):
126
+ cdef AllocatorProtocol instance = AllocatorProtocol.__new__(AllocatorProtocol, 0)
127
+ instance.protocol = protocol
128
+ if protocol != NULL:
129
+ c_ap_allocator_protocol_acquire_owner(protocol)
130
+ return instance
131
+
132
+ def __repr__(self):
133
+ if not self.protocol:
134
+ return f'<{self.__class__.__name__}>(Uninitialized)'
135
+ return f'<{self.__class__.__name__} {<uintptr_t> self.protocol:#0x}>(with_shm={self.protocol.with_shm}, with_lock={self.protocol.with_lock}, size={self.protocol.size})'
136
+
137
+ property with_lock:
138
+ def __get__(self):
139
+ if not self.protocol:
140
+ raise RuntimeError('allocator_protocol not initialized')
141
+ return self.protocol.with_lock
142
+
143
+ property with_shm:
144
+ def __get__(self):
145
+ if not self.protocol:
146
+ raise RuntimeError('allocator_protocol not initialized')
147
+ return self.protocol.with_shm
148
+
149
+ property with_freelist:
150
+ def __get__(self):
151
+ if not self.protocol:
152
+ raise RuntimeError('allocator_protocol not initialized')
153
+ return self.protocol.with_freelist
154
+
155
+ property size:
156
+ def __get__(self):
157
+ if not self.protocol:
158
+ raise RuntimeError('allocator_protocol not initialized')
159
+ return self.protocol.size
160
+
161
+ property buf:
162
+ def __get__(self):
163
+ if not self.protocol:
164
+ raise RuntimeError('allocator_protocol not initialized')
165
+ if self.protocol:
166
+ return <char[:self.protocol.size]> self.protocol.buf
167
+ return None
168
+
169
+ property addr:
170
+ def __get__(self):
171
+ if not self.protocol:
172
+ raise RuntimeError('allocator_protocol not initialized')
173
+ return <uintptr_t> self.protocol
174
+
175
+
176
+ cdef allocator_protocol* AP_DEFAULT_ALLOCATOR = <allocator_protocol*> calloc(1, sizeof(allocator_protocol))
177
+ cdef allocator_protocol* AP_SHM_ALLOCATOR = <allocator_protocol*> calloc(1, sizeof(allocator_protocol))
178
+ cdef allocator_protocol* AP_HEAP_ALLOCATOR = <allocator_protocol*> calloc(1, sizeof(allocator_protocol))
179
+
180
+ AP_DEFAULT_ALLOCATOR.with_lock = AP_ALLOC_WITH_LOCK
181
+ AP_DEFAULT_ALLOCATOR.with_shm = AP_ALLOC_WITH_SHM
182
+ AP_DEFAULT_ALLOCATOR.with_freelist = AP_ALLOC_WITH_FREELIST
183
+ AP_DEFAULT_ALLOCATOR.shm_allocator_ctx = SHM_ALLOCATOR
184
+ AP_DEFAULT_ALLOCATOR.shm_allocator = SHM_ALLOCATOR.shm_allocator if SHM_ALLOCATOR != NULL else NULL
185
+ AP_DEFAULT_ALLOCATOR.heap_allocator = HEAP_ALLOCATOR
186
+
187
+ AP_SHM_ALLOCATOR.with_lock = True
188
+ AP_SHM_ALLOCATOR.with_shm = True
189
+ AP_SHM_ALLOCATOR.with_freelist = True
190
+ AP_SHM_ALLOCATOR.shm_allocator_ctx = SHM_ALLOCATOR
191
+ AP_SHM_ALLOCATOR.shm_allocator = SHM_ALLOCATOR.shm_allocator if SHM_ALLOCATOR != NULL else NULL
192
+ AP_SHM_ALLOCATOR.heap_allocator = NULL
193
+
194
+ AP_HEAP_ALLOCATOR.with_lock = True
195
+ AP_HEAP_ALLOCATOR.with_shm = False
196
+ AP_HEAP_ALLOCATOR.with_freelist = True
197
+ AP_HEAP_ALLOCATOR.shm_allocator_ctx = NULL
198
+ AP_HEAP_ALLOCATOR.shm_allocator = NULL
199
+ AP_HEAP_ALLOCATOR.heap_allocator = HEAP_ALLOCATOR
200
+
201
+ cdef AllocatorConfigContext AP_SHARED = AllocatorConfigContext(shared=True)
202
+ cdef AllocatorConfigContext AP_LOCKED = AllocatorConfigContext(locked=True)
203
+ cdef AllocatorConfigContext AP_LOCKFREE = AllocatorConfigContext(locked=False)
204
+ cdef AllocatorConfigContext AP_FREELIST = AllocatorConfigContext(freelist=True)
205
+
206
+ globals()['AP_SHARED'] = AP_SHARED
207
+ globals()['AP_LOCKED'] = AP_LOCKED
208
+ globals()['AP_LOCKFREE'] = AP_LOCKFREE
209
+ globals()['AP_FREELIST'] = AP_FREELIST