Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
gh-132983: Simplify_zstd_exec()
#133775
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
fa9b12b
daf2e31
55f876a
6a3a135
d5ff6d3
9f402d7
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -554,28 +554,74 @@ static PyMethodDef _zstd_methods[] = { | ||
{0} | ||
}; | ||
static int | ||
_zstd_exec(PyObject *m) | ||
AA-Turner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
{ | ||
#define ADD_TYPE(TYPE, SPEC) \ | ||
do { \ | ||
TYPE = (PyTypeObject *)PyType_FromModuleAndSpec(m, &(SPEC), NULL); \ | ||
if (TYPE == NULL) { \ | ||
return -1; \ | ||
} \ | ||
if (PyModule_AddType(m, TYPE) < 0) { \ | ||
return -1; \ | ||
} \ | ||
} while (0) | ||
#define ADD_INT_MACRO(MACRO) \ | ||
if (PyModule_AddIntConstant((m), #MACRO, (MACRO)) < 0) { \ | ||
return -1; \ | ||
} | ||
#define ADD_INT_CONST_TO_TYPE(TYPE, NAME, VALUE) \ | ||
do { \ | ||
PyObject *v = PyLong_FromLong((VALUE)); \ | ||
if (v == NULL || PyObject_SetAttrString((PyObject *)(TYPE), \ | ||
(NAME), v) < 0) { \ | ||
Py_XDECREF(v); \ | ||
return -1; \ | ||
} \ | ||
Py_DECREF(v); \ | ||
} while (0) | ||
_zstd_state* const mod_state = get_zstd_state(m); | ||
/* Reusable objects & variables */ | ||
mod_state->empty_bytes = PyBytes_FromStringAndSize(NULL, 0); | ||
AA-Turner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if (mod_state->empty_bytes == NULL) { | ||
return -1; | ||
} | ||
mod_state->CParameter_type = NULL; | ||
mod_state->DParameter_type = NULL; | ||
/* Create and add heap types */ | ||
ADD_TYPE(mod_state->ZstdDict_type, zstd_dict_type_spec); | ||
ADD_TYPE(mod_state->ZstdCompressor_type, zstd_compressor_type_spec); | ||
ADD_TYPE(mod_state->ZstdDecompressor_type, zstd_decompressor_type_spec); | ||
mod_state->ZstdError = PyErr_NewExceptionWithDoc( | ||
"_zstd.ZstdError", | ||
"An error occurred in the zstd library.", | ||
NULL, NULL); | ||
if (mod_state->ZstdError == NULL) { | ||
return -1; | ||
} | ||
if (PyModule_AddType(m, (PyTypeObject *)mod_state->ZstdError) < 0) { | ||
Py_DECREF(mod_state->ZstdError); | ||
return -1; | ||
} | ||
/* Add constants */ | ||
if (PyModule_AddIntConstant(m, "zstd_version_number", | ||
ZSTD_versionNumber()) < 0) { | ||
return -1; | ||
} | ||
if (PyModule_AddStringConstant(m, "zstd_version", | ||
ZSTD_versionString()) < 0) { | ||
return -1; | ||
} | ||
#if ZSTD_VERSION_NUMBER >= 10500 | ||
if (PyModule_AddIntConstant(m, "ZSTD_CLEVEL_DEFAULT", | ||
ZSTD_defaultCLevel()) < 0) { | ||
@@ -585,7 +631,6 @@ add_vars_to_module(PyObject *m) | ||
ADD_INT_MACRO(ZSTD_CLEVEL_DEFAULT); | ||
#endif | ||
if (PyModule_Add(m, "ZSTD_DStreamOutSize", | ||
PyLong_FromSize_t(ZSTD_DStreamOutSize())) < 0) { | ||
return -1; | ||
@@ -618,7 +663,7 @@ add_vars_to_module(PyObject *m) | ||
/* Add zstd decompression parameters. All should also be in dp_list. */ | ||
ADD_INT_MACRO(ZSTD_d_windowLogMax); | ||
/*AddZSTD_strategy enum members */ | ||
ADD_INT_MACRO(ZSTD_fast); | ||
ADD_INT_MACRO(ZSTD_dfast); | ||
ADD_INT_MACRO(ZSTD_greedy); | ||
@@ -629,135 +674,17 @@ add_vars_to_module(PyObject *m) | ||
ADD_INT_MACRO(ZSTD_btultra); | ||
ADD_INT_MACRO(ZSTD_btultra2); | ||
/* Add ZSTD_EndDirective enum members to ZstdCompressor */ | ||
ADD_INT_CONST_TO_TYPE(mod_state->ZstdCompressor_type, | ||
"CONTINUE", ZSTD_e_continue); | ||
ADD_INT_CONST_TO_TYPE(mod_state->ZstdCompressor_type, | ||
"FLUSH_BLOCK", ZSTD_e_flush); | ||
ADD_INT_CONST_TO_TYPE(mod_state->ZstdCompressor_type, | ||
"FLUSH_FRAME", ZSTD_e_end); | ||
#undef ADD_TYPE | ||
#undef ADD_INT_MACRO | ||
#undef ADD_ZSTD_COMPRESSOR_INT_CONST | ||
return 0; | ||
} | ||
@@ -768,11 +695,6 @@ _zstd_traverse(PyObject *module, visitproc visit, void *arg) | ||
_zstd_state* const mod_state = get_zstd_state(module); | ||
Py_VISIT(mod_state->empty_bytes); | ||
Py_VISIT(mod_state->ZstdDict_type); | ||
Py_VISIT(mod_state->ZstdCompressor_type); | ||
@@ -792,11 +714,6 @@ _zstd_clear(PyObject *module) | ||
_zstd_state* const mod_state = get_zstd_state(module); | ||
Py_CLEAR(mod_state->empty_bytes); | ||
Py_CLEAR(mod_state->ZstdDict_type); | ||
Py_CLEAR(mod_state->ZstdCompressor_type); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -699,7 +699,7 @@ static PyType_Slot zstdcompressor_slots[] = { | ||
{0} | ||
}; | ||
PyType_Speczstd_compressor_type_spec = { | ||
.name = "_zstd.ZstdCompressor", | ||
.basicsize = sizeof(ZstdCompressor), | ||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, | ||
AA-Turner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
Uh oh!
There was an error while loading.Please reload this page.