Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Generate path strings in C++ for PDF and PS #4197

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 13, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't copy string
  • Loading branch information
mdboom committed Mar 10, 2015
commit 1b2a762a5fa80d38628a8b6760b6d36e7bfad215
25 changes: 17 additions & 8 deletions src/_path_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,24 +674,33 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
}

size_t buffersize = path.total_vertices() * (precision + 5) * 4;
std::string buffer;
buffer.reserve(buffersize);
PyObject *bufferobj = PyBytes_FromStringAndSize(NULL, buffersize);
if (bufferobj == NULL) {
return NULL;
}
char *buffer = PyBytes_AsString(bufferobj);

CALL_CPP("convert_to_string",
(status = convert_to_string(
path, trans, cliprect, simplify, sketch,
precision, codes, (bool)postfix, &buffer[0],
precision, codes, (bool)postfix, buffer,
&buffersize)));

if (status == 1) {
PyErr_SetString(PyExc_MemoryError, "Buffer overflow");
if (status) {
Py_DECREF(bufferobj);
if (status == 1) {
PyErr_SetString(PyExc_MemoryError, "Buffer overflow");
} else if (status == 2) {
PyErr_SetString(PyExc_ValueError, "Malformed path codes");
}
return NULL;
} else if (status == 2) {
PyErr_SetString(PyExc_ValueError, "Malformed path codes");
}

if (_PyBytes_Resize(&bufferobj, buffersize)) {
return NULL;
}

return PyBytes_FromStringAndSize(&buffer[0], buffersize);
return bufferobj;
}

extern "C" {
Expand Down