Skip to content

Commit a71aa3c

Browse files
committed
Remove Zstd{Compressor,Decompressor,Dict} from _zstdmodule.h
1 parent 942be5b commit a71aa3c

File tree

9 files changed

+121
-104
lines changed

9 files changed

+121
-104
lines changed

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3341,7 +3341,7 @@ MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_tes
33413341
MODULE__TESTLIMITEDCAPI_DEPS=$(srcdir)/Modules/_testlimitedcapi/testcapi_long.h $(srcdir)/Modules/_testlimitedcapi/parts.h $(srcdir)/Modules/_testlimitedcapi/util.h
33423342
MODULE__TESTINTERNALCAPI_DEPS=$(srcdir)/Modules/_testinternalcapi/parts.h
33433343
MODULE__SQLITE3_DEPS=$(srcdir)/Modules/_sqlite/connection.h $(srcdir)/Modules/_sqlite/cursor.h $(srcdir)/Modules/_sqlite/microprotocols.h $(srcdir)/Modules/_sqlite/module.h $(srcdir)/Modules/_sqlite/prepare_protocol.h $(srcdir)/Modules/_sqlite/row.h $(srcdir)/Modules/_sqlite/util.h
3344-
MODULE__ZSTD_DEPS=$(srcdir)/Modules/_zstd/_zstdmodule.h $(srcdir)/Modules/_zstd/buffer.h
3344+
MODULE__ZSTD_DEPS=$(srcdir)/Modules/_zstd/_zstdmodule.h $(srcdir)/Modules/_zstd/buffer.h $(srcdir)/Modules/_zstd/zstddict.h
33453345

33463346
CODECS_COMMON_HEADERS=$(srcdir)/Modules/cjkcodecs/multibytecodec.h $(srcdir)/Modules/cjkcodecs/cjkcodecs.h
33473347
MODULE__CODECS_CN_DEPS=$(srcdir)/Modules/cjkcodecs/mappings_cn.h $(CODECS_COMMON_HEADERS)

Modules/_zstd/_zstdmodule.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ Python module.
77
# define Py_BUILD_CORE_MODULE 1
88
#endif
99

10+
#include "Python.h"
11+
1012
#include "_zstdmodule.h"
13+
#include "zstddict.h"
14+
15+
#include <zstd.h> // ZSTD_*()
16+
#include <zdict.h> // ZDICT_*()
1117

1218
/*[clinic input]
1319
module _zstd

Modules/_zstd/_zstdmodule.h

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ Python module.
99
#define ZSTD_MODULE_H
1010
#include "Python.h"
1111

12-
#include <stdbool.h> // bool
13-
#include <zstd.h>
14-
#include <zdict.h>
15-
16-
1712
/* Forward declaration of module state */
1813
typedef struct _zstd_state _zstd_state;
1914

@@ -47,84 +42,6 @@ struct _zstd_state {
4742
PyTypeObject *DParameter_type;
4843
};
4944

50-
typedef struct {
51-
PyObject_HEAD
52-
53-
/* Reusable compress/decompress dictionary, they are created once and
54-
can be shared by multiple threads concurrently, since its usage is
55-
read-only.
56-
c_dicts is a dict, int(compressionLevel):PyCapsule(ZSTD_CDict*) */
57-
ZSTD_DDict *d_dict;
58-
PyObject *c_dicts;
59-
60-
/* Content of the dictionary, bytes object. */
61-
PyObject *dict_content;
62-
/* Dictionary id */
63-
uint32_t dict_id;
64-
65-
/* __init__ has been called, 0 or 1. */
66-
bool initialized;
67-
} ZstdDict;
68-
69-
typedef struct {
70-
PyObject_HEAD
71-
72-
/* Compression context */
73-
ZSTD_CCtx *cctx;
74-
75-
/* ZstdDict object in use */
76-
PyObject *dict;
77-
78-
/* Last mode, initialized to ZSTD_e_end */
79-
int last_mode;
80-
81-
/* (nbWorker >= 1) ? 1 : 0 */
82-
int use_multithread;
83-
84-
/* Compression level */
85-
int compression_level;
86-
87-
/* __init__ has been called, 0 or 1. */
88-
bool initialized;
89-
} ZstdCompressor;
90-
91-
typedef struct {
92-
PyObject_HEAD
93-
94-
/* Decompression context */
95-
ZSTD_DCtx *dctx;
96-
97-
/* ZstdDict object in use */
98-
PyObject *dict;
99-
100-
/* Unconsumed input data */
101-
char *input_buffer;
102-
size_t input_buffer_size;
103-
size_t in_begin, in_end;
104-
105-
/* Unused data */
106-
PyObject *unused_data;
107-
108-
/* 0 if decompressor has (or may has) unconsumed input data, 0 or 1. */
109-
char needs_input;
110-
111-
/* For decompress(), 0 or 1.
112-
1 when both input and output streams are at a frame edge, means a
113-
frame is completely decoded and fully flushed, or the decompressor
114-
just be initialized. */
115-
char at_frame_edge;
116-
117-
/* For ZstdDecompressor, 0 or 1.
118-
1 means the end of the first frame has been reached. */
119-
char eof;
120-
121-
/* Used for fast reset above three variables */
122-
char _unused_char_for_align;
123-
124-
/* __init__ has been called, 0 or 1. */
125-
bool initialized;
126-
} ZstdDecompressor;
127-
12845
typedef enum {
12946
ERR_DECOMPRESS,
13047
ERR_COMPRESS,

Modules/_zstd/compressor.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,50 @@ Python module.
77

88
/*[clinic input]
99
module _zstd
10-
class _zstd.ZstdCompressor "ZstdCompressor *" "clinic_state()->ZstdCompressor_type"
10+
class _zstd.ZstdCompressor "ZstdCompressor *" "zstd_compressor_type_spec"
1111
[clinic start generated code]*/
1212
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=875bf614798f80cb]*/
1313

