8000 GH-132983: PEP 7 and Argument Clinic changes for zstd by AA-Turner · Pull Request #133791 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-132983: PEP 7 and Argument Clinic changes for zstd #133791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PEP 7; make more things static
  • Loading branch information
AA-Turner committed May 9, 2025
commit b8eaca63dcabf7775b2d10707917f5f439c1b6ee
10 changes: 4 additions & 6 deletions Modules/_zstd/_zstdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ typedef struct {
char parameter_name[32];
} ParameterInfo;

static const ParameterInfo cp_list[] =
{
static const ParameterInfo cp_list[] = {
{ZSTD_c_compressionLevel, "compression_level"},
{ZSTD_c_windowLog, "window_log"},
{ZSTD_c_hashLog, "hash_log"},
Expand All @@ -95,8 +94,7 @@ static const ParameterInfo cp_list[] =
{ZSTD_c_overlapLog, "overlap_log"}
};

static const ParameterInfo dp_list[] =
{
static const ParameterInfo dp_list[] = {
{ZSTD_d_windowLogMax, "window_log_max"}
};

Expand Down Expand Up @@ -730,14 +728,14 @@ static struct PyModuleDef_Slot _zstd_slots[] = {
};

struct PyModuleDef _zstdmodule = {
PyModuleDef_HEAD_INIT,
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_zstd",
.m_size = sizeof(_zstd_state),
.m_slots = _zstd_slots,
.m_methods = _zstd_methods,
.m_traverse = _zstd_traverse,
.m_clear = _zstd_clear,
.m_free = _zstd_free
.m_free = _zstd_free,
};

PyMODINIT_FUNC
Expand Down
16 changes: 4 additions & 12 deletions Modules/_zstd/_zstdmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ extern PyModuleDef _zstdmodule;

/* For clinic type calculations */
static inline _zstd_state *
get_zstd_state_from_type(PyTypeObject *type) {
get_zstd_state_from_type(PyTypeObject *type)
{
PyObject *module = PyType_GetModuleByDef(type, &_zstdmodule);
if (module == NULL) {
return NULL;
Expand Down Expand Up @@ -149,7 +150,8 @@ typedef enum {
} dictionary_type;

static inline int
mt_continue_should_break(ZSTD_inBuffer *in, ZSTD_outBuffer *out) {
mt_continue_should_break(ZSTD_inBuffer *in, ZSTD_outBuffer *out)
{
return in->size == in->pos && out->size != out->pos;
}

Expand All @@ -163,13 +165,3 @@ 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.";

extern PyObject *
decompress_impl(ZstdDecompressor *self, ZSTD_inBuffer *in,
Py_ssize_t max_length,
Py_ssize_t initial_size,
decompress_type type);

extern PyObject *
compress_impl(ZstdCompressor *self, Py_buffer *data,
ZSTD_EndDirective end_directive);
9 changes: 5 additions & 4 deletions Modules/_zstd/compressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ _get_CDict(ZstdDict *self, int compressionLevel)
}

static int
_zstd_load_c_dict(ZstdCompressor *self, PyObject *dict) {
_zstd_load_c_dict(ZstdCompressor *self, PyObject *dict)
{

size_t zstd_ret;
_zstd_state* const mod_state = PyType_GetModuleState(Py_TYPE(self));
Expand Down Expand Up @@ -412,7 +413,7 @@ _zstd_ZstdCompressor___init___impl(ZstdCompressor *self, PyObject *level,
return 0;
}

PyObject *
static PyObject *
compress_impl(ZstdCompressor *self, Py_buffer *data,
ZSTD_EndDirective end_directive)
{
Expand Down Expand Up @@ -667,7 +668,7 @@ PyDoc_STRVAR(ZstdCompressor_last_mode_doc,
static PyMemberDef ZstdCompressor_members[] = {
{"last_mode", Py_T_INT, offsetof(ZstdCompressor, last_mode),
Py_READONLY, ZstdCompressor_last_mode_doc},
{0}
{NULL}
};

static int
Expand Down Expand Up @@ -695,7 +696,7 @@ static PyType_Slot zstdcompressor_slots[] = {
{Py_tp_doc, (char*)_zstd_ZstdCompressor___init____doc__},
{Py_tp_traverse, ZstdCompressor_traverse},
{Py_tp_clear, ZstdCompressor_clear},
{0}
{0, 0}
};

PyType_Spec zstd_compressor_type_spec = {
Expand Down
15 changes: 6 additions & 9 deletions Modules/_zstd/decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ _zstd_load_d_dict(ZstdDecompressor *self, PyObject *dict)
output stream: ====================|
^
*/
PyObject *
static PyObject *
decompress_impl(ZstdDecompressor *self, ZSTD_inBuffer *in,
Py_ssize_t max_length,< 8000 /span>
Py_ssize_t initial_size,
Expand Down Expand Up @@ -374,7 +374,7 @@ decompress_impl(ZstdDecompressor *self, ZSTD_inBuffer *in,
return NULL;
}

void
static void
decompressor_reset_session(ZstdDecompressor *self,
decompress_type type)
{
Expand All @@ -399,7 +399,7 @@ decompressor_reset_session(ZstdDecompressor *self,
ZSTD_DCtx_reset(self->dctx, ZSTD_reset_session_only);
}

PyObject *
static PyObject *
stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length,
decompress_type type)
{
Expand Down Expand Up @@ -823,17 +823,14 @@ PyDoc_STRVAR(ZstdDecompressor_needs_input_doc,
static PyMemberDef ZstdDecompressor_members[] = {
{"eof", Py_T_BOOL, offsetof(ZstdDecompressor, eof),
Py_READONLY, ZstdDecompressor_eof_doc},

{"needs_input", Py_T_BOOL, offsetof(ZstdDecompressor, needs_input),
Py_READONLY, ZstdDecompressor_needs_input_doc},

{0}
{NULL}
};

static PyGetSetDef ZstdDecompressor_getset[] = {
_ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF

{0}
{NULL}
};

static int
Expand Down Expand Up @@ -863,7 +860,7 @@ static PyType_Slot ZstdDecompressor_slots[] = {
{Py_tp_doc, (char*)_zstd_ZstdDecompressor___init____doc__},
{Py_tp_traverse, ZstdDecompressor_traverse},
{Py_tp_clear, ZstdDecompressor_clear},
{0}
{0, 0}
};

PyType_Spec zstd_decompressor_type_spec = {
Expand Down
9 changes: 3 additions & 6 deletions Modules/_zstd/zstddict.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ ZstdDict_str(PyObject *ob)
static PyMemberDef ZstdDict_members[] = {
{"dict_id", Py_T_UINT, offsetof(ZstdDict, dict_id), Py_READONLY, ZstdDict_dictid_doc},
{"dict_content", Py_T_OBJECT_EX, offsetof(ZstdDict, dict_content), Py_READONLY, ZstdDict_dictcontent_doc},
{0}
{NULL}
};

/*[clinic input]
Expand Down Expand Up @@ -231,12 +231,9 @@ _zstd_ZstdDict_as_prefix_get_impl(ZstdDict *self)

static PyGetSetDef ZstdDict_getset[] = {
_ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF

_ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF

_ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF

{0}
{NULL}
};

static Py_ssize_t
Expand Down Expand Up @@ -275,7 +272,7 @@ static PyType_Slot zstddict_slots[] = {
{Py_sq_length, ZstdDict_length},
{Py_tp_traverse, ZstdDict_traverse},
{Py_tp_clear, ZstdDict_clear},
{0}
{0, 0}
};

PyType_Spec zstd_dict_type_spec = {
Expand Down
0