Skip to content

Commit

Permalink
Merge pull request #1126 from alex/limit-tp-name
Browse files Browse the repository at this point in the history
Reduce the direct access to tp_name which is not part of the limited API
  • Loading branch information
davidhewitt authored Aug 30, 2020
2 parents bd12d89 + d93a5e3 commit 494ed63
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 494ed63

Please sign in to comment.