8000 Merge pull request #13346 from anntzer/pyarg_parse · matplotlib/matplotlib@bb0ba70 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb0ba70

Browse files
authored
Merge pull request #13346 from anntzer/pyarg_parse
MNT: Simplify parsing of tuple in C extension code.
2 parents 9c1d70b + 592d019 commit bb0ba70

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

src/_path_wrapper.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -680,14 +680,13 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
680680
bool simplify = false;
681681
SketchParams sketch;
682682
int precision;
683-
PyObject *codesobj;
684683
char *codes[5];
685684
bool postfix;
686685
std::string buffer;
687686
bool status;
688687

689688
if (!PyArg_ParseTuple(args,
690-
"O&O&O&OO&iOO&:convert_to_string",
689+
"O&O&O&OO&i(yyyyy)O&:convert_to_string",
691690
&convert_path,
692691
&path,
693692
&convert_trans_affine,
@@ -698,7 +697,11 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
698697
&convert_sketch_params,
699698
&sketch,
700699
&precision,
701-
&codesobj,
700+
&codes[0],
701+
&codes[1],
702+
&codes[2],
703+
&codes[3],
704+
&codes[4],
702705
&convert_bool,
703706
&postfix)) {
704707
return NULL;
@@ -710,27 +713,6 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
710713
simplify = true;
711714
}
712715

713-
if (!PySequence_Check(codesobj)) {
714-
return NULL;
715-
}
716-
if (PySequence_Size(codesobj) != 5) {
717-
PyErr_SetString(
718-
PyExc_ValueError,
719-
"codes must be a 5-length sequence of byte strings");
720-
return NULL;
721-
}
722-
for (int i = 0; i < 5; ++i) {
723-
PyObject *item = PySequence_GetItem(codesobj, i);
724-
if (item == NULL) {
725-
return NULL;
726-
}
727-
codes[i] = PyBytes_AsString(item);
728-
Py_DECREF(item);
729-
if (codes[i] == NULL) {
730-
return NULL;
731-
}
732-
}
733-
734716
CALL_CPP("convert_to_string",
735717
(status = convert_to_string(
736718
path, trans, cliprect, simplify, sketch,

0 commit comments

Comments
 (0)
0