Patchwork [STABLE] python-zstandard: apply big-endian fix (issue6188)

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 25, 2019, 4:01 p.m.
Message ID <0da517c3ff6ce9e0ea01.1566748918@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/41400/
State Accepted
Headers show

Comments

Gregory Szorc - Aug. 25, 2019, 4:01 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1566748826 25200
#      Sun Aug 25 09:00:26 2019 -0700
# Branch stable
# Node ID 0da517c3ff6ce9e0ea014a85fb7344eca61b97b2
# Parent  7521e6d18057bfc41614d63c85424c50ee114cdf
python-zstandard: apply big-endian fix (issue6188)

This is a port of commit d4baf1f95b811f40773f5df0d8780fb2111ba6f5
from the upstream project to fix python-zstandard on 64-bit big-endian.
Julien Cristau - Aug. 25, 2019, 4:17 p.m.
Hi Greg,

On Sun, Aug 25, 2019 at 09:01:58 -0700, Gregory Szorc wrote:

> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1566748826 25200
> #      Sun Aug 25 09:00:26 2019 -0700
> # Branch stable
> # Node ID 0da517c3ff6ce9e0ea014a85fb7344eca61b97b2
> # Parent  7521e6d18057bfc41614d63c85424c50ee114cdf
> python-zstandard: apply big-endian fix (issue6188)
> 
For what it's worth the test failure from issue6188 happens with or
without this patch, and affects both 32 and 64bit builds.

Cheers,
Julien
Yuya Nishihara - Aug. 26, 2019, 12:27 p.m.
On Sun, 25 Aug 2019 09:01:58 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1566748826 25200
> #      Sun Aug 25 09:00:26 2019 -0700
> # Branch stable
> # Node ID 0da517c3ff6ce9e0ea014a85fb7344eca61b97b2
> # Parent  7521e6d18057bfc41614d63c85424c50ee114cdf
> python-zstandard: apply big-endian fix (issue6188)

Even if this doesn't fix the issue, the change looks good. Queued, thanks.

> This is a port of commit d4baf1f95b811f40773f5df0d8780fb2111ba6f5
> from the upstream project to fix python-zstandard on 64-bit big-endian.
> 
> diff --git a/contrib/python-zstandard/c-ext/decompressor.c b/contrib/python-zstandard/c-ext/decompressor.c
> --- a/contrib/python-zstandard/c-ext/decompressor.c
> +++ b/contrib/python-zstandard/c-ext/decompressor.c
> @@ -68,13 +68,13 @@ static int Decompressor_init(ZstdDecompr
>  	};
>  
>  	ZstdCompressionDict* dict = NULL;
> -	size_t maxWindowSize = 0;
> +	Py_ssize_t maxWindowSize = 0;
>  	ZSTD_format_e format = ZSTD_f_zstd1;
>  
>  	self->dctx = NULL;
>  	self->dict = NULL;
>  
> -	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O!II:ZstdDecompressor", kwlist,
> +	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O!nI:ZstdDecompressor", kwlist,
>  		&ZstdCompressionDictType, &dict, &maxWindowSize, &format)) {

Nit: enum can be narrower than int, though it's unlikely on most PC platforms.

Patch

diff --git a/contrib/python-zstandard/c-ext/decompressor.c b/contrib/python-zstandard/c-ext/decompressor.c
--- a/contrib/python-zstandard/c-ext/decompressor.c
+++ b/contrib/python-zstandard/c-ext/decompressor.c
@@ -68,13 +68,13 @@  static int Decompressor_init(ZstdDecompr
 	};
 
 	ZstdCompressionDict* dict = NULL;
-	size_t maxWindowSize = 0;
+	Py_ssize_t maxWindowSize = 0;
 	ZSTD_format_e format = ZSTD_f_zstd1;
 
 	self->dctx = NULL;
 	self->dict = NULL;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O!II:ZstdDecompressor", kwlist,
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O!nI:ZstdDecompressor", kwlist,
 		&ZstdCompressionDictType, &dict, &maxWindowSize, &format)) {
 		return -1;
 	}