1- #pragma once
21/*
32Low level interface to Meta's zstd library for use in the compression.zstd
43Python module.
54*/
65
76/* Declarations shared between different parts of the _zstd module*/
87
9- #include "Python.h"
10-
11- #include "zstd.h"
12- #include "zdict.h"
13-
14-
15- /* Forward declaration of module state */
16- typedef struct _zstd_state _zstd_state ;
17-
18- /* Forward reference of module def */
19- extern PyModuleDef _zstdmodule ;
20-
21- /* For clinic type calculations */
22- static inline _zstd_state *
23- get_zstd_state_from_type (PyTypeObject * type )
24- {
25- PyObject * module = PyType_GetModuleByDef (type , & _zstdmodule );
26- if (module == NULL ) {
27- return NULL ;
28- }
29- void * state = PyModule_GetState (module );
30- assert (state != NULL );
31- return (_zstd_state * )state ;
32- }
8+ #ifndef ZSTD_MODULE_H
9+ #define ZSTD_MODULE_H
3310
11+ /* Type specs */
3412extern PyType_Spec zstd_dict_type_spec ;
3513extern PyType_Spec zstd_compressor_type_spec ;
3614extern PyType_Spec zstd_decompressor_type_spec ;
3715
38- struct _zstd_state {
16+ typedef struct {
17+ /* Module heap types. */
3918 PyTypeObject * ZstdDict_type ;
4019 PyTypeObject * ZstdCompressor_type ;
4120 PyTypeObject * ZstdDecompressor_type ;
4221 PyObject * ZstdError ;
4322
23+ /* enum types set by set_parameter_types. */
4424 PyTypeObject * CParameter_type ;
4525 PyTypeObject * DParameter_type ;
46- };
47-
48- typedef struct {
49- PyObject_HEAD
50-
51- /* Reusable compress/decompress dictionary, they are created once and
52- can be shared by multiple threads concurrently, since its usage is
53- read-only.
54- c_dicts is a dict, int(compressionLevel):PyCapsule(ZSTD_CDict*) */
55- ZSTD_DDict * d_dict ;
56- PyObject * c_dicts ;
57-
58- /* Content of the dictionary, bytes object. */
59- PyObject * dict_content ;
60- /* Dictionary id */
61- uint32_t dict_id ;
62-
63- /* __init__ has been called, 0 or 1. */
64- int inited ;
65- } ZstdDict ;
66-
67- typedef struct {
68- PyObject_HEAD
69-
70- /* Compression context */
71- ZSTD_CCtx * cctx ;
72-
73- /* ZstdDict object in use */
74- PyObject * dict ;
75-
76- /* Last mode, initialized to ZSTD_e_end */
77- int last_mode ;
78-
79- /* (nbWorker >= 1) ? 1 : 0 */
80- int use_multithread ;
81-
82- /* Compression level */
83- int compression_level ;
84-
85- /* __init__ has been called, 0 or 1. */
86- int inited ;
87- } ZstdCompressor ;
88-
89- typedef struct {
90- PyObject_HEAD
91-
92- /* Decompression context */
93- ZSTD_DCtx * dctx ;
94-
95- /* ZstdDict object in use */
96- PyObject * dict ;
97-
98- /* Unconsumed input data */
99- char * input_buffer ;
100- size_t input_buffer_size ;
101- size_t in_begin , in_end ;
102-
103- /* Unused data */
104- PyObject * unused_data ;
105-
106- /* 0 if decompressor has (or may has) unconsumed input data, 0 or 1. */
107- char needs_input ;
108-
109- /* For decompress(), 0 or 1.
110- 1 when both input and output streams are at a frame edge, means a
111- frame is completely decoded and fully flushed, or the decompressor
112- just be initialized. */
113- char at_frame_edge ;
114-
115- /* For ZstdDecompressor, 0 or 1.
116- 1 means the end of the first frame has been reached. */
117- char eof ;
118-
119- /* Used for fast reset above three variables */
120- char _unused_char_for_align ;
121-
122- /* __init__ has been called, 0 or 1. */
123- int inited ;
124- } ZstdDecompressor ;
125-
126- typedef enum {
127- TYPE_DECOMPRESSOR , // <D>, ZstdDecompressor class
128- TYPE_ENDLESS_DECOMPRESSOR , // <E>, decompress() function
129- } decompress_type ;
26+ } _zstd_state ;
13027
13128typedef enum {
13229 ERR_DECOMPRESS ,
@@ -149,12 +46,6 @@ typedef enum {
14946 DICT_TYPE_PREFIX = 2
15047} dictionary_type ;
15148
152- static inline int
153- mt_continue_should_break (ZSTD_inBuffer * in , ZSTD_outBuffer * out )
154- {
155- return in -> size == in -> pos && out -> size != out -> pos ;
156- }
157-
15849/* Format error message and set ZstdError. */
15950extern void
16051set_zstd_error (const _zstd_state * const state ,
@@ -164,4 +55,4 @@ extern void
16455set_parameter_error (const _zstd_state * const state , int is_compress ,
16556 int key_v , int value_v );
16657
167- static const char init_twice_msg [] = "__init__ method is called twice." ;
58+ #endif // !ZSTD_MODULE_H
0 commit comments