Skip to content

class SliceBox initialization panic with PyO3 0.7 #97

@rth

Description

@rth

After I upgraded my project in rth/vtext#56 to use rust-numpy 0.6.0 (and PyO3 0.7), I started to see panics in python tests with the following message,

thread '<unnamed>' panicked at 'An error occurred while initializing class SliceBox'

that is raised in pyo3 here

full backtrace below,

Details
tests/test_vectorize.py::test_count_vectorizer thread '<unnamed>' panicked at 'An error occurred while initializing class SliceBox', C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\pyo3-0.7.0\src\type_object.rs:260:17
stack backtrace:
   0: std::sys::windows::backtrace::set_frames
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\sys\windows\backtrace\mod.rs:94
   1: std::sys::windows::backtrace::unwind_backtrace
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\sys\windows\backtrace\mod.rs:81
   2: std::sys_common::backtrace::_print
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\sys_common\backtrace.rs:70
   3: std::sys_common::backtrace::print
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\sys_common\backtrace.rs:58
   4: std::panicking::default_hook::{{closure}}
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\panicking.rs:200
   5: std::panicking::default_hook
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\panicking.rs:215
   6: std::panicking::rust_panic_with_hook
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\panicking.rs:478
   7: std::panicking::continue_panic_fmt
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\panicking.rs:385
   8: std::panicking::begin_panic_fmt
             at /rustc/7e001e5c6c7c090b41416a57d4be412ed3ccd937\/src\libstd\panicking.rs:340
   9: <T as pyo3::type_object::PyTypeObject>::init_type::{{closure}}
  10: <numpy::slice_box::SliceBox<T>>::new
  11: <numpy::array::PyArray<T, D>>::from_boxed_slice
  12: <ndarray::ArrayBase<ndarray::OwnedRepr<A>, D> as numpy::convert::IntoPyArray>::into_pyarray
  13: <T as pyo3::type_object::PyTypeObject>::init_type::{{closure}}
  14: <T as pyo3::type_object::PyTypeObject>::init_type::{{closure}}
  15: PyMethodDef_RawFastCallKeywords
  16: PyMethodDef_RawFastCallKeywords
  17: PyEval_EvalFrameDefault
  18: PyMethodDef_RawFastCallKeywords
  19: PyEval_EvalFrameDefault
  20: PyFunction_FastCallDict
  21: PySlice_New
  22: PyEval_EvalFrameDefault
  23: PyEval_EvalCodeWithName
  24: PyFunction_FastCallDict
  25: PySlice_New
  26: PyEval_EvalFrameDefault
  27: PyEval_EvalCodeWithName
  28: PyMethodDef_RawFastCallKeywords
  29: PyEval_EvalFrameDefault
  30: PyEval_EvalCodeWithName
  31: PyMethodDef_RawFastCallKeywords
  32: PyEval_EvalFrameDefault
  33: PyMethodDef_RawFastCallKeywords
  34: PyEval_EvalFrameDefault
  35: PyEval_EvalCodeWithName
  36: PyFunction_FastCallDict
  37: PyObject_Call_Prepend
  38: PyType_FromSpecWithBases
  39: PyObject_FastCallKeywords
  40: PyMethodDef_RawFastCallKeywords
  41: PyEval_EvalFrameDefault
  42: PyMethodDef_RawFastCallKeywords
  43: PyEval_EvalFrameDefault
  44: PyFunction_FastCallDict
  45: PySlice_New
  46: PyEval_EvalFrameDefault
  47: PyEval_EvalCodeWithName
  48: PyMethodDef_RawFastCallKeywords
  49: PyEval_EvalFrameDefault
  50: PyEval_EvalCodeWithName
  51: PyMethodDef_RawFastCallKeywords
  52: PyEval_EvalFrameDefault
  53: PyMethodDef_RawFastCallKeywords
  54: PyEval_EvalFrameDefault
  55: PyEval_EvalCodeWithName
  56: PyFunction_FastCallDict
  57: PyObject_Call_Prepend
  58: PyType_FromSpecWithBases
  59: PySlice_New
  60: PyEval_EvalFrameDefault
  61: PyEval_EvalCodeWithName
  62: PyMethodDef_RawFastCallKeywords
  63: PyEval_EvalFrameDefault
  64: PyEval_EvalCodeWithName
  65: PyMethodDef_RawFastCallKeywords
  66: PyEval_EvalFrameDefault
  67: PyEval_EvalCodeWithName
  68: PyFunction_FastCallDict
  69: PySlice_New
  70: PyEval_EvalFrameDefault
  71: PyEval_EvalCodeWithName
  72: PyMethodDef_RawFastCallKeywords
  73: PyEval_EvalFrameDefault
  74: PyEval_EvalCodeWithName
  75: PyMethodDef_RawFastCallKeywords
  76: PyEval_EvalFrameDefault
  77: PyFunction_FastCallDict
  78: PySlice_New
  79: PyEval_EvalFrameDefault
  80: PyEval_EvalCodeWithName
  81: PyMethodDef_RawFastCallKeywords
  82: PyEval_EvalFrameDefault
  83: PyEval_EvalCodeWithName
  84: PyMethodDef_RawFastCallKeywords
  85: PyEval_EvalFrameDefault
  86: PyMethodDef_RawFastCallKeywords
  87: PyEval_EvalFrameDefault
  88: PyEval_EvalCodeWithName
  89: PyFunction_FastCallDict
  90: PyObject_Call_Prepend
  91: PyType_FromSpecWithBases
  92: PyObject_FastCallKeywords
  93: PyMethodDef_RawFastCallKeywords
  94: PyEval_EvalFrameDefault
  95: PyFunction_FastCallDict
  96: PySlice_New
  97: PyEval_EvalFrameDefault
  98: PyEval_EvalCodeWithName
  99: PyMethodDef_RawFastCallKeywords
Windows fatal exception: code 0xc000001d

I think it must be happening in this function that mostly does something along the lines of,

ndarray::arr1(..).mapv(|elem| elem as i32).into_pyarray(py).to_owned()

(sorry for not providing a more self-contained example).

Interestingly this happens somewhat erratically. A week or so ago, this error was consistently happening on Windows builds while Linux and MacOS builds were fine. Now Windows builds pass, and Linux build fails.

I managed to reproduce this on a separate windows machine, but only when building wheels (i.e. this error did not happen when running python setup.py develop).

I'm not sure if this is an issue with rust-numpy, Pyo3 or if I'm doing something wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions