Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This code can be removed #124

Closed
ghost opened this issue Nov 29, 2020 · 1 comment
Closed

This code can be removed #124

ghost opened this issue Nov 29, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Nov 29, 2020

 if (!PyBuffer_IsContiguous(&dest, 'C') || dest.ndim > 1) {
	PyErr_SetString(PyExc_ValueError,
	                "destination buffer should be contiguous and have at most one dimension");
	goto finally;
}

In PyArg_ParseTuple*() functions, the first condition has been checked.
w*:
https://github.com/python/cpython/blob/v3.5.0/Python/getargs.c#L1251
y*:
https://github.com/python/cpython/blob/v3.5.0/Python/getargs.c#L857
https://github.com/python/cpython/blob/v3.5.0/Python/getargs.c#L1306

The second condition is rare, even in Python's Argument Clinic, it is not checked for bytes-like object:
https://github.com/python/cpython/blob/3.9/Modules/clinic/_lzmamodule.c.h#L28-L34

@indygreg
Copy link
Owner

Good catch! I agree we can remove these extra checks.

The ndim bit is likely semantically correct. But very little code in the wild looks for this. FWIW the only code I know actually setting multiple dimensions in a PyBuffer is NumPy.

indygreg added a commit that referenced this issue Dec 25, 2020
The former is redundant with what Python does behind the scenes
and the latter isn't needed in practice.

I believe all removed instances were for PyBuffer obtained via
Python's argument parser using `y*` or `w*`.

Closes #124.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant