1 | #[cfg (not(PyPy))] |
2 | use crate::Py_hash_t; |
3 | use crate::{PyObject, Py_UCS1, Py_UCS2, Py_UCS4, Py_UNICODE, Py_ssize_t}; |
4 | #[cfg (not(Py_3_12))] |
5 | use libc::wchar_t; |
6 | use std::os::raw::{c_char, c_int, c_uint, c_void}; |
7 | |
8 | // skipped Py_UNICODE_ISSPACE() |
9 | // skipped Py_UNICODE_ISLOWER() |
10 | // skipped Py_UNICODE_ISUPPER() |
11 | // skipped Py_UNICODE_ISTITLE() |
12 | // skipped Py_UNICODE_ISLINEBREAK |
13 | // skipped Py_UNICODE_TOLOWER |
14 | // skipped Py_UNICODE_TOUPPER |
15 | // skipped Py_UNICODE_TOTITLE |
16 | // skipped Py_UNICODE_ISDECIMAL |
17 | // skipped Py_UNICODE_ISDIGIT |
18 | // skipped Py_UNICODE_ISNUMERIC |
19 | // skipped Py_UNICODE_ISPRINTABLE |
20 | // skipped Py_UNICODE_TODECIMAL |
21 | // skipped Py_UNICODE_TODIGIT |
22 | // skipped Py_UNICODE_TONUMERIC |
23 | // skipped Py_UNICODE_ISALPHA |
24 | // skipped Py_UNICODE_ISALNUM |
25 | // skipped Py_UNICODE_COPY |
26 | // skipped Py_UNICODE_FILL |
27 | // skipped Py_UNICODE_IS_SURROGATE |
28 | // skipped Py_UNICODE_IS_HIGH_SURROGATE |
29 | // skipped Py_UNICODE_IS_LOW_SURROGATE |
30 | // skipped Py_UNICODE_JOIN_SURROGATES |
31 | // skipped Py_UNICODE_HIGH_SURROGATE |
32 | // skipped Py_UNICODE_LOW_SURROGATE |
33 | |
34 | // generated by bindgen v0.63.0 (with small adaptations) |
35 | #[repr (C)] |
36 | struct BitfieldUnit<Storage> { |
37 | storage: Storage, |
38 | } |
39 | |
40 | impl<Storage> BitfieldUnit<Storage> { |
41 | #[inline ] |
42 | pub const fn new(storage: Storage) -> Self { |
43 | Self { storage } |
44 | } |
45 | } |
46 | |
47 | impl<Storage> BitfieldUnit<Storage> |
48 | where |
49 | Storage: AsRef<[u8]> + AsMut<[u8]>, |
50 | { |
51 | #[inline ] |
52 | fn get_bit(&self, index: usize) -> bool { |
53 | debug_assert!(index / 8 < self.storage.as_ref().len()); |
54 | let byte_index = index / 8; |
55 | let byte = self.storage.as_ref()[byte_index]; |
56 | let bit_index = if cfg!(target_endian = "big" ) { |
57 | 7 - (index % 8) |
58 | } else { |
59 | index % 8 |
60 | }; |
61 | let mask = 1 << bit_index; |
62 | byte & mask == mask |
63 | } |
64 | |
65 | #[inline ] |
66 | fn set_bit(&mut self, index: usize, val: bool) { |
67 | debug_assert!(index / 8 < self.storage.as_ref().len()); |
68 | let byte_index = index / 8; |
69 | let byte = &mut self.storage.as_mut()[byte_index]; |
70 | let bit_index = if cfg!(target_endian = "big" ) { |
71 | 7 - (index % 8) |
72 | } else { |
73 | index % 8 |
74 | }; |
75 | let mask = 1 << bit_index; |
76 | if val { |
77 | *byte |= mask; |
78 | } else { |
79 | *byte &= !mask; |
80 | } |
81 | } |
82 | |
83 | #[inline ] |
84 | fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { |
85 | debug_assert!(bit_width <= 64); |
86 | debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); |
87 | debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); |
88 | let mut val = 0; |
89 | for i in 0..(bit_width as usize) { |
90 | if self.get_bit(i + bit_offset) { |
91 | let index = if cfg!(target_endian = "big" ) { |
92 | bit_width as usize - 1 - i |
93 | } else { |
94 | i |
95 | }; |
96 | val |= 1 << index; |
97 | } |
98 | } |
99 | val |
100 | } |
101 | |
102 | #[inline ] |
103 | fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { |
104 | debug_assert!(bit_width <= 64); |
105 | debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); |
106 | debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); |
107 | for i in 0..(bit_width as usize) { |
108 | let mask = 1 << i; |
109 | let val_bit_is_set = val & mask == mask; |
110 | let index = if cfg!(target_endian = "big" ) { |
111 | bit_width as usize - 1 - i |
112 | } else { |
113 | i |
114 | }; |
115 | self.set_bit(index + bit_offset, val_bit_is_set); |
116 | } |
117 | } |
118 | } |
119 | |
120 | const STATE_INTERNED_INDEX: usize = 0; |
121 | const STATE_INTERNED_WIDTH: u8 = 2; |
122 | |
123 | const STATE_KIND_INDEX: usize = STATE_INTERNED_WIDTH as usize; |
124 | const STATE_KIND_WIDTH: u8 = 3; |
125 | |
126 | const STATE_COMPACT_INDEX: usize = (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH) as usize; |
127 | const STATE_COMPACT_WIDTH: u8 = 1; |
128 | |
129 | const STATE_ASCII_INDEX: usize = |
130 | (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH + STATE_COMPACT_WIDTH) as usize; |
131 | const STATE_ASCII_WIDTH: u8 = 1; |
132 | |
133 | #[cfg (not(Py_3_12))] |
134 | const STATE_READY_INDEX: usize = |
135 | (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH + STATE_COMPACT_WIDTH + STATE_ASCII_WIDTH) as usize; |
136 | #[cfg (not(Py_3_12))] |
137 | const STATE_READY_WIDTH: u8 = 1; |
138 | |
139 | // generated by bindgen v0.63.0 (with small adaptations) |
140 | // The same code is generated for Python 3.7, 3.8, 3.9, 3.10, and 3.11, but the "ready" field |
141 | // has been removed from Python 3.12. |
142 | |
143 | /// Wrapper around the `PyASCIIObject.state` bitfield with getters and setters that work |
144 | /// on most little- and big-endian architectures. |
145 | /// |
146 | /// Memory layout of C bitfields is implementation defined, so these functions are still |
147 | /// unsafe. Users must verify that they work as expected on the architectures they target. |
148 | #[repr (C)] |
149 | #[repr (align(4))] |
150 | struct PyASCIIObjectState { |
151 | bitfield_align: [u8; 0], |
152 | bitfield: BitfieldUnit<[u8; 4usize]>, |
153 | } |
154 | |
155 | // c_uint and u32 are not necessarily the same type on all targets / architectures |
156 | #[allow (clippy::useless_transmute)] |
157 | impl PyASCIIObjectState { |
158 | #[inline ] |
159 | unsafe fn interned(&self) -> c_uint { |
160 | std::mem::transmute( |
161 | self.bitfield |
162 | .get(STATE_INTERNED_INDEX, STATE_INTERNED_WIDTH) as u32, |
163 | ) |
164 | } |
165 | |
166 | #[inline ] |
167 | unsafe fn set_interned(&mut self, val: c_uint) { |
168 | let val: u32 = std::mem::transmute(val); |
169 | self.bitfield |
170 | .set(STATE_INTERNED_INDEX, STATE_INTERNED_WIDTH, val as u64) |
171 | } |
172 | |
173 | #[inline ] |
174 | unsafe fn kind(&self) -> c_uint { |
175 | std::mem::transmute(self.bitfield.get(STATE_KIND_INDEX, STATE_KIND_WIDTH) as u32) |
176 | } |
177 | |
178 | #[inline ] |
179 | unsafe fn set_kind(&mut self, val: c_uint) { |
180 | let val: u32 = std::mem::transmute(val); |
181 | self.bitfield |
182 | .set(STATE_KIND_INDEX, STATE_KIND_WIDTH, val as u64) |
183 | } |
184 | |
185 | #[inline ] |
186 | unsafe fn compact(&self) -> c_uint { |
187 | std::mem::transmute(self.bitfield.get(STATE_COMPACT_INDEX, STATE_COMPACT_WIDTH) as u32) |
188 | } |
189 | |
190 | #[inline ] |
191 | unsafe fn set_compact(&mut self, val: c_uint) { |
192 | let val: u32 = std::mem::transmute(val); |
193 | self.bitfield |
194 | .set(STATE_COMPACT_INDEX, STATE_COMPACT_WIDTH, val as u64) |
195 | } |
196 | |
197 | #[inline ] |
198 | unsafe fn ascii(&self) -> c_uint { |
199 | std::mem::transmute(self.bitfield.get(STATE_ASCII_INDEX, STATE_ASCII_WIDTH) as u32) |
200 | } |
201 | |
202 | #[inline ] |
203 | unsafe fn set_ascii(&mut self, val: c_uint) { |
204 | let val: u32 = std::mem::transmute(val); |
205 | self.bitfield |
206 | .set(STATE_ASCII_INDEX, STATE_ASCII_WIDTH, val as u64) |
207 | } |
208 | |
209 | #[cfg (not(Py_3_12))] |
210 | #[inline ] |
211 | unsafe fn ready(&self) -> c_uint { |
212 | std::mem::transmute(self.bitfield.get(STATE_READY_INDEX, STATE_READY_WIDTH) as u32) |
213 | } |
214 | |
215 | #[cfg (not(Py_3_12))] |
216 | #[inline ] |
217 | unsafe fn set_ready(&mut self, val: c_uint) { |
218 | let val: u32 = std::mem::transmute(val); |
219 | self.bitfield |
220 | .set(STATE_READY_INDEX, STATE_READY_WIDTH, val as u64) |
221 | } |
222 | } |
223 | |
224 | impl From<u32> for PyASCIIObjectState { |
225 | #[inline ] |
226 | fn from(value: u32) -> Self { |
227 | PyASCIIObjectState { |
228 | bitfield_align: [], |
229 | bitfield: BitfieldUnit::new(storage:value.to_ne_bytes()), |
230 | } |
231 | } |
232 | } |
233 | |
234 | impl From<PyASCIIObjectState> for u32 { |
235 | #[inline ] |
236 | fn from(value: PyASCIIObjectState) -> Self { |
237 | u32::from_ne_bytes(value.bitfield.storage) |
238 | } |
239 | } |
240 | |
241 | #[repr (C)] |
242 | pub struct PyASCIIObject { |
243 | pub ob_base: PyObject, |
244 | pub length: Py_ssize_t, |
245 | #[cfg (not(PyPy))] |
246 | pub hash: Py_hash_t, |
247 | /// A bit field with various properties. |
248 | /// |
249 | /// Rust doesn't expose bitfields. So we have accessor functions for |
250 | /// retrieving values. |
251 | /// |
252 | /// unsigned int interned:2; // SSTATE_* constants. |
253 | /// unsigned int kind:3; // PyUnicode_*_KIND constants. |
254 | /// unsigned int compact:1; |
255 | /// unsigned int ascii:1; |
256 | /// unsigned int ready:1; |
257 | /// unsigned int :24; |
258 | pub state: u32, |
259 | #[cfg (not(Py_3_12))] |
260 | pub wstr: *mut wchar_t, |
261 | } |
262 | |
263 | /// Interacting with the bitfield is not actually well-defined, so we mark these APIs unsafe. |
264 | impl PyASCIIObject { |
265 | #[cfg_attr (not(Py_3_12), allow(rustdoc::broken_intra_doc_links))] // SSTATE_INTERNED_IMMORTAL_STATIC requires 3.12 |
266 | /// Get the `interned` field of the [`PyASCIIObject`] state bitfield. |
267 | /// |
268 | /// Returns one of: [`SSTATE_NOT_INTERNED`], [`SSTATE_INTERNED_MORTAL`], |
269 | /// [`SSTATE_INTERNED_IMMORTAL`], or [`SSTATE_INTERNED_IMMORTAL_STATIC`]. |
270 | #[inline ] |
271 | pub unsafe fn interned(&self) -> c_uint { |
272 | PyASCIIObjectState::from(self.state).interned() |
273 | } |
274 | |
275 | #[cfg_attr (not(Py_3_12), allow(rustdoc::broken_intra_doc_links))] // SSTATE_INTERNED_IMMORTAL_STATIC requires 3.12 |
276 | /// Set the `interned` field of the [`PyASCIIObject`] state bitfield. |
277 | /// |
278 | /// Calling this function with an argument that is not [`SSTATE_NOT_INTERNED`], |
279 | /// [`SSTATE_INTERNED_MORTAL`], [`SSTATE_INTERNED_IMMORTAL`], or |
280 | /// [`SSTATE_INTERNED_IMMORTAL_STATIC`] is invalid. |
281 | #[inline ] |
282 | pub unsafe fn set_interned(&mut self, val: c_uint) { |
283 | let mut state = PyASCIIObjectState::from(self.state); |
284 | state.set_interned(val); |
285 | self.state = u32::from(state); |
286 | } |
287 | |
288 | /// Get the `kind` field of the [`PyASCIIObject`] state bitfield. |
289 | /// |
290 | /// Returns one of: |
291 | #[cfg_attr (not(Py_3_12), doc = "[`PyUnicode_WCHAR_KIND`], " )] |
292 | /// [`PyUnicode_1BYTE_KIND`], [`PyUnicode_2BYTE_KIND`], or [`PyUnicode_4BYTE_KIND`]. |
293 | #[inline ] |
294 | pub unsafe fn kind(&self) -> c_uint { |
295 | PyASCIIObjectState::from(self.state).kind() |
296 | } |
297 | |
298 | /// Set the `kind` field of the [`PyASCIIObject`] state bitfield. |
299 | /// |
300 | /// Calling this function with an argument that is not |
301 | #[cfg_attr (not(Py_3_12), doc = "[`PyUnicode_WCHAR_KIND`], " )] |
302 | /// [`PyUnicode_1BYTE_KIND`], [`PyUnicode_2BYTE_KIND`], or [`PyUnicode_4BYTE_KIND`] is invalid. |
303 | #[inline ] |
304 | pub unsafe fn set_kind(&mut self, val: c_uint) { |
305 | let mut state = PyASCIIObjectState::from(self.state); |
306 | state.set_kind(val); |
307 | self.state = u32::from(state); |
308 | } |
309 | |
310 | /// Get the `compact` field of the [`PyASCIIObject`] state bitfield. |
311 | /// |
312 | /// Returns either `0` or `1`. |
313 | #[inline ] |
314 | pub unsafe fn compact(&self) -> c_uint { |
315 | PyASCIIObjectState::from(self.state).compact() |
316 | } |
317 | |
318 | /// Set the `compact` flag of the [`PyASCIIObject`] state bitfield. |
319 | /// |
320 | /// Calling this function with an argument that is neither `0` nor `1` is invalid. |
321 | #[inline ] |
322 | pub unsafe fn set_compact(&mut self, val: c_uint) { |
323 | let mut state = PyASCIIObjectState::from(self.state); |
324 | state.set_compact(val); |
325 | self.state = u32::from(state); |
326 | } |
327 | |
328 | /// Get the `ascii` field of the [`PyASCIIObject`] state bitfield. |
329 | /// |
330 | /// Returns either `0` or `1`. |
331 | #[inline ] |
332 | pub unsafe fn ascii(&self) -> c_uint { |
333 | PyASCIIObjectState::from(self.state).ascii() |
334 | } |
335 | |
336 | /// Set the `ascii` flag of the [`PyASCIIObject`] state bitfield. |
337 | /// |
338 | /// Calling this function with an argument that is neither `0` nor `1` is invalid. |
339 | #[inline ] |
340 | pub unsafe fn set_ascii(&mut self, val: c_uint) { |
341 | let mut state = PyASCIIObjectState::from(self.state); |
342 | state.set_ascii(val); |
343 | self.state = u32::from(state); |
344 | } |
345 | |
346 | /// Get the `ready` field of the [`PyASCIIObject`] state bitfield. |
347 | /// |
348 | /// Returns either `0` or `1`. |
349 | #[cfg (not(Py_3_12))] |
350 | #[inline ] |
351 | pub unsafe fn ready(&self) -> c_uint { |
352 | PyASCIIObjectState::from(self.state).ready() |
353 | } |
354 | |
355 | /// Set the `ready` flag of the [`PyASCIIObject`] state bitfield. |
356 | /// |
357 | /// Calling this function with an argument that is neither `0` nor `1` is invalid. |
358 | #[cfg (not(Py_3_12))] |
359 | #[inline ] |
360 | pub unsafe fn set_ready(&mut self, val: c_uint) { |
361 | let mut state = PyASCIIObjectState::from(self.state); |
362 | state.set_ready(val); |
363 | self.state = u32::from(state); |
364 | } |
365 | } |
366 | |
367 | #[repr (C)] |
368 | pub struct PyCompactUnicodeObject { |
369 | pub _base: PyASCIIObject, |
370 | pub utf8_length: Py_ssize_t, |
371 | pub utf8: *mut c_char, |
372 | #[cfg (not(Py_3_12))] |
373 | pub wstr_length: Py_ssize_t, |
374 | } |
375 | |
376 | #[repr (C)] |
377 | pub union PyUnicodeObjectData { |
378 | pub any: *mut c_void, |
379 | pub latin1: *mut Py_UCS1, |
380 | pub ucs2: *mut Py_UCS2, |
381 | pub ucs4: *mut Py_UCS4, |
382 | } |
383 | |
384 | #[repr (C)] |
385 | pub struct PyUnicodeObject { |
386 | pub _base: PyCompactUnicodeObject, |
387 | pub data: PyUnicodeObjectData, |
388 | } |
389 | |
390 | extern "C" { |
391 | #[cfg (not(PyPy))] |
392 | pub fn _PyUnicode_CheckConsistency(op: *mut PyObject, check_content: c_int) -> c_int; |
393 | } |
394 | |
395 | // skipped PyUnicode_GET_SIZE |
396 | // skipped PyUnicode_GET_DATA_SIZE |
397 | // skipped PyUnicode_AS_UNICODE |
398 | // skipped PyUnicode_AS_DATA |
399 | |
400 | pub const SSTATE_NOT_INTERNED: c_uint = 0; |
401 | pub const SSTATE_INTERNED_MORTAL: c_uint = 1; |
402 | pub const SSTATE_INTERNED_IMMORTAL: c_uint = 2; |
403 | #[cfg (Py_3_12)] |
404 | pub const SSTATE_INTERNED_IMMORTAL_STATIC: c_uint = 3; |
405 | |
406 | #[inline ] |
407 | pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint { |
408 | debug_assert!(crate::PyUnicode_Check(op) != 0); |
409 | #[cfg (not(Py_3_12))] |
410 | debug_assert!(PyUnicode_IS_READY(op) != 0); |
411 | |
412 | (*(op as *mut PyASCIIObject)).ascii() |
413 | } |
414 | |
415 | #[inline ] |
416 | pub unsafe fn PyUnicode_IS_COMPACT(op: *mut PyObject) -> c_uint { |
417 | (*(op as *mut PyASCIIObject)).compact() |
418 | } |
419 | |
420 | #[inline ] |
421 | pub unsafe fn PyUnicode_IS_COMPACT_ASCII(op: *mut PyObject) -> c_uint { |
422 | ((*(op as *mut PyASCIIObject)).ascii() != 0 && PyUnicode_IS_COMPACT(op) != 0).into() |
423 | } |
424 | |
425 | #[cfg (not(Py_3_12))] |
426 | #[deprecated (note = "Removed in Python 3.12" )] |
427 | pub const PyUnicode_WCHAR_KIND: c_uint = 0; |
428 | |
429 | pub const PyUnicode_1BYTE_KIND: c_uint = 1; |
430 | pub const PyUnicode_2BYTE_KIND: c_uint = 2; |
431 | pub const PyUnicode_4BYTE_KIND: c_uint = 4; |
432 | |
433 | #[inline ] |
434 | pub unsafe fn PyUnicode_1BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS1 { |
435 | PyUnicode_DATA(op) as *mut Py_UCS1 |
436 | } |
437 | |
438 | #[inline ] |
439 | pub unsafe fn PyUnicode_2BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS2 { |
440 | PyUnicode_DATA(op) as *mut Py_UCS2 |
441 | } |
442 | |
443 | #[inline ] |
444 | pub unsafe fn PyUnicode_4BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS4 { |
445 | PyUnicode_DATA(op) as *mut Py_UCS4 |
446 | } |
447 | |
448 | #[inline ] |
449 | pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint { |
450 | debug_assert!(crate::PyUnicode_Check(op) != 0); |
451 | #[cfg (not(Py_3_12))] |
452 | debug_assert!(PyUnicode_IS_READY(op) != 0); |
453 | |
454 | (*(op as *mut PyASCIIObject)).kind() |
455 | } |
456 | |
457 | #[inline ] |
458 | pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void { |
459 | if PyUnicode_IS_ASCII(op) != 0 { |
460 | (op as *mut PyASCIIObject).offset(count:1) as *mut c_void |
461 | } else { |
462 | (op as *mut PyCompactUnicodeObject).offset(count:1) as *mut c_void |
463 | } |
464 | } |
465 | |
466 | #[inline ] |
467 | pub unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void { |
468 | debug_assert!(!(*(op as *mut PyUnicodeObject)).data.any.is_null()); |
469 | |
470 | (*(op as *mut PyUnicodeObject)).data.any |
471 | } |
472 | |
473 | #[inline ] |
474 | pub unsafe fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void { |
475 | debug_assert!(crate::PyUnicode_Check(op) != 0); |
476 | |
477 | if PyUnicode_IS_COMPACT(op) != 0 { |
478 | _PyUnicode_COMPACT_DATA(op) |
479 | } else { |
480 | _PyUnicode_NONCOMPACT_DATA(op) |
481 | } |
482 | } |
483 | |
484 | // skipped PyUnicode_WRITE |
485 | // skipped PyUnicode_READ |
486 | // skipped PyUnicode_READ_CHAR |
487 | |
488 | #[inline ] |
489 | pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t { |
490 | debug_assert!(crate::PyUnicode_Check(op) != 0); |
491 | #[cfg (not(Py_3_12))] |
492 | debug_assert!(PyUnicode_IS_READY(op) != 0); |
493 | |
494 | (*(op as *mut PyASCIIObject)).length |
495 | } |
496 | |
497 | #[cfg (Py_3_12)] |
498 | #[inline ] |
499 | pub unsafe fn PyUnicode_IS_READY(_op: *mut PyObject) -> c_uint { |
500 | // kept in CPython for backwards compatibility |
501 | 1 |
502 | } |
503 | |
504 | #[cfg (not(Py_3_12))] |
505 | #[inline ] |
506 | pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint { |
507 | (*(op as *mut PyASCIIObject)).ready() |
508 | } |
509 | |
510 | #[cfg (Py_3_12)] |
511 | #[inline ] |
512 | pub unsafe fn PyUnicode_READY(_op: *mut PyObject) -> c_int { |
513 | 0 |
514 | } |
515 | |
516 | #[cfg (not(Py_3_12))] |
517 | #[inline ] |
518 | pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int { |
519 | debug_assert!(crate::PyUnicode_Check(op) != 0); |
520 | |
521 | if PyUnicode_IS_READY(op) != 0 { |
522 | 0 |
523 | } else { |
524 | _PyUnicode_Ready(unicode:op) |
525 | } |
526 | } |
527 | |
528 | // skipped PyUnicode_MAX_CHAR_VALUE |
529 | // skipped _PyUnicode_get_wstr_length |
530 | // skipped PyUnicode_WSTR_LENGTH |
531 | |
532 | extern "C" { |
533 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_New" )] |
534 | pub fn PyUnicode_New(size: Py_ssize_t, maxchar: Py_UCS4) -> *mut PyObject; |
535 | #[cfg_attr (PyPy, link_name = "_PyPyUnicode_Ready" )] |
536 | pub fn _PyUnicode_Ready(unicode: *mut PyObject) -> c_int; |
537 | |
538 | // skipped _PyUnicode_Copy |
539 | |
540 | #[cfg (not(PyPy))] |
541 | pub fn PyUnicode_CopyCharacters( |
542 | to: *mut PyObject, |
543 | to_start: Py_ssize_t, |
544 | from: *mut PyObject, |
545 | from_start: Py_ssize_t, |
546 | how_many: Py_ssize_t, |
547 | ) -> Py_ssize_t; |
548 | |
549 | // skipped _PyUnicode_FastCopyCharacters |
550 | |
551 | #[cfg (not(PyPy))] |
552 | pub fn PyUnicode_Fill( |
553 | unicode: *mut PyObject, |
554 | start: Py_ssize_t, |
555 | length: Py_ssize_t, |
556 | fill_char: Py_UCS4, |
557 | ) -> Py_ssize_t; |
558 | |
559 | // skipped _PyUnicode_FastFill |
560 | |
561 | #[cfg (not(Py_3_12))] |
562 | #[deprecated ] |
563 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_FromUnicode" )] |
564 | pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; |
565 | |
566 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_FromKindAndData" )] |
567 | pub fn PyUnicode_FromKindAndData( |
568 | kind: c_int, |
569 | buffer: *const c_void, |
570 | size: Py_ssize_t, |
571 | ) -> *mut PyObject; |
572 | |
573 | // skipped _PyUnicode_FromASCII |
574 | // skipped _PyUnicode_FindMaxChar |
575 | |
576 | #[cfg (not(Py_3_12))] |
577 | #[deprecated ] |
578 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_AsUnicode" )] |
579 | pub fn PyUnicode_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; |
580 | |
581 | // skipped _PyUnicode_AsUnicode |
582 | |
583 | #[cfg (not(Py_3_12))] |
584 | #[deprecated ] |
585 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_AsUnicodeAndSize" )] |
586 | pub fn PyUnicode_AsUnicodeAndSize( |
587 | unicode: *mut PyObject, |
588 | size: *mut Py_ssize_t, |
589 | ) -> *mut Py_UNICODE; |
590 | |
591 | // skipped PyUnicode_GetMax |
592 | } |
593 | |
594 | // skipped _PyUnicodeWriter |
595 | // skipped _PyUnicodeWriter_Init |
596 | // skipped _PyUnicodeWriter_Prepare |
597 | // skipped _PyUnicodeWriter_PrepareInternal |
598 | // skipped _PyUnicodeWriter_PrepareKind |
599 | // skipped _PyUnicodeWriter_PrepareKindInternal |
600 | // skipped _PyUnicodeWriter_WriteChar |
601 | // skipped _PyUnicodeWriter_WriteStr |
602 | // skipped _PyUnicodeWriter_WriteSubstring |
603 | // skipped _PyUnicodeWriter_WriteASCIIString |
604 | // skipped _PyUnicodeWriter_WriteLatin1String |
605 | // skipped _PyUnicodeWriter_Finish |
606 | // skipped _PyUnicodeWriter_Dealloc |
607 | // skipped _PyUnicode_FormatAdvancedWriter |
608 | |
609 | extern "C" { |
610 | // skipped _PyUnicode_AsStringAndSize |
611 | |
612 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_AsUTF8" )] |
613 | pub fn PyUnicode_AsUTF8(unicode: *mut PyObject) -> *const c_char; |
614 | |
615 | // skipped _PyUnicode_AsString |
616 | |
617 | pub fn PyUnicode_Encode( |
618 | s: *const Py_UNICODE, |
619 | size: Py_ssize_t, |
620 | encoding: *const c_char, |
621 | errors: *const c_char, |
622 | ) -> *mut PyObject; |
623 | |
624 | pub fn PyUnicode_EncodeUTF7( |
625 | data: *const Py_UNICODE, |
626 | length: Py_ssize_t, |
627 | base64SetO: c_int, |
628 | base64WhiteSpace: c_int, |
629 | errors: *const c_char, |
630 | ) -> *mut PyObject; |
631 | |
632 | // skipped _PyUnicode_EncodeUTF7 |
633 | // skipped _PyUnicode_AsUTF8String |
634 | |
635 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_EncodeUTF8" )] |
636 | pub fn PyUnicode_EncodeUTF8( |
637 | data: *const Py_UNICODE, |
638 | length: Py_ssize_t, |
639 | errors: *const c_char, |
640 | ) -> *mut PyObject; |
641 | |
642 | pub fn PyUnicode_EncodeUTF32( |
643 | data: *const Py_UNICODE, |
644 | length: Py_ssize_t, |
645 | errors: *const c_char, |
646 | byteorder: c_int, |
647 | ) -> *mut PyObject; |
648 | |
649 | // skipped _PyUnicode_EncodeUTF32 |
650 | |
651 | pub fn PyUnicode_EncodeUTF16( |
652 | data: *const Py_UNICODE, |
653 | length: Py_ssize_t, |
654 | errors: *const c_char, |
655 | byteorder: c_int, |
656 | ) -> *mut PyObject; |
657 | |
658 | // skipped _PyUnicode_EncodeUTF16 |
659 | // skipped _PyUnicode_DecodeUnicodeEscape |
660 | |
661 | pub fn PyUnicode_EncodeUnicodeEscape( |
662 | data: *const Py_UNICODE, |
663 | length: Py_ssize_t, |
664 | ) -> *mut PyObject; |
665 | |
666 | pub fn PyUnicode_EncodeRawUnicodeEscape( |
667 | data: *const Py_UNICODE, |
668 | length: Py_ssize_t, |
669 | ) -> *mut PyObject; |
670 | |
671 | // skipped _PyUnicode_AsLatin1String |
672 | |
673 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_EncodeLatin1" )] |
674 | pub fn PyUnicode_EncodeLatin1( |
675 | data: *const Py_UNICODE, |
676 | length: Py_ssize_t, |
677 | errors: *const c_char, |
678 | ) -> *mut PyObject; |
679 | |
680 | // skipped _PyUnicode_AsASCIIString |
681 | |
682 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_EncodeASCII" )] |
683 | pub fn PyUnicode_EncodeASCII( |
684 | data: *const Py_UNICODE, |
685 | length: Py_ssize_t, |
686 | errors: *const c_char, |
687 | ) -> *mut PyObject; |
688 | |
689 | pub fn PyUnicode_EncodeCharmap( |
690 | data: *const Py_UNICODE, |
691 | length: Py_ssize_t, |
692 | mapping: *mut PyObject, |
693 | errors: *const c_char, |
694 | ) -> *mut PyObject; |
695 | |
696 | // skipped _PyUnicode_EncodeCharmap |
697 | |
698 | pub fn PyUnicode_TranslateCharmap( |
699 | data: *const Py_UNICODE, |
700 | length: Py_ssize_t, |
701 | table: *mut PyObject, |
702 | errors: *const c_char, |
703 | ) -> *mut PyObject; |
704 | |
705 | // skipped PyUnicode_EncodeMBCS |
706 | |
707 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_EncodeDecimal" )] |
708 | pub fn PyUnicode_EncodeDecimal( |
709 | s: *mut Py_UNICODE, |
710 | length: Py_ssize_t, |
711 | output: *mut c_char, |
712 | errors: *const c_char, |
713 | ) -> c_int; |
714 | |
715 | #[cfg_attr (PyPy, link_name = "PyPyUnicode_TransformDecimalToASCII" )] |
716 | pub fn PyUnicode_TransformDecimalToASCII( |
717 | s: *mut Py_UNICODE, |
718 | length: Py_ssize_t, |
719 | ) -> *mut PyObject; |
720 | |
721 | // skipped _PyUnicode_TransformDecimalAndSpaceToASCII |
722 | } |
723 | |
724 | // skipped _PyUnicode_JoinArray |
725 | // skipped _PyUnicode_EqualToASCIIId |
726 | // skipped _PyUnicode_EqualToASCIIString |
727 | // skipped _PyUnicode_XStrip |
728 | // skipped _PyUnicode_InsertThousandsGrouping |
729 | |
730 | // skipped _Py_ascii_whitespace |
731 | |
732 | // skipped _PyUnicode_IsLowercase |
733 | // skipped _PyUnicode_IsUppercase |
734 | // skipped _PyUnicode_IsTitlecase |
735 | // skipped _PyUnicode_IsXidStart |
736 | // skipped _PyUnicode_IsXidContinue |
737 | // skipped _PyUnicode_IsWhitespace |
738 | // skipped _PyUnicode_IsLinebreak |
739 | // skipped _PyUnicode_ToLowercase |
740 | // skipped _PyUnicode_ToUppercase |
741 | // skipped _PyUnicode_ToTitlecase |
742 | // skipped _PyUnicode_ToLowerFull |
743 | // skipped _PyUnicode_ToTitleFull |
744 | // skipped _PyUnicode_ToUpperFull |
745 | // skipped _PyUnicode_ToFoldedFull |
746 | // skipped _PyUnicode_IsCaseIgnorable |
747 | // skipped _PyUnicode_IsCased |
748 | // skipped _PyUnicode_ToDecimalDigit |
749 | // skipped _PyUnicode_ToDigit |
750 | // skipped _PyUnicode_ToNumeric |
751 | // skipped _PyUnicode_IsDecimalDigit |
752 | // skipped _PyUnicode_IsDigit |
753 | // skipped _PyUnicode_IsNumeric |
754 | // skipped _PyUnicode_IsPrintable |
755 | // skipped _PyUnicode_IsAlpha |
756 | // skipped Py_UNICODE_strlen |
757 | // skipped Py_UNICODE_strcpy |
758 | // skipped Py_UNICODE_strcat |
759 | // skipped Py_UNICODE_strncpy |
760 | // skipped Py_UNICODE_strcmp |
761 | // skipped Py_UNICODE_strncmp |
762 | // skipped Py_UNICODE_strchr |
763 | // skipped Py_UNICODE_strrchr |
764 | // skipped _PyUnicode_FormatLong |
765 | // skipped PyUnicode_AsUnicodeCopy |
766 | // skipped _PyUnicode_FromId |
767 | // skipped _PyUnicode_EQ |
768 | // skipped _PyUnicode_ScanIdentifier |
769 | |