Skip to content

Commit

Permalink
Use py::ssize_t instead of ssize_t.
Browse files Browse the repository at this point in the history
The latter is not portable, and apparently only worked by fluke.
  • Loading branch information
QuLogic committed Aug 20, 2021
1 parent 6cb6774 commit 77fabe4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/qpdf/pipeline.cpp
Expand Up @@ -26,12 +26,12 @@
void Pl_PythonOutput::write(unsigned char *buf, size_t len)
{
py::gil_scoped_acquire gil;
ssize_t so_far = 0;
py::ssize_t so_far = 0;
while (len > 0) {
auto view_buffer = py::memoryview::from_memory(buf, len);
py::object result = this->stream.attr("write")(view_buffer);
try {
so_far = result.cast<ssize_t>();
so_far = result.cast<py::ssize_t>();
} catch (const py::cast_error &e) {
throw py::type_error("Unexpected return type of write()");
}
Expand Down
14 changes: 7 additions & 7 deletions src/qpdf/qpdf_pagelist.cpp
Expand Up @@ -25,7 +25,7 @@ static void assert_pyobject_is_page_helper(py::handle obj)
}
}

size_t uindex_from_index(PageList &pl, ssize_t index)
size_t uindex_from_index(PageList &pl, py::ssize_t index)
{
if (index < 0)
index += pl.count();
Expand Down Expand Up @@ -216,27 +216,27 @@ void init_pagelist(py::module_ &m)
{
py::class_<PageList>(m, "PageList")
.def("__getitem__",
[](PageList &pl, ssize_t index) {
[](PageList &pl, py::ssize_t index) {
size_t uindex = uindex_from_index(pl, index);
return pl.get_page(uindex);
})
.def("__getitem__", &PageList::get_pages)
.def("__setitem__",
[](PageList &pl, ssize_t index, py::object page) {
[](PageList &pl, py::ssize_t index, py::object page) {
size_t uindex = uindex_from_index(pl, index);
pl.set_page(uindex, page);
})
.def("__setitem__", &PageList::set_pages_from_iterable)
.def("__delitem__",
[](PageList &pl, ssize_t index) {
[](PageList &pl, py::ssize_t index) {
size_t uindex = uindex_from_index(pl, index);
pl.delete_page(uindex);
})
.def("__delitem__", &PageList::delete_pages_from_iterable)
.def("__len__", &PageList::count)
.def(
"p",
[](PageList &pl, ssize_t pnum) {
[](PageList &pl, py::ssize_t pnum) {
if (pnum <= 0) // Indexing past end is checked in .get_page
throw py::index_error(
"page access out of range in 1-based indexing");
Expand All @@ -254,7 +254,7 @@ void init_pagelist(py::module_ &m)
})
.def(
"insert",
[](PageList &pl, ssize_t index, py::object obj) {
[](PageList &pl, py::ssize_t index, py::object obj) {
size_t uindex = uindex_from_index(pl, index);
pl.insert_page(uindex, obj);
},
Expand Down Expand Up @@ -316,7 +316,7 @@ void init_pagelist(py::module_ &m)
.def(
"remove",
[](PageList &pl, py::kwargs kwargs) {
auto pnum = kwargs["p"].cast<ssize_t>();
auto pnum = kwargs["p"].cast<py::ssize_t>();
if (pnum <= 0) // Indexing past end is checked in .get_page
throw py::index_error(
"page access out of range in 1-based indexing");
Expand Down

0 comments on commit 77fabe4

Please sign in to comment.