Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

_objects attribute of ctypes data instances is sometimes not None or a dictionary #132177

Copy link
Copy link
Open
@brianschubert

Description

@brianschubert
Issue body actions

Documentation

According to the current ctypes docs, the _objects attribute of ctypes data instances is supposed to be either None or a dictionary:

_objects
This member is either None or a dictionary containing Python objects that need to be kept alive so that the memory block contents is kept valid. This object is only exposed for debugging; never modify the contents of this dictionary.

However, instances created with from_buffer have this attribute set to a memoryview of the source buffer, not to a dictionary:

>>> import ctypes
>>> x = ctypes.c_uint8.from_buffer(bytearray(1), 0)
>>> type(x._objects)
<class 'memoryview'>

This behavior traces to this call of KeepRef inside CDataType_from_buffer_impl. Prior to this call, the result's b_objects is NULL, so this branch in KeepRef is taken, setting b_objects to reference the memoryview.

I'm not familiar with ctypes internals, but to my reading this behavior seems intentional and doesn't appear to cause any problems. Hence I'm filing this as a docs issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.