Skip to content

Commit e45600c

Browse files
committed
Simplify compressobj parser
1 parent a52d46d commit e45600c

File tree

1 file changed

+9
-72
lines changed

1 file changed

+9
-72
lines changed

src/isal/isal_zlib.c

Lines changed: 9 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -868,91 +868,28 @@ PyDoc_STRVAR(isal_zlib_compressobj__doc__,
868868
" containing subsequences that are likely to occur in the input data.");
869869

870870
#define ISAL_ZLIB_COMPRESSOBJ_METHODDEF \
871-
{"compressobj", (PyCFunction)(void(*)(void))isal_zlib_compressobj, METH_FASTCALL|METH_KEYWORDS, isal_zlib_compressobj__doc__}
871+
{"compressobj", (PyCFunction)(void(*)(void))isal_zlib_compressobj, METH_VARARGS|METH_KEYWORDS, isal_zlib_compressobj__doc__}
872872

873873
static PyObject *
874-
isal_zlib_compressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
874+
isal_zlib_compressobj(PyObject *module, PyObject *args, PyObject *kwargs)
875875
{
876876
PyObject *return_value = NULL;
877-
static const char * const _keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL};
878-
static _PyArg_Parser _parser = {NULL, _keywords, "compressobj", 0};
879-
PyObject *argsbuf[6];
880-
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
877+
char *keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL};
878+
char *format = "|iiiiiy*:compressobj";
881879
int level = ISAL_DEFAULT_COMPRESSION;
882880
int method = Z_DEFLATED;
883881
int wbits = ISAL_DEF_MAX_HIST_BITS;
884882
int memLevel = DEF_MEM_LEVEL;
885883
int strategy = Z_DEFAULT_STRATEGY;
886884
Py_buffer zdict = {NULL, NULL};
887885

888-
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 6, 0, argsbuf);
889-
if (!args) {
890-
goto exit;
891-
}
892-
if (!noptargs) {
893-
goto skip_optional_pos;
894-
}
895-
if (args[0]) {
896-
level = _PyLong_AsInt(args[0]);
897-
if (level == -1 && PyErr_Occurred()) {
898-
goto exit;
899-
}
900-
if (!--noptargs) {
901-
goto skip_optional_pos;
902-
}
903-
}
904-
if (args[1]) {
905-
method = _PyLong_AsInt(args[1]);
906-
if (method == -1 && PyErr_Occurred()) {
907-
goto exit;
908-
}
909-
if (!--noptargs) {
910-
goto skip_optional_pos;
911-
}
912-
}
913-
if (args[2]) {
914-
wbits = _PyLong_AsInt(args[2]);
915-
if (wbits == -1 && PyErr_Occurred()) {
916-
goto exit;
917-
}
918-
if (!--noptargs) {
919-
goto skip_optional_pos;
920-
}
921-
}
922-
if (args[3]) {
923-
memLevel = _PyLong_AsInt(args[3]);
924-
if (memLevel == -1 && PyErr_Occurred()) {
925-
goto exit;
926-
}
927-
if (!--noptargs) {
928-
goto skip_optional_pos;
929-
}
930-
}
931-
if (args[4]) {
932-
strategy = _PyLong_AsInt(args[4]);
933-
if (strategy == -1 && PyErr_Occurred()) {
934-
goto exit;
935-
}
936-
if (!--noptargs) {
937-
goto skip_optional_pos;
938-
}
939-
}
940-
if (PyObject_GetBuffer(args[5], &zdict, PyBUF_SIMPLE) != 0) {
941-
goto exit;
942-
}
943-
if (!PyBuffer_IsContiguous(&zdict, 'C')) {
944-
_PyArg_BadArgument("compressobj", "argument 'zdict'", "contiguous buffer", args[5]);
945-
goto exit;
886+
if (!PyArg_ParseTupleAndKeywords(
887+
args, kwargs, format, keywords,
888+
&level, &method, &wbits, &memLevel, &strategy, &zdict)) {
889+
return NULL;
946890
}
947-
skip_optional_pos:
948891
return_value = isal_zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict);
949-
950-
exit:
951-
/* Cleanup for zdict */
952-
if (zdict.obj) {
953-
PyBuffer_Release(&zdict);
954-
}
955-
892+
PyBuffer_Release(&zdict);
956893
return return_value;
957894
}
958895

0 commit comments

Comments
 (0)