Merge pull request #1126 from alex/limit-tp-name

Reduce the direct access to tp_name which is not part of the limited API
This commit is contained in:
David Hewitt 2020-08-30 20:10:58 +01:00 committed by GitHub
commit 494ed63af0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 8 deletions

View File

@ -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()
@ -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())