@@ -39,37 +39,36 @@ impl PyType {
39
39
self . as_borrowed ( ) . as_type_ptr ( )
40
40
}
41
41
42
- /// Deprecated form of [`PyType::from_type_ptr_borrowed `].
42
+ /// Deprecated form of [`PyType::from_type_ptr_bound `].
43
43
///
44
44
/// # Safety
45
45
///
46
- /// See [`PyType::from_type_ptr_borrowed`] .
46
+ /// - The pointer must a valid non-null reference to a `PyTypeObject` .
47
47
#[ inline]
48
48
#[ cfg_attr(
49
49
not( feature = "gil-refs" ) ,
50
50
deprecated(
51
51
since = "0.21.0" ,
52
- note = "`from_type_ptr` will be replaced by `from_type_ptr_borrowed ` in a future PyO3 version"
52
+ note = "`from_type_ptr` will be replaced by `from_type_ptr_bound ` in a future PyO3 version"
53
53
)
54
54
) ]
55
55
pub unsafe fn from_type_ptr ( py : Python < ' _ > , p : * mut ffi:: PyTypeObject ) -> & PyType {
56
- Self :: from_type_ptr_borrowed ( py, p ) . into_gil_ref ( )
56
+ Self :: from_type_ptr_bound ( py, & p ) . to_owned ( ) . into_gil_ref ( )
57
57
}
58
58
59
- /// Retrieves the ` PyType` instance for the given FFI pointer .
59
+ /// Converts the given FFI pointer into `&Bound< PyType>`, to use in safe code .
60
60
///
61
61
/// # Safety
62
62
/// - The pointer must be non-null.
63
63
/// - The pointer must be valid for the entire of the lifetime 'a for which the reference is used,
64
64
/// as with `std::slice::from_raw_parts`.
65
65
#[ inline]
66
- pub unsafe fn from_type_ptr_borrowed < ' a > (
67
- py : Python < ' _ > ,
68
- p : * mut ffi:: PyTypeObject ,
69
- ) -> Borrowed < ' a , ' _ , PyType > {
70
- ( p as * mut ffi:: PyObject )
71
- . assume_borrowed_unchecked ( py)
72
- . downcast_unchecked ( )
66
+ pub unsafe fn from_type_ptr_bound < ' a , ' py > (
67
+ py : Python < ' py > ,
68
+ p : & ' a * mut ffi:: PyTypeObject ,
69
+ ) -> & ' a Bound < ' py , PyType > {
70
+ let object_ptr = & * ( p as * const * mut ffi:: PyTypeObject as * const * mut ffi:: PyObject ) ;
71
+ Bound :: ref_from_ptr ( py, object_ptr) . downcast_unchecked ( )
73
72
}
74
73
75
74
/// Gets the [qualified name](https://docs.python.org/3/glossary.html#term-qualified-name) of the `PyType`.
0 commit comments