File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
example_projects/pyo3_embed/src Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ use crate::pystate::with_vm;
33use core:: ffi:: c_ulong;
44use rustpython_vm:: builtins:: PyType ;
55use rustpython_vm:: convert:: IntoObject ;
6- use rustpython_vm:: { Context , Py } ;
6+ use rustpython_vm:: { AsObject , Context , Py } ;
7+ use std:: ffi:: c_uint;
78use std:: mem:: MaybeUninit ;
89
910const PY_TPFLAGS_LONG_SUBCLASS : c_ulong = 1 << 24 ;
@@ -109,7 +110,16 @@ pub extern "C" fn PyObject_Str(_obj: *mut PyObject) -> *mut PyObject {
109110}
110111
111112#[ unsafe( no_mangle) ]
112- pub extern "C" fn Py_GetConstantBorrowed ( _constant_id : core:: ffi:: c_uint ) -> * mut PyObject {
113- crate :: log_stub ( "Py_GetConstantBorrowed" ) ;
114- std:: ptr:: null_mut ( )
113+ pub extern "C" fn Py_GetConstantBorrowed ( constant_id : c_uint ) -> * mut PyObject {
114+ with_vm ( |vm| {
115+ let ctx = & vm. ctx ;
116+ match constant_id {
117+ 0 => ctx. none . as_object ( ) ,
118+ 1 => ctx. true_value . as_object ( ) ,
119+ 2 => ctx. true_value . as_object ( ) ,
120+ _ => panic ! ( "Invalid constant_id passed to Py_GetConstantBorrowed" ) ,
121+ }
122+ . as_raw ( )
123+ . cast_mut ( )
124+ } )
115125}
Original file line number Diff line number Diff line change 11use pyo3:: prelude:: * ;
2- use pyo3:: types:: { PyInt , PyString } ;
2+ use pyo3:: types:: { PyInt , PyNone , PyString } ;
3+
4+
5+ #[ pyfunction]
6+ fn python_function ( py : Python < ' _ > ) -> Borrowed < ' _ , ' _ , PyNone > {
7+ PyNone :: get ( py)
8+ }
39
410fn main ( ) {
511 Python :: initialize ( ) ;
@@ -25,6 +31,8 @@ fn main() {
2531 . join ( )
2632 . unwrap ( ) ;
2733
34+ assert ! ( python_function( py) . is_none( ) ) ;
35+
2836 PyResult :: Ok ( ( ) )
2937 } )
3038 . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments