Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6c51794

Browse filesBrowse files
committed
Simplify convert_to_string's return value.
It either works or it doesn't. Any out-of-memory case would cause an exception and be handled by CALL_CPP.
1 parent 2592cbc commit 6c51794
Copy full SHA for 6c51794

File tree

Expand file treeCollapse file tree

2 files changed

+21
-25
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-25
lines changed

‎src/_path.h

Copy file name to clipboardExpand all lines: src/_path.h
+18-18Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,11 +1082,11 @@ void __add_number(double val, char format_code, int precision,
10821082

10831083

10841084
template <class PathIterator>
1085-
int __convert_to_string(PathIterator &path,
1086-
int precision,
1087-
char **codes,
1088-
bool postfix,
1089-
std::string& buffer)
1085+
bool __convert_to_string(PathIterator &path,
1086+
int precision,
1087+
char **codes,
1088+
bool postfix,
1089+
std::string& buffer)
10901090
{
10911091
const char format_code = 'f';
10921092

@@ -1108,7 +1108,7 @@ int __convert_to_string(PathIterator &path,
11081108
for (int i = 1; i < size; ++i) {
11091109
unsigned subcode = path.vertex(&x[i], &y[i]);
11101110
if (subcode != code) {
1111-
return 2;
1111+
return false;
11121112
}
11131113
}
11141114

@@ -1140,25 +1140,25 @@ int __convert_to_string(PathIterator &path,
11401140
last_y = y[size - 1];
11411141
} else {
11421142
// Unknown code value
1143-
return 2;
1143+
return false;
11441144
}
11451145

11461146
buffer += '\n';
11471147
}
11481148

1149-
return 0;
1149+
return true;
11501150
}
11511151

11521152
template <class PathIterator>
1153-
int convert_to_string(PathIterator &path,
1154-
agg::trans_affine &trans,
1155-
agg::rect_d &clip_rect,
1156-
bool simplify,
1157-
SketchParams sketch_params,
1158-
int precision,
1159-
char **codes,
1160-
bool postfix,
1161-
std::string& buffer)
1153+
bool convert_to_string(PathIterator &path,
1154+
agg::trans_affine &trans,
1155+
agg::rect_d &clip_rect,
1156+
bool simplify,
1157+
SketchParams sketch_params,
1158+
int precision,
1159+
char **codes,
1160+
bool postfix,
1161+
std::string& buffer)
11621162
{
11631163
size_t buffersize;
11641164
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
@@ -1177,7 +1177,7 @@ int convert_to_string(PathIterator &path,
11771177

11781178
buffersize = path.total_vertices() * (precision + 5) * 4;
11791179
if (buffersize == 0) {
1180-
return 0;
1180+
return true;
11811181
}
11821182

11831183
if (sketch_params.scale != 0.0) {

‎src/_path_wrapper.cpp

Copy file name to clipboardExpand all lines: src/_path_wrapper.cpp
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
685685
bool postfix;
686686
std::string buffer;
687687
PyObject *result;
688-
int status;
688+
bool status;
689689

690690
if (!PyArg_ParseTuple(args,
691691
"O&O&O&OO&iOO&:convert_to_string",
@@ -736,12 +736,8 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
736736
path, trans, cliprect, simplify, sketch,
737737
precision, codes, postfix, buffer)));
738738

739-
if (status) {
740-
if (status == 1) {
741-
PyErr_SetString(PyExc_MemoryError, "Memory error");
742-
} else if (status == 2) {
743-
PyErr_SetString(PyExc_ValueError, "Malformed path codes");
744-
}
739+
if (!status) {
740+
PyErr_SetString(PyExc_ValueError, "Malformed path codes");
745741
return NULL;
746742
}
747743

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.