Skip to content

Commit

Permalink
Fixed return of invalid pointer from the fp attribute of encoder/decoder
Browse files Browse the repository at this point in the history
Fixes #171.
  • Loading branch information
agronholm committed Sep 2, 2023
1 parent 2017c2d commit 532fb80
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ This library adheres to `Semantic Versioning <http://semver.org/>`_.

- Added support for Python 3.12
- Dropped support for Python 3.7
- Fixed bug in the ``fp`` attribute of the built-in version of ``CBORDecoder`` and
``CBOREncoder`` where the getter returns an invalid pointer if the ``read`` method of
the file was a built-in method

**5.4.6** (2022-12-07)

Expand Down
9 changes: 6 additions & 3 deletions source/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,12 @@ CBORDecoder_init(CBORDecoderObject *self, PyObject *args, PyObject *kwargs)
static PyObject *
_CBORDecoder_get_fp(CBORDecoderObject *self, void *closure)
{
PyObject *ret = PyMethod_GET_SELF(self->read);
Py_INCREF(ret);
return ret;
PyObject *fp = PyObject_GetAttrString(self->read, "__self__");
if (fp) {
return fp;
} else {
Py_RETURN_NONE;
}
}


Expand Down
9 changes: 6 additions & 3 deletions source/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,12 @@ CBOREncoder_init(CBOREncoderObject *self, PyObject *args, PyObject *kwargs)
static PyObject *
_CBOREncoder_get_fp(CBOREncoderObject *self, void *closure)
{
PyObject *ret = PyMethod_GET_SELF(self->write);
Py_INCREF(ret);
return ret;
PyObject *fp = PyObject_GetAttrString(self->write, "__self__");
if (fp) {
return fp;
} else {
Py_RETURN_NONE;
}
}


Expand Down

0 comments on commit 532fb80

Please sign in to comment.