{"action":"created","issue":{"url":"https://api.github.com/repos/PyO3/pyo3/issues/140","repository_url":"https://api.github.com/repos/PyO3/pyo3","labels_url":"https://api.github.com/repos/PyO3/pyo3/issues/140/labels{/name}","comments_url":"https://api.github.com/repos/PyO3/pyo3/issues/140/comments","events_url":"https://api.github.com/repos/PyO3/pyo3/issues/140/events","html_url":"https://github.com/PyO3/pyo3/issues/140","id":315338174,"number":140,"title":"Segfault with std::regex::Regex","user":{"login":"plattfot","id":1094537,"avatar_url":"https://avatars3.githubusercontent.com/u/1094537?v=4","gravatar_id":"","url":"https://api.github.com/users/plattfot","html_url":"https://github.com/plattfot","followers_url":"https://api.github.com/users/plattfot/followers","following_url":"https://api.github.com/users/plattfot/following{/other_user}","gists_url":"https://api.github.com/users/plattfot/gists{/gist_id}","starred_url":"https://api.github.com/users/plattfot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plattfot/subscriptions","organizations_url":"https://api.github.com/users/plattfot/orgs","repos_url":"https://api.github.com/users/plattfot/repos","events_url":"https://api.github.com/users/plattfot/events{/privacy}","received_events_url":"https://api.github.com/users/plattfot/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-18T05:41:37Z","updated_at":"2018-04-18T07:32:05Z","closed_at":"2018-04-18T07:32:05Z","author_association":"NONE","body":"Hi,\r\nI'm having some issues with rust's regex library and python. As soon as I create a new regex it will segfault. I started out using rust-cpython as I'm brand new to rust and didn't want to start mixing in nightly. But couldn't get it to work, see this issue:  https://github.com/dgrunwald/rust-cpython/issues/130\r\n\r\nSo today I decided to try out pyo3 and see if I have any luck with that. But same thing. \r\n\r\n```toml\r\n#Cargo.toml\r\n[package]\r\nname = \"picmover\"\r\nversion = \"0.1.0\"\r\n\r\n[lib]\r\nname = \"picmover\"\r\ncrate-type = [\"dylib\"]\r\nplugin=true\r\n\r\n[dependencies]\r\nregex = \"0.2\"\r\npyo3 = \"0.2\"\r\n```\r\n```rust\r\n//lib.rs\r\n#![feature(proc_macro, specialization)]\r\n\r\nextern crate pyo3;\r\nextern crate regex;\r\n\r\nuse regex::Regex;\r\n\r\nuse pyo3::prelude::*;\r\n\r\n#[py::modinit(libpicmover)]\r\nfn init_mod(py: Python, m: &PyModule) -> PyResult<()> {\r\n    #[pyfn(m, \"segfault\")]\r\n    fn segfault_py(name: &str ) -> PyResult<String> {\r\n        let re = Regex::new(r\"segfault\").unwrap();\r\n        Ok(name.to_string())\r\n    }\r\n    Ok(())\r\n}\r\n```\r\nAt least this time I got a better backtrace\r\n```sh\r\nRUST_BACKTRACE=1 LD_LIBRARY_PATH=~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib PYTHONPATH=target/debug/ gdb python\r\n\r\n(gdb) r\r\nStarting program: /usr/bin/python \r\n[Thread debugging using libthread_db enabled]\r\nUsing host libthread_db library \"/usr/lib/libthread_db.so.1\".\r\nPython 3.6.4 (default, Jan  5 2018, 02:35:40) \r\n[GCC 7.2.1 20171224] on linux\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n>>> from libpicmover import segfault\r\n>>> segfault(\"\")\r\nthread '<unnamed>' panicked at 'index out of bounds: the len is 25 but the index is 140737301839888', /checkout/src/libcore/slice/mod.rs:871:14\r\nstack backtrace:\r\n   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace\r\n             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49\r\n   1: std::sys_common::backtrace::print\r\n             at libstd/sys_common/backtrace.rs:71\r\n             at libstd/sys_common/backtrace.rs:59\r\n   2: std::panicking::default_hook::{{closure}}\r\n             at libstd/panicking.rs:206\r\n   3: std::panicking::default_hook\r\n             at libstd/panicking.rs:222\r\n   4: std::panicking::rust_panic_with_hook\r\n             at libstd/panicking.rs:400\r\n   5: std::panicking::begin_panic_fmt\r\n             at libstd/panicking.rs:347\r\n   6: rust_begin_unwind\r\n             at libstd/panicking.rs:323\r\n   7: core::panicking::panic_fmt\r\n             at libcore/panicking.rs:71\r\n   8: core::panicking::panic_bounds_check\r\n             at libcore/panicking.rs:58\r\n   9: <usize as core::slice::SliceIndex<[T]>>::index_mut\r\n             at /checkout/src/libcore/slice/mod.rs:871\r\n  10: core::slice::<impl core::ops::index::IndexMut<I> for [T]>::index_mut\r\n             at /checkout/src/libcore/slice/mod.rs:778\r\n  11: <alloc::vec::Vec<T> as core::ops::index::IndexMut<I>>::index_mut\r\n             at /checkout/src/liballoc/vec.rs:1716\r\n  12: regex::compile::Compiler::fill\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/compile.rs:678\r\n  13: regex::compile::Compiler::fill\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/compile.rs:682\r\n  14: regex::compile::Compiler::c_repeat_zero_or_more\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/compile.rs:590\r\n  15: regex::compile::Compiler::c_repeat\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/compile.rs:557\r\n  16: regex::compile::Compiler::c\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/compile.rs:361\r\n  17: regex::compile::Compiler::c_dotstar\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/compile.rs:390\r\n  18: regex::compile::Compiler::compile_one\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/compile.rs:144\r\n  19: regex::compile::Compiler::compile\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/compile.rs:129\r\n  20: regex::exec::ExecBuilder::build\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/exec.rs:304\r\n  21: regex::re_builder::unicode::RegexBuilder::build\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/re_builder.rs:77\r\n  22: regex::re_unicode::Regex::new\r\n             at /home/plattfot/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.2.10/src/re_unicode.rs:176\r\n  23: picmover::init_mod::segfault_py\r\n             at src/lib.rs:10\r\n  24: picmover::init_mod::__wrap\r\n             at src/lib.rs:10\r\n  25: _PyCFunction_FastCallDict\r\n  26: <unknown>\r\n  27: _PyEval_EvalFrameDefault\r\n  28: PyEval_EvalCodeEx\r\n  29: PyEval_EvalCode\r\n  30: <unknown>\r\n  31: <unknown>\r\n  32: PyRun_InteractiveLoopFlags\r\n  33: <unknown>\r\n  34: <unknown>\r\n  35: main\r\n  36: __libc_start_main\r\n  37: _start\r\nfatal runtime error: failed to initiate panic, error 5\r\n\r\nProgram received signal SIGABRT, Aborted.\r\n0x00007ffff7837860 in raise () from /usr/lib/libc.so.6\r\n```\r\nAny idea why it's going out of bounds?\r\n\r\nThanks\r\n"},"comment":{"url":"https://api.github.com/repos/PyO3/pyo3/issues/comments/382291927","html_url":"https://github.com/PyO3/pyo3/issues/140#issuecomment-382291927","issue_url":"https://api.github.com/repos/PyO3/pyo3/issues/140","id":382291927,"user":{"login":"plattfot","id":1094537,"avatar_url":"https://avatars3.githubusercontent.com/u/1094537?v=4","gravatar_id":"","url":"https://api.github.com/users/plattfot","html_url":"https://github.com/plattfot","followers_url":"https://api.github.com/users/plattfot/followers","following_url":"https://api.github.com/users/plattfot/following{/other_user}","gists_url":"https://api.github.com/users/plattfot/gists{/gist_id}","starred_url":"https://api.github.com/users/plattfot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plattfot/subscriptions","organizations_url":"https://api.github.com/users/plattfot/orgs","repos_url":"https://api.github.com/users/plattfot/repos","events_url":"https://api.github.com/users/plattfot/events{/privacy}","received_events_url":"https://api.github.com/users/plattfot/received_events","type":"User","site_admin":false},"created_at":"2018-04-18T07:32:05Z","updated_at":"2018-04-18T07:32:05Z","author_association":"NONE","body":"ssokolow discovered what was wrong in https://github.com/dgrunwald/rust-cpython/issues/130. I'd put dylib instead of cdylib, which was causing rust to segfault for some reason."}}
{"actor":{"display_login":"plattfot"}}