From c566bc4818e5d61e675f10c712dc050b81810857 Mon Sep 17 00:00:00 2001 From: Dominik 'Rathann' Mierzejewski Date: Mon, 18 Oct 2021 13:54:43 +0200 Subject: [PATCH] c-ext: fix inconsistent type for `closed` attribute 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. --- c-ext/python-zstandard.h | 8 ++++---- docs/news.rst | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/c-ext/python-zstandard.h b/c-ext/python-zstandard.h index e0335c55..f852a86a 100644 --- a/c-ext/python-zstandard.h +++ b/c-ext/python-zstandard.h @@ -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; @@ -164,7 +164,7 @@ typedef struct { int closefd; int entered; - int closed; + char closed; unsigned long long bytesCompressed; ZSTD_inBuffer input; @@ -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; @@ -271,7 +271,7 @@ typedef struct { size_t outSize; int entered; int closing; - int closed; + char closed; int writeReturnRead; int closefd; } ZstdDecompressionWriter; diff --git a/docs/news.rst b/docs/news.rst index 4bc3d7d6..8f873653 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -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 -------