Skip to content

ctypeslib.as_array aborts #6741

@PolarNick239

Description

@PolarNick239

This script fails:

import numpy as np
import ctypes

sh = (1, 1)
tmp = np.zeros(sh, np.uint8)
test = ctypes.cast(ctypes.c_void_p(tmp.__array_interface__['data'][0]), ctypes.POINTER(ctypes.c_ubyte))
np.ctypeslib.as_array(test, sh)

python 3.4.2-dbg
numpy==1.10.1
Ubuntu 14.10

  1. Under release python this code runs without crashes, because of disabled assertions
  2. Under debug release python asserts failed:
    python3.4: ../Objects/abstract.c:2077: PyObject_Call: Assertion '(result != ((void *)0) && !PyErr_Occurred()) || (result == ((void *)0) && PyErr_Occurred())' failed.

Can you please explain why?

P.S. may be it can help:
If sh = (1, 1) change to sh = 239:

  1. Release python will raise TypeError: shape must be a tuple
  2. Debug python will also aborts

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions