Skip to content

Commit

Permalink
c-ext: fix inconsistent type for closed attribute
Browse files Browse the repository at this point in the history
In Zstd(De)?Compression(Reader|Writer) structs, `closed` is declared as `int`:
```C
typedef struct {
    PyObject_HEAD
    ...
    int closed;
    ...
} ZstdCompressionWriter;
```
but in [`PyMemberDef`](https://docs.python.org/3/c-api/structures.html#c.PyMemberDef), it's `T_BOOL`:
```C
static PyMemberDef ZstdCompressionWriter_members[] = {
    {"closed", T_BOOL, offsetof(ZstdCompressionWriter, closed), READONLY, NULL},
    {NULL}};
```
which is `char`.

This fixes regression tests on s390x (#105).

Closes #164.
  • Loading branch information
rathann authored and indygreg committed Jan 17, 2022
1 parent 54c0eaf commit c566bc4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions c-ext/python-zstandard.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ typedef struct {
size_t outSize;
int entered;
int closing;
int closed;
char closed;
int writeReturnRead;
int closefd;
unsigned long long bytesCompressed;
Expand Down Expand Up @@ -164,7 +164,7 @@ typedef struct {
int closefd;

int entered;
int closed;
char closed;
unsigned long long bytesCompressed;

ZSTD_inBuffer input;
Expand Down Expand Up @@ -244,7 +244,7 @@ typedef struct {
/* Whether the context manager is active. */
int entered;
/* Whether we've closed the stream. */
int closed;
char closed;

/* Number of bytes decompressed and returned to user. */
unsigned long long bytesDecompressed;
Expand All @@ -271,7 +271,7 @@ typedef struct {
size_t outSize;
int entered;
int closing;
int closed;
char closed;
int writeReturnRead;
int closefd;
} ZstdDecompressionWriter;
Expand Down
10 changes: 10 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ Other Actions Not Blocking Release
0.17.0 (not yet released)
=========================

Bug Fixes
---------

* The `ZstdCompressionReader`, `ZstdCompressionWriter`,
`ZstdDecompressionReader`, and `ZstdDecompressionWriter` types in the C
backend now tracks their `closed` attribute using the proper C type. Before,
due to a mismatch between the C struct type and the type declared to Python,
Python could read the wrong bits on platforms like s390x and incorrectly
report the value of the `closed` attribute to Python. (#105, #164)

Changes
-------

Expand Down

0 comments on commit c566bc4

Please sign in to comment.