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

Check documentation of PyObject_CopyData #102383

Closed
purpleKarrot opened this issue Mar 3, 2023 · 3 comments
Closed

Check documentation of PyObject_CopyData #102383

purpleKarrot opened this issue Mar 3, 2023 · 3 comments
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@purpleKarrot
Copy link

purpleKarrot commented Mar 3, 2023

According to the documentation, PyObject_CopyData takes two arguments of type Py_buffer*:

.. c:function:: int PyObject_CopyData(Py_buffer *dest, Py_buffer *src)

But in the implementation, it actually takes two arguments of PyObject*:

int PyObject_CopyData(PyObject *dest, PyObject *src)

Linked PRs

@terryjreedy
Copy link
Member

I few lines below, abstract.c has

    if (!PyObject_CheckBuffer(dest) ||
        !PyObject_CheckBuffer(src)) {
        PyErr_SetString(PyExc_TypeError,
                        "both destination and source must be "\
                        "bytes-like objects");

So the 'PyObjects' indeed have to be buffer-like. I don't know the technical details, but I suspect that there is no real bug.

@ronaldoussoren
Copy link
Contributor

I don't know the technical details, but I suspect that there is no real bug.

There is a bug as the documentation does not match the implementation, Py_buffer is not a Python object. In this case IMHO the documentation should be fixed.

@sobolevn
Copy link
Member

sobolevn commented Mar 3, 2023

Yes, PyObject_CheckBuffer looks like so:

int
PyObject_CheckBuffer(PyObject *obj)
{
    PyBufferProcs *tp_as_buffer = Py_TYPE(obj)->tp_as_buffer;
    return (tp_as_buffer != NULL && tp_as_buffer->bf_getbuffer != NULL);
}

So, there's clearly a bug in the docs. PR is sent :)
Thanks a lot for the report!

sobolevn added a commit to sobolevn/cpython that referenced this issue Mar 3, 2023
@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error docs Documentation in the Doc dir labels Mar 3, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 3, 2023
…t *` (pythonGH-102390)

(cherry picked from commit 7b91320)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington added a commit that referenced this issue Mar 3, 2023
…H-102390)

(cherry picked from commit 7b91320)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
carljm added a commit to carljm/cpython that referenced this issue Mar 4, 2023
* main:
  pythongh-102021 : Allow multiple input files for interpreter loop generator (python#102022)
  Add import of `unittest.mock.Mock` in documentation (python#102346)
  pythongh-102383: [docs] Arguments of `PyObject_CopyData` are `PyObject *` (python#102390)
  pythongh-101754: Document that Windows converts keys in `os.environ` to uppercase (pythonGH-101840)
  pythongh-102324: Improve tests of `typing.override` (python#102325)
@sobolevn sobolevn closed this as completed Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants