Skip to content

Commit 494ed63

Browse files
authored
Merge pull request #1126 from alex/limit-tp-name
Reduce the direct access to tp_name which is not part of the limited API
2 parents bd12d89 + d93a5e3 commit 494ed63

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/exceptions.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ macro_rules! impl_exception_boilerplate {
3838

3939
impl std::fmt::Debug for $name {
4040
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
41-
use $crate::AsPyPointer;
42-
let py_type_name =
43-
unsafe { std::ffi::CStr::from_ptr((*(*self.as_ptr()).ob_type).tp_name) };
44-
let type_name = py_type_name.to_string_lossy();
41+
let type_name = self.get_type().name();
4542
f.debug_struct(&*type_name)
4643
// TODO: print out actual fields!
4744
.finish()
@@ -50,10 +47,7 @@ macro_rules! impl_exception_boilerplate {
5047

5148
impl std::fmt::Display for $name {
5249
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
53-
use $crate::AsPyPointer;
54-
let py_type_name =
55-
unsafe { std::ffi::CStr::from_ptr((*(*self.as_ptr()).ob_type).tp_name) };
56-
let type_name = py_type_name.to_string_lossy();
50+
let type_name = self.get_type().name();
5751
write!(f, "{}", type_name)?;
5852
if let Ok(s) = self.str() {
5953
write!(f, ": {}", &s.to_string_lossy())

0 commit comments

Comments
 (0)