Skip to content

Commit 1f56a8e

Browse files
authored
Merge pull request #288 from Hoikas/fix_s#
Fix erroneous `TypeError` from all bindings using the `s#` code.
2 parents ebb8db0 + f171821 commit 1f56a8e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Python/PRP/Surface/pyMipmap.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ PY_METHOD_VA(Mipmap, setRawImage,
124124
"Set the raw full image data (not for JPEG or RLE encoding)")
125125
{
126126
const char* data;
127-
int dataSize;
127+
Py_ssize_t dataSize;
128128
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
129129
PyErr_SetString(PyExc_TypeError, "setRawImage expects a binary string");
130130
return nullptr;
@@ -138,7 +138,8 @@ PY_METHOD_VA(Mipmap, setLevel,
138138
"Set the image data for a specified mip level")
139139
{
140140
const char* data;
141-
int dataSize, level;
141+
Py_ssize_t dataSize;
142+
int level;
142143
if (!PyArg_ParseTuple(args, "is#", &level, &data, &dataSize)) {
143144
PyErr_SetString(PyExc_TypeError, "setLevel expects int, binary string");
144145
return nullptr;
@@ -157,7 +158,7 @@ PY_METHOD_VA(Mipmap, setImageJPEG,
157158
"Set the image data as a JPEG stream")
158159
{
159160
const char* data;
160-
int dataSize;
161+
Py_ssize_t dataSize;
161162
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
162163
PyErr_SetString(PyExc_TypeError, "setImageJPEG expects a binary string");
163164
return nullptr;
@@ -176,7 +177,7 @@ PY_METHOD_VA(Mipmap, setAlphaJPEG,
176177
"Set the alpha data as a JPEG stream")
177178
{
178179
const char* data;
179-
int dataSize;
180+
Py_ssize_t dataSize;
180181
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
181182
PyErr_SetString(PyExc_TypeError, "setAlphaJPEG expects a binary string");
182183
return nullptr;
@@ -195,7 +196,7 @@ PY_METHOD_VA(Mipmap, setColorData,
195196
"Set the RGB color data for a JPEG mipmap")
196197
{
197198
const char* data;
198-
int dataSize;
199+
Py_ssize_t dataSize;
199200
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
200201
PyErr_SetString(PyExc_TypeError, "setColorData expects a binary string");
201202
return nullptr;
@@ -214,7 +215,7 @@ PY_METHOD_VA(Mipmap, setAlphaData,
214215
"Set the alpha data for a JPEG mipmap")
215216
{
216217
const char* data;
217-
int dataSize;
218+
Py_ssize_t dataSize;
218219
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
219220
PyErr_SetString(PyExc_TypeError, "setAlphaData expects a binary string");
220221
return nullptr;
@@ -287,7 +288,8 @@ PY_METHOD_KWARGS(Mipmap, CompressImage,
287288
"Compresses the specified mip level")
288289
{
289290
static char* kwlist[] = { _pycs("level"), _pycs("data"), _pycs("quality"), nullptr };
290-
int level, dataSize;
291+
int level;
292+
Py_ssize_t dataSize;
291293
char* data;
292294
plMipmap::BlockQuality quality = plMipmap::kBlockQualityNormal;
293295
if (!PyArg_ParseTupleAndKeywords(args, kwds, "is#|i", kwlist, &level, &data, &dataSize, &quality)) {

Python/PyPlasma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef _PYPLASMA_H
1818
#define _PYPLASMA_H
1919

20+
#define PY_SSIZE_T_CLEAN
21+
2022
#include <Python.h>
2123
#include <PlasmaDefs.h>
2224
#include <Sys/Platform.h>

Python/Stream/pyStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ PY_METHOD_VA(Stream, write,
110110
"Writes `data` (as a binary string) to the stream")
111111
{
112112
const char* data;
113-
int dataSize;
113+
Py_ssize_t dataSize;
114114
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
115115
PyErr_SetString(PyExc_TypeError, "write expects a binary string");
116116
return nullptr;

0 commit comments

Comments
 (0)