Skip to content

Commit

Permalink
Work around size mismatch between enum and Py_ssize_t
Browse files Browse the repository at this point in the history
  • Loading branch information
roehling committed Feb 23, 2022
1 parent 8f1e992 commit d9f464c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/odb_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ pgit_odb_backend_read(void **ptr, size_t *sz, git_object_t *type,
return git_error_for_exc();

const char *bytes;
if (!PyArg_ParseTuple(result, "ny#", type, &bytes, sz) || !bytes) {
Py_ssize_t type_value;
if (!PyArg_ParseTuple(result, "ny#", &type_value, &bytes, sz) || !bytes) {
Py_DECREF(result);
return GIT_EUSER;
}
*type = (git_object_t)type_value;

*ptr = git_odb_backend_data_alloc(_be, *sz);
if (!*ptr) {
Expand Down Expand Up @@ -103,11 +105,13 @@ pgit_odb_backend_read_prefix(git_oid *oid_out, void **ptr, size_t *sz, git_objec

// Parse output from calback
PyObject *py_oid_out;
Py_ssize_t type_value;
const char *bytes;
if (!PyArg_ParseTuple(result, "ny#O", type, &bytes, sz, &py_oid_out) || !bytes) {
if (!PyArg_ParseTuple(result, "ny#O", &type_value, &bytes, sz, &py_oid_out) || !bytes) {
Py_DECREF(result);
return GIT_EUSER;
}
*type = (git_object_t)type_value;

*ptr = git_odb_backend_data_alloc(_be, *sz);
if (!*ptr) {
Expand Down Expand Up @@ -135,10 +139,12 @@ pgit_odb_backend_read_header(size_t *len, git_object_t *type,
if (result == NULL)
return git_error_for_exc();

if (!PyArg_ParseTuple(result, "nn", type, len)) {
Py_ssize_t type_value;
if (!PyArg_ParseTuple(result, "nn", &type_value, len)) {
Py_DECREF(result);
return GIT_EUSER;
}
*type = (git_object_t)type_value;

Py_DECREF(result);
return 0;
Expand Down

0 comments on commit d9f464c

Please sign in to comment.