mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.14] gh-132983: Reduce the size of `_zstdmodule.h
` (GH-133793) (#133854)
gh-132983: Reduce the size of ``_zstdmodule.h`` (GH-133793)
(cherry picked from commit 1a548c0a50
)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
parent
39485d5935
commit
f7c441cc82
10 changed files with 166 additions and 165 deletions
|
@ -1,4 +1,3 @@
|
|||
#pragma once
|
||||
/*
|
||||
Low level interface to Meta's zstd library for use in the compression.zstd
|
||||
Python module.
|
||||
|
@ -6,127 +5,25 @@ Python module.
|
|||
|
||||
/* Declarations shared between different parts of the _zstd module*/
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
#include "zstd.h"
|
||||
#include "zdict.h"
|
||||
|
||||
|
||||
/* Forward declaration of module state */
|
||||
typedef struct _zstd_state _zstd_state;
|
||||
|
||||
/* Forward reference of module def */
|
||||
extern PyModuleDef _zstdmodule;
|
||||
|
||||
/* For clinic type calculations */
|
||||
static inline _zstd_state *
|
||||
get_zstd_state_from_type(PyTypeObject *type)
|
||||
{
|
||||
PyObject *module = PyType_GetModuleByDef(type, &_zstdmodule);
|
||||
if (module == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
void *state = PyModule_GetState(module);
|
||||
assert(state != NULL);
|
||||
return (_zstd_state *)state;
|
||||
}
|
||||
#ifndef ZSTD_MODULE_H
|
||||
#define ZSTD_MODULE_H
|
||||
|
||||
/* Type specs */
|
||||
extern PyType_Spec zstd_dict_type_spec;
|
||||
extern PyType_Spec zstd_compressor_type_spec;
|
||||
extern PyType_Spec zstd_decompressor_type_spec;
|
||||
|
||||
struct _zstd_state {
|
||||
typedef struct {
|
||||
/* Module heap types. */
|
||||
PyTypeObject *ZstdDict_type;
|
||||
PyTypeObject *ZstdCompressor_type;
|
||||
PyTypeObject *ZstdDecompressor_type;
|
||||
PyObject *ZstdError;
|
||||
|
||||
/* enum types set by set_parameter_types. */
|
||||
PyTypeObject *CParameter_type;
|
||||
PyTypeObject *DParameter_type;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
||||
/* Reusable compress/decompress dictionary, they are created once and
|
||||
can be shared by multiple threads concurrently, since its usage is
|
||||
read-only.
|
||||
c_dicts is a dict, int(compressionLevel):PyCapsule(ZSTD_CDict*) */
|
||||
ZSTD_DDict *d_dict;
|
||||
PyObject *c_dicts;
|
||||
|
||||
/* Content of the dictionary, bytes object. */
|
||||
PyObject *dict_content;
|
||||
/* Dictionary id */
|
||||
uint32_t dict_id;
|
||||
|
||||
/* __init__ has been called, 0 or 1. */
|
||||
int inited;
|
||||
} ZstdDict;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
||||
/* Compression context */
|
||||
ZSTD_CCtx *cctx;
|
||||
|
||||
/* ZstdDict object in use */
|
||||
PyObject *dict;
|
||||
|
||||
/* Last mode, initialized to ZSTD_e_end */
|
||||
int last_mode;
|
||||
|
||||
/* (nbWorker >= 1) ? 1 : 0 */
|
||||
int use_multithread;
|
||||
|
||||
/* Compression level */
|
||||
int compression_level;
|
||||
|
||||
/* __init__ has been called, 0 or 1. */
|
||||
int inited;
|
||||
} ZstdCompressor;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
||||
/* Decompression context */
|
||||
ZSTD_DCtx *dctx;
|
||||
|
||||
/* ZstdDict object in use */
|
||||
PyObject *dict;
|
||||
|
||||
/* Unconsumed input data */
|
||||
char *input_buffer;
|
||||
size_t input_buffer_size;
|
||||
size_t in_begin, in_end;
|
||||
|
||||
/* Unused data */
|
||||
PyObject *unused_data;
|
||||
|
||||
/* 0 if decompressor has (or may has) unconsumed input data, 0 or 1. */
|
||||
char needs_input;
|
||||
|
||||
/* For decompress(), 0 or 1.
|
||||
1 when both input and output streams are at a frame edge, means a
|
||||
frame is completely decoded and fully flushed, or the decompressor
|
||||
just be initialized. */
|
||||
char at_frame_edge;
|
||||
|
||||
/* For ZstdDecompressor, 0 or 1.
|
||||
1 means the end of the first frame has been reached. */
|
||||
char eof;
|
||||
|
||||
/* Used for fast reset above three variables */
|
||||
char _unused_char_for_align;
|
||||
|
||||
/* __init__ has been called, 0 or 1. */
|
||||
int inited;
|
||||
} ZstdDecompressor;
|
||||
|
||||
typedef enum {
|
||||
TYPE_DECOMPRESSOR, // <D>, ZstdDecompressor class
|
||||
TYPE_ENDLESS_DECOMPRESSOR, // <E>, decompress() function
|
||||
} decompress_type;
|
||||
} _zstd_state;
|
||||
|
||||
typedef enum {
|
||||
ERR_DECOMPRESS,
|
||||
|
@ -149,12 +46,6 @@ typedef enum {
|
|||
DICT_TYPE_PREFIX = 2
|
||||
} dictionary_type;
|
||||
|
||||
static inline int
|
||||
mt_continue_should_break(ZSTD_inBuffer *in, ZSTD_outBuffer *out)
|
||||
{
|
||||
return in->size == in->pos && out->size != out->pos;
|
||||
}
|
||||
|
||||
/* Format error message and set ZstdError. */
|
||||
extern void
|
||||
set_zstd_error(const _zstd_state* const state,
|
||||
|
@ -164,4 +55,4 @@ extern void
|
|||
set_parameter_error(const _zstd_state* const state, int is_compress,
|
||||
int key_v, int value_v);
|
||||
|
||||
static const char init_twice_msg[] = "__init__ method is called twice.";
|
||||
#endif // !ZSTD_MODULE_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue