Skip to content

Commit

Permalink
Merge pull request #288 from Hoikas/fix_s#
Browse files Browse the repository at this point in the history
Fix erroneous `TypeError` from all bindings using the `s#` code.
  • Loading branch information
zrax committed Apr 28, 2024
2 parents ebb8db0 + f171821 commit 1f56a8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
16 changes: 9 additions & 7 deletions Python/PRP/Surface/pyMipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ PY_METHOD_VA(Mipmap, setRawImage,
"Set the raw full image data (not for JPEG or RLE encoding)")
{
const char* data;
int dataSize;
Py_ssize_t dataSize;
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
PyErr_SetString(PyExc_TypeError, "setRawImage expects a binary string");
return nullptr;
Expand All @@ -138,7 +138,8 @@ PY_METHOD_VA(Mipmap, setLevel,
"Set the image data for a specified mip level")
{
const char* data;
int dataSize, level;
Py_ssize_t dataSize;
int level;
if (!PyArg_ParseTuple(args, "is#", &level, &data, &dataSize)) {
PyErr_SetString(PyExc_TypeError, "setLevel expects int, binary string");
return nullptr;
Expand All @@ -157,7 +158,7 @@ PY_METHOD_VA(Mipmap, setImageJPEG,
"Set the image data as a JPEG stream")
{
const char* data;
int dataSize;
Py_ssize_t dataSize;
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
PyErr_SetString(PyExc_TypeError, "setImageJPEG expects a binary string");
return nullptr;
Expand All @@ -176,7 +177,7 @@ PY_METHOD_VA(Mipmap, setAlphaJPEG,
"Set the alpha data as a JPEG stream")
{
const char* data;
int dataSize;
Py_ssize_t dataSize;
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
PyErr_SetString(PyExc_TypeError, "setAlphaJPEG expects a binary string");
return nullptr;
Expand All @@ -195,7 +196,7 @@ PY_METHOD_VA(Mipmap, setColorData,
"Set the RGB color data for a JPEG mipmap")
{
const char* data;
int dataSize;
Py_ssize_t dataSize;
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
PyErr_SetString(PyExc_TypeError, "setColorData expects a binary string");
return nullptr;
Expand All @@ -214,7 +215,7 @@ PY_METHOD_VA(Mipmap, setAlphaData,
"Set the alpha data for a JPEG mipmap")
{
const char* data;
int dataSize;
Py_ssize_t dataSize;
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
PyErr_SetString(PyExc_TypeError, "setAlphaData expects a binary string");
return nullptr;
Expand Down Expand Up @@ -287,7 +288,8 @@ PY_METHOD_KWARGS(Mipmap, CompressImage,
"Compresses the specified mip level")
{
static char* kwlist[] = { _pycs("level"), _pycs("data"), _pycs("quality"), nullptr };
int level, dataSize;
int level;
Py_ssize_t dataSize;
char* data;
plMipmap::BlockQuality quality = plMipmap::kBlockQualityNormal;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "is#|i", kwlist, &level, &data, &dataSize, &quality)) {
Expand Down
2 changes: 2 additions & 0 deletions Python/PyPlasma.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef _PYPLASMA_H
#define _PYPLASMA_H

#define PY_SSIZE_T_CLEAN

#include <Python.h>
#include <PlasmaDefs.h>
#include <Sys/Platform.h>
Expand Down
2 changes: 1 addition & 1 deletion Python/Stream/pyStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ PY_METHOD_VA(Stream, write,
"Writes `data` (as a binary string) to the stream")
{
const char* data;
int dataSize;
Py_ssize_t dataSize;
if (!PyArg_ParseTuple(args, "s#", &data, &dataSize)) {
PyErr_SetString(PyExc_TypeError, "write expects a binary string");
return nullptr;
Expand Down

0 comments on commit 1f56a8e

Please sign in to comment.