Skip to content

Commit 13a33b0

Browse files
committed
Custom parser for IgzipDecompressor.__init__
1 parent e70b361 commit 13a33b0

File tree

1 file changed

+6
-46
lines changed

1 file changed

+6
-46
lines changed

src/isal/igzip_lib.c

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -437,57 +437,17 @@ static int
437437
igzip_lib_IgzipDecompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
438438
{
439439
int return_value = -1;
440-
static const char * const _keywords[] = {"flag", "hist_bits", "zdict", NULL};
441-
static _PyArg_Parser _parser = {NULL, _keywords, "IgzipDecompressor", 0};
442-
PyObject *argsbuf[3];
443-
PyObject * const *fastargs;
444-
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
445-
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
440+
char *keywords[] = {"flag", "hist_bits", "zdict", NULL};
441+
char *format = "|iiO:IgzipDecompressor";
446442
int flag = ISAL_DEFLATE;
447443
int hist_bits = ISAL_DEF_MAX_HIST_BITS;
448444
PyObject *zdict = NULL;
449445

450-
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
451-
if (!fastargs) {
452-
goto exit;
453-
}
454-
if (!noptargs) {
455-
goto skip_optional_pos;
456-
}
457-
if (fastargs[0]) {
458-
if (PyFloat_Check(fastargs[0])) {
459-
PyErr_SetString(PyExc_TypeError,
460-
"integer argument expected, got float" );
461-
goto exit;
462-
}
463-
flag = _PyLong_AsInt(fastargs[0]);
464-
if (flag == -1 && PyErr_Occurred()) {
465-
goto exit;
466-
}
467-
if (!--noptargs) {
468-
goto skip_optional_pos;
469-
}
470-
}
471-
if (fastargs[1]) {
472-
if (PyFloat_Check(fastargs[1])) {
473-
PyErr_SetString(PyExc_TypeError,
474-
"integer argument expected, got float" );
475-
goto exit;
476-
}
477-
hist_bits = _PyLong_AsInt(fastargs[1]);
478-
if (hist_bits == -1 && PyErr_Occurred()) {
479-
goto exit;
480-
}
481-
if (!--noptargs) {
482-
goto skip_optional_pos;
483-
}
446+
if (!PyArg_ParseTupleAndKeywords(
447+
args, kwargs, format, keywords, &flag, &hist_bits, &zdict)) {
448+
return NULL;
484449
}
485-
zdict = fastargs[2];
486-
skip_optional_pos:
487-
return_value = igzip_lib_IgzipDecompressor___init___impl((IgzipDecompressor *)self, flag, hist_bits, zdict);
488-
489-
exit:
490-
return return_value;
450+
return igzip_lib_IgzipDecompressor___init___impl((IgzipDecompressor *)self, flag, hist_bits, zdict);
491451
}
492452

493453
static PyMethodDef IgzipDecompressor_methods[] = {

0 commit comments

Comments
 (0)