MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / py_module_initializer_impl

Function py_module_initializer_impl

src/lib.rs:320–347  ·  view source on GitHub ↗
(
    name: *const libc::c_char,
    init: fn(Python, &PyModule) -> PyResult<()>,
)

Source from the content-addressed store, hash-verified

318#[doc(hidden)]
319#[cfg(feature = "python27-sys")]
320pub unsafe fn py_module_initializer_impl(
321 name: *const libc::c_char,
322 init: fn(Python, &PyModule) -> PyResult<()>,
323) {
324 let guard = function::AbortOnDrop("py_module_initializer");
325 let py = Python::assume_gil_acquired();
326 ffi::PyEval_InitThreads();
327 let module = ffi::Py_InitModule(name, ptr::null_mut());
328 if module.is_null() {
329 mem::forget(guard);
330 return;
331 }
332
333 let module = match PyObject::from_borrowed_ptr(py, module).cast_into::<PyModule>(py) {
334 Ok(m) => m,
335 Err(e) => {
336 PyErr::from(e).restore(py);
337 mem::forget(guard);
338 return;
339 }
340 };
341 let ret = match init(py, &module) {
342 Ok(()) => (),
343 Err(e) => e.restore(py),
344 };
345 mem::forget(guard);
346 ret
347}
348
349#[macro_export]
350#[cfg(feature = "python3-sys")]

Callers

nothing calls this directly

Calls 6

AbortOnDropClass · 0.85
Py_InitModuleFunction · 0.85
PyModule_CreateFunction · 0.85
restoreMethod · 0.80
steal_ptrMethod · 0.45
into_objectMethod · 0.45

Tested by

no test coverage detected