14-
1514
#ifndef Py_BUILD_CORE_BUILTIN
1615
# define Py_BUILD_CORE_MODULE 1
1716
#endif
1817

19-
#include "_zstdmodule.h"
18+
#include "Python.h"
2019

20+
#include "_zstdmodule.h"
2121
#include "buffer.h"
22+
#include "zstddict.h"
2223

2324
#include <stdbool.h> // bool
2425
#include <stddef.h> // offsetof()
26+
#include <zstd.h> // ZSTD_*()
27+
28+
typedef struct {
29+
PyObject_HEAD
30+
31+
/* Compression context */
32+
ZSTD_CCtx *cctx;
33+
34+
/* ZstdDict object in use */
35+
PyObject *dict;
2536

37+
/* Last mode, initialized to ZSTD_e_end */
38+
int last_mode;
39+
40+
/* (nbWorker >= 1) ? 1 : 0 */
41+
int use_multithread;
42+
43+
/* Compression level */
44+
int compression_level;
45+
46+
/* __init__ has been called, 0 or 1. */
47+
bool initialized;
48+
} ZstdCompressor;
2649

2750
#define ZstdCompressor_CAST(op) ((ZstdCompressor *)op)
2851

52+
#include "clinic/compressor.c.h"
53+
2954
static int
3055
_zstd_set_c_parameters(ZstdCompressor *self, PyObject *level_or_options,
3156
const char *arg_name, const char* arg_type)
@@ -293,10 +318,6 @@ _zstd_load_c_dict(ZstdCompressor *self, PyObject *dict)
293318
return 0;
294319
}
295320

296-
#define clinic_state() (get_zstd_state_from_type(type))
297-
#include "clinic/compressor.c.h"
298-
#undef clinic_state
299-
300321
static PyObject *
301322
_zstd_ZstdCompressor_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwargs))
302323
{

Modules/_zstd/decompressor.c

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,65 @@ Python module.
77

88
/*[clinic input]
99
module _zstd
10-
class _zstd.ZstdDecompressor "ZstdDecompressor *" "clinic_state()->ZstdDecompressor_type"
10+
class _zstd.ZstdDecompressor "ZstdDecompressor *" "&zstd_decompressor_type_spec"
1111
[clinic start generated code]*/
1212
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=4e6eae327c0c0c76]*/
1313

1414
#ifndef Py_BUILD_CORE_BUILTIN
1515
# define Py_BUILD_CORE_MODULE 1
1616
#endif
1717

18-
#include "_zstdmodule.h"
18+
#include "Python.h"
1919

20+
#include "_zstdmodule.h"
2021
#include "buffer.h"
22+
#include "zstddict.h"
2123

2224
#include <stdbool.h> // bool
2325
#include <stddef.h> // offsetof()
26+
#include <zstd.h> // ZSTD_*()
27+
28+
typedef struct {
29+
PyObject_HEAD
30+
31+
/* Decompression context */
32+
ZSTD_DCtx *dctx;
33+
34+
/* ZstdDict object in use */
35+
PyObject *dict;
36+
37+
/* Unconsumed input data */
38+
char *input_buffer;
39+
size_t input_buffer_size;
40+
size_t in_begin, in_end;
41+
42+
/* Unused data */
43+
PyObject *unused_data;
44+
45+
/* 0 if decompressor has (or may has) unconsumed input data, 0 or 1. */
46+
char needs_input;
47+
48+
/* For decompress(), 0 or 1.
49+
1 when both input and output streams are at a frame edge, means a
50+
frame is completely decoded and fully flushed, or the decompressor
51+
just be initialized. */
52+
char at_frame_edge;
53+
54+
/* For ZstdDecompressor, 0 or 1.
55+
1 means the end of the first frame has been reached. */
56+
char eof;
57+
58+
/* Used for fast reset above three variables */
59+
char _unused_char_for_align;
60+
61+
/* __init__ has been called, 0 or 1. */
62+
bool initialized;
63+
} ZstdDecompressor;
2464

2565
#define ZstdDecompressor_CAST(op) ((ZstdDecompressor *)op)
2666

67+
#include "clinic/decompressor.c.h"
68+
2769
static inline ZSTD_DDict *
2870
_get_DDict(ZstdDict *self)
2971
{
@@ -800,10 +842,6 @@ _zstd_ZstdDecompressor_decompress_impl(ZstdDecompressor *self,
800842
return ret;
801843
}
802844

803-
#define clinic_state() (get_zstd_state_from_type(type))
804-
#include "clinic/decompressor.c.h"
805-
#undef clinic_state
806-
807845
static PyMethodDef ZstdDecompressor_methods[] = {
808846
_ZSTD_ZSTDDECOMPRESSOR_DECOMPRESS_METHODDEF
809847
{NULL, NULL}

Modules/_zstd/zstddict.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ Python module.
77

88
/*[clinic input]
99
module _zstd
10-
class _zstd.ZstdDict "ZstdDict *" "clinic_state()->ZstdDict_type"
10+
class _zstd.ZstdDict "ZstdDict *" "&zstd_dict_type_spec"
1111
[clinic start generated code]*/
1212
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=a5d1254c497e52ba]*/
1313

1414
#ifndef Py_BUILD_CORE_BUILTIN
1515
# define Py_BUILD_CORE_MODULE 1
1616
#endif
1717

18+
#include "Python.h"
19+
1820
#include "_zstdmodule.h"
21+
#include "zstddict.h"
22+
#include "clinic/zstddict.c.h"
1923

20-
#include <stdbool.h> // bool
21-
#include <stddef.h> // offsetof()
24+
#include <zstd.h> // ZSTD_freeDDict(), ZSTD_getDictID_fromDict()
2225

2326
#define ZstdDict_CAST(op) ((ZstdDict *)op)
2427

@@ -136,10 +139,6 @@ _zstd_ZstdDict___init___impl(ZstdDict *self, PyObject *dict_content,
136139
return 0;
137140
}
138141

139-
#define clinic_state() (get_zstd_state(type))
140-
#include "clinic/zstddict.c.h"
141-
#undef clinic_state
142-
143142
PyDoc_STRVAR(ZstdDict_dictid_doc,
144143
"ID of zstd dictionary, a 32-bit unsigned int value.\n\n"
145144
"Non-zero means ordinary dictionary, was created by zstd functions, follow\n"

Modules/_zstd/zstddict.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Low level interface to Meta's zstd library for use in the compression.zstd
3+
Python module.
4+
*/
5+
6+
#ifndef ZSTD_DICT_H
7+
#define ZSTD_DICT_H
8+
#include "Python.h"
9+
10+
#include <stdbool.h> // bool
11+
#include <zstd.h> // ZSTD_DDict
12+
13+
typedef struct {
14+
PyObject_HEAD
15+
16+
/* Reusable compress/decompress dictionary, they are created once and
17+
can be shared by multiple threads concurrently, since its usage is
18+
read-only.
19+
c_dicts is a dict, int(compressionLevel):PyCapsule(ZSTD_CDict*) */
20+
ZSTD_DDict *d_dict;
21+
PyObject *c_dicts;
22+
23+
/* Content of the dictionary, bytes object. */
24+
PyObject *dict_content;
25+
/* Dictionary id */
26+
uint32_t dict_id;
27+
28+
/* __init__ has been called, 0 or 1. */
29+
bool initialized;
30+
} ZstdDict;
31+
32+
#endif

PCbuild/_zstd.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<ItemGroup>
138138
<ClInclude Include="..\Modules\_zstd\_zstdmodule.h" />
139139
<ClInclude Include="..\Modules\_zstd\buffer.h" />
140+
<ClInclude Include="..\Modules\_zstd\zstddict.h" />
140141
<ClInclude Include="$(zstdDir)lib\common\bitstream.h" />
141142
<ClInclude Include="$(zstdDir)lib\common\error_private.h" />
142143
<ClInclude Include="$(zstdDir)lib\common\fse.h" />

PCbuild/_zstd.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
<ClInclude Include="..\Modules\_zstd\buffer.h">
129129
<Filter>Header Files</Filter>
130130
</ClInclude>
131+
<ClInclude Include="..\Modules\_zstd\zstddict.h">
132+
<Filter>Header Files</Filter>
133+
</ClInclude>
131134
<ClInclude Include="$(zstdDir)lib\zstd.h">
132135
<Filter>Header Files\zstd</Filter>
133136
</ClInclude>

0 commit comments

Comments
 (0)