Skip to content

Commit

Permalink
Move code to a Py_3 function
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-N committed Mar 17, 2019
1 parent dd8e621 commit 59fd504
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,7 @@ where
let mut props = py_class_properties::<T>();

if cfg!(Py_3) && has_dict {
let dict_slot = ffi::PyGetSetDef {
name: "__dict__\0".as_ptr() as *mut c_char,
get: Some(ffi::PyObject_GenericGetDict),
set: Some(ffi::PyObject_GenericSetDict),
doc: ptr::null_mut(),
closure: ptr::null_mut(),
};
props.push(dict_slot);
props.push(get_dict_slot());
}
if !props.is_empty() {
props.push(ffi::PyGetSetDef_INIT);
Expand All @@ -424,6 +417,17 @@ where
}
}

#[cfg(Py_3)]
fn get_dict_slot() -> ffi::PyGetSetDef {
ffi::PyGetSetDef {
name: "__dict__\0".as_ptr() as *mut c_char,
get: Some(ffi::PyObject_GenericGetDict),
set: Some(ffi::PyObject_GenericSetDict),
doc: ptr::null_mut(),
closure: ptr::null_mut(),
}
}

#[cfg(Py_3)]
fn async_methods<T>(type_info: &mut ffi::PyTypeObject) {
if let Some(meth) = <T as class::pyasync::PyAsyncProtocolImpl>::tp_as_async() {
Expand Down

0 comments on commit 59fd504

Please sign in to comment.