Skip to content

Commit

Permalink
Fix compilation for Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-N committed Mar 17, 2019
1 parent dd8e621 commit 5a3466d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/ffi2/descrobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef {
closure: ptr::null_mut(),
};

pub const PyGetSetDef_DICT: PyGetSetDef = PyGetSetDef_INIT;

impl Clone for PyGetSetDef {
#[inline]
fn clone(&self) -> PyGetSetDef {
Expand Down
12 changes: 11 additions & 1 deletion src/ffi3/descrobject.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::ffi3::methodobject::PyMethodDef;
use crate::ffi3::object::{PyObject, PyTypeObject};
use crate::ffi3::object::{
PyObject, PyObject_GenericGetDict, PyObject_GenericSetDict, PyTypeObject,
};
use crate::ffi3::structmember::PyMemberDef;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
Expand Down Expand Up @@ -27,6 +29,14 @@ pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef {
closure: ptr::null_mut(),
};

pub const PyGetSetDef_DICT: PyGetSetDef = PyGetSetDef {
name: "__dict__\0".as_ptr() as *mut c_char,
get: Some(PyObject_GenericGetDict),
set: Some(PyObject_GenericSetDict),
doc: ptr::null_mut(),
closure: ptr::null_mut(),
};

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyClassMethodDescr_Type: PyTypeObject;
Expand Down
11 changes: 1 addition & 10 deletions src/type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use crate::{class, ffi, gil};
use class::methods::PyMethodsProtocol;
use std::collections::HashMap;
use std::ffi::CString;
use std::os::raw::c_char;
use std::os::raw::c_void;
use std::ptr;
use std::ptr::NonNull;

/// Python type information.
Expand Down Expand Up @@ -397,14 +395,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(ffi::PyGetSetDef_DICT);
}
if !props.is_empty() {
props.push(ffi::PyGetSetDef_INIT);
Expand Down

0 comments on commit 5a3466d

Please sign in to comment.