|
|
|||
File indexing completed on 2025-11-19 09:50:45
0001 #ifndef Py_INTERNAL_BYTESOBJECT_H 0002 #define Py_INTERNAL_BYTESOBJECT_H 0003 #ifdef __cplusplus 0004 extern "C" { 0005 #endif 0006 0007 #ifndef Py_BUILD_CORE 0008 # error "this header requires Py_BUILD_CORE define" 0009 #endif 0010 0011 extern PyObject* _PyBytes_FormatEx( 0012 const char *format, 0013 Py_ssize_t format_len, 0014 PyObject *args, 0015 int use_bytearray); 0016 0017 extern PyObject* _PyBytes_FromHex( 0018 PyObject *string, 0019 int use_bytearray); 0020 0021 // Helper for PyBytes_DecodeEscape that detects invalid escape chars. 0022 // Export for test_peg_generator. 0023 PyAPI_FUNC(PyObject*) _PyBytes_DecodeEscape2(const char *, Py_ssize_t, 0024 const char *, 0025 int *, const char **); 0026 // Export for binary compatibility. 0027 PyAPI_FUNC(PyObject*) _PyBytes_DecodeEscape(const char *, Py_ssize_t, 0028 const char *, const char **); 0029 0030 0031 // Substring Search. 0032 // 0033 // Returns the index of the first occurrence of 0034 // a substring ("needle") in a larger text ("haystack"). 0035 // If the needle is not found, return -1. 0036 // If the needle is found, add offset to the index. 0037 // 0038 // Export for 'mmap' shared extension. 0039 PyAPI_FUNC(Py_ssize_t) 0040 _PyBytes_Find(const char *haystack, Py_ssize_t len_haystack, 0041 const char *needle, Py_ssize_t len_needle, 0042 Py_ssize_t offset); 0043 0044 // Same as above, but search right-to-left. 0045 // Export for 'mmap' shared extension. 0046 PyAPI_FUNC(Py_ssize_t) 0047 _PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack, 0048 const char *needle, Py_ssize_t len_needle, 0049 Py_ssize_t offset); 0050 0051 0052 // Helper function to implement the repeat and inplace repeat methods on a 0053 // buffer. 0054 // 0055 // len_dest is assumed to be an integer multiple of len_src. 0056 // If src equals dest, then assume the operation is inplace. 0057 // 0058 // This method repeately doubles the number of bytes copied to reduce 0059 // the number of invocations of memcpy. 0060 // 0061 // Export for 'array' shared extension. 0062 PyAPI_FUNC(void) 0063 _PyBytes_Repeat(char* dest, Py_ssize_t len_dest, 0064 const char* src, Py_ssize_t len_src); 0065 0066 /* --- _PyBytesWriter ----------------------------------------------------- */ 0067 0068 /* The _PyBytesWriter structure is big: it contains an embedded "stack buffer". 0069 A _PyBytesWriter variable must be declared at the end of variables in a 0070 function to optimize the memory allocation on the stack. */ 0071 typedef struct { 0072 /* bytes, bytearray or NULL (when the small buffer is used) */ 0073 PyObject *buffer; 0074 0075 /* Number of allocated size. */ 0076 Py_ssize_t allocated; 0077 0078 /* Minimum number of allocated bytes, 0079 incremented by _PyBytesWriter_Prepare() */ 0080 Py_ssize_t min_size; 0081 0082 /* If non-zero, use a bytearray instead of a bytes object for buffer. */ 0083 int use_bytearray; 0084 0085 /* If non-zero, overallocate the buffer (default: 0). 0086 This flag must be zero if use_bytearray is non-zero. */ 0087 int overallocate; 0088 0089 /* Stack buffer */ 0090 int use_small_buffer; 0091 char small_buffer[512]; 0092 } _PyBytesWriter; 0093 0094 /* Initialize a bytes writer 0095 0096 By default, the overallocation is disabled. Set the overallocate attribute 0097 to control the allocation of the buffer. 0098 0099 Export _PyBytesWriter API for '_pickle' shared extension. */ 0100 PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer); 0101 0102 /* Get the buffer content and reset the writer. 0103 Return a bytes object, or a bytearray object if use_bytearray is non-zero. 0104 Raise an exception and return NULL on error. */ 0105 PyAPI_FUNC(PyObject *) _PyBytesWriter_Finish(_PyBytesWriter *writer, 0106 void *str); 0107 0108 /* Deallocate memory of a writer (clear its internal buffer). */ 0109 PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer); 0110 0111 /* Allocate the buffer to write size bytes. 0112 Return the pointer to the beginning of buffer data. 0113 Raise an exception and return NULL on error. */ 0114 PyAPI_FUNC(void*) _PyBytesWriter_Alloc(_PyBytesWriter *writer, 0115 Py_ssize_t size); 0116 0117 /* Ensure that the buffer is large enough to write *size* bytes. 0118 Add size to the writer minimum size (min_size attribute). 0119 0120 str is the current pointer inside the buffer. 0121 Return the updated current pointer inside the buffer. 0122 Raise an exception and return NULL on error. */ 0123 PyAPI_FUNC(void*) _PyBytesWriter_Prepare(_PyBytesWriter *writer, 0124 void *str, 0125 Py_ssize_t size); 0126 0127 /* Resize the buffer to make it larger. 0128 The new buffer may be larger than size bytes because of overallocation. 0129 Return the updated current pointer inside the buffer. 0130 Raise an exception and return NULL on error. 0131 0132 Note: size must be greater than the number of allocated bytes in the writer. 0133 0134 This function doesn't use the writer minimum size (min_size attribute). 0135 0136 See also _PyBytesWriter_Prepare(). 0137 */ 0138 PyAPI_FUNC(void*) _PyBytesWriter_Resize(_PyBytesWriter *writer, 0139 void *str, 0140 Py_ssize_t size); 0141 0142 /* Write bytes. 0143 Raise an exception and return NULL on error. */ 0144 PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer, 0145 void *str, 0146 const void *bytes, 0147 Py_ssize_t size); 0148 0149 #ifdef __cplusplus 0150 } 0151 #endif 0152 #endif /* !Py_INTERNAL_BYTESOBJECT_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|