Skip to content

Commit

Permalink
Use y* to parse bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 2, 2025
1 parent a3f8d65 commit adc5bbf
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/_avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ static PyTypeObject AvifEncoder_Type;
// Decoder type
typedef struct {
PyObject_HEAD avifDecoder *decoder;
PyObject *data;
char *mode;
} AvifDecoderObject;

Expand Down Expand Up @@ -664,7 +663,7 @@ _encoder_finish(AvifEncoderObject *self) {
// Decoder functions
PyObject *
AvifDecoderNew(PyObject *self_, PyObject *args) {
PyObject *avif_bytes;
Py_buffer buffer;
AvifDecoderObject *self = NULL;
avifDecoder *decoder;

Expand All @@ -674,7 +673,7 @@ AvifDecoderNew(PyObject *self_, PyObject *args) {

avifResult result;

if (!PyArg_ParseTuple(args, "Ssi", &avif_bytes, &codec_str, &max_threads)) {
if (!PyArg_ParseTuple(args, "y*si", &buffer, &codec_str, &max_threads)) {
return NULL;
}

Expand All @@ -690,9 +689,6 @@ AvifDecoderNew(PyObject *self_, PyObject *args) {
return NULL;
}

Py_INCREF(avif_bytes);
self->data = avif_bytes;

decoder = avifDecoderCreate();
#if AVIF_VERSION >= 80400
decoder->maxThreads = max_threads;
Expand All @@ -707,9 +703,7 @@ AvifDecoderNew(PyObject *self_, PyObject *args) {
#endif
decoder->codecChoice = codec;

result = avifDecoderSetIOMemory(
decoder, (uint8_t *)PyBytes_AS_STRING(self->data), PyBytes_GET_SIZE(self->data)
);
result = avifDecoderSetIOMemory(decoder, buffer.buf, buffer.len);
if (result != AVIF_RESULT_OK) {
PyErr_Format(
exc_type_for_avif_result(result),
Expand Down Expand Up @@ -749,7 +743,6 @@ _decoder_dealloc(AvifDecoderObject *self) {
if (self->decoder) {
avifDecoderDestroy(self->decoder);
}
Py_XDECREF(self->data);
Py_RETURN_NONE;
}

Expand Down

0 comments on commit adc5bbf

Please sign in to comment.