Skip to content

Commit

Permalink
Reduce the direct access to tp_name which is not part of the limited API
Browse files Browse the repository at this point in the history
Refs #1125
  • Loading branch information
alex committed Aug 30, 2020
1 parent bd12d89 commit d93a5e3
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ macro_rules! impl_exception_boilerplate {

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

impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use $crate::AsPyPointer;
let py_type_name =
unsafe { std::ffi::CStr::from_ptr((*(*self.as_ptr()).ob_type).tp_name) };
let type_name = py_type_name.to_string_lossy();
let type_name = self.get_type().name();
write!(f, "{}", type_name)?;
if let Ok(s) = self.str() {
write!(f, ": {}", &s.to_string_lossy())
Expand Down

0 comments on commit d93a5e3

Please sign in to comment.