`_objects` attribute of ctypes data instances is sometimes not None or a dictionary
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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 eitherNoneor 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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la documentación de _CData._objects y con el código CDataType_from_buffer_impl y KeepRef referenciado allí en Modules/_ctypes/_ctypes.c. Confirma si el comportamiento de memoria de from_buffer con memoryview es intencionado y, después, actualiza la documentación para describirlo con precisión; verifica el comportamiento documentado con el ejemplo de ctypes proporcionado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, python
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 52/100