Skip to content

Commit

Permalink
Merge pull request #1162 from alex/disable-buffer-more
Browse files Browse the repository at this point in the history
Complete the process of disabling buffers with Py_LIMITED_API
  • Loading branch information
kngwyu authored Sep 8, 2020
2 parents 4325a59 + 80e2497 commit e8936be
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/class/proto_methods.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#[cfg(not(Py_LIMITED_API))]
use crate::class::buffer::PyBufferProcs;
use crate::class::{
basic::PyObjectMethods, buffer::PyBufferProcs, descr::PyDescrMethods, gc::PyGCMethods,
iter::PyIterMethods, mapping::PyMappingMethods, number::PyNumberMethods,
pyasync::PyAsyncMethods, sequence::PySequenceMethods,
basic::PyObjectMethods, descr::PyDescrMethods, gc::PyGCMethods, iter::PyIterMethods,
mapping::PyMappingMethods, number::PyNumberMethods, pyasync::PyAsyncMethods,
sequence::PySequenceMethods,
};
use std::{
ptr::{self, NonNull},
Expand All @@ -17,6 +19,7 @@ pub trait PyProtoMethods {
fn basic_methods() -> Option<NonNull<PyObjectMethods>> {
None
}
#[cfg(not(Py_LIMITED_API))]
fn buffer_methods() -> Option<NonNull<PyBufferProcs>> {
None
}
Expand Down Expand Up @@ -53,6 +56,7 @@ impl<T: HasProtoRegistry> PyProtoMethods for T {
fn basic_methods() -> Option<NonNull<PyObjectMethods>> {
NonNull::new(Self::registry().basic_methods.load(Ordering::Relaxed))
}
#[cfg(not(Py_LIMITED_API))]
fn buffer_methods() -> Option<NonNull<PyBufferProcs>> {
NonNull::new(Self::registry().buffer_methods.load(Ordering::Relaxed))
}
Expand Down Expand Up @@ -85,6 +89,7 @@ pub struct PyProtoRegistry {
/// Basic protocols.
basic_methods: AtomicPtr<PyObjectMethods>,
/// Buffer protocols.
#[cfg(not(Py_LIMITED_API))]
buffer_methods: AtomicPtr<PyBufferProcs>,
/// Descr pProtocols.
descr_methods: AtomicPtr<PyDescrMethods>,
Expand All @@ -105,6 +110,7 @@ impl PyProtoRegistry {
PyProtoRegistry {
async_methods: AtomicPtr::new(ptr::null_mut()),
basic_methods: AtomicPtr::new(ptr::null_mut()),
#[cfg(not(Py_LIMITED_API))]
buffer_methods: AtomicPtr::new(ptr::null_mut()),
descr_methods: AtomicPtr::new(ptr::null_mut()),
gc_methods: AtomicPtr::new(ptr::null_mut()),
Expand All @@ -122,6 +128,7 @@ impl PyProtoRegistry {
self.basic_methods
.store(Box::into_raw(Box::new(methods)), Ordering::Relaxed)
}
#[cfg(not(Py_LIMITED_API))]
pub fn set_buffer_methods(&self, methods: PyBufferProcs) {
self.buffer_methods
.store(Box::into_raw(Box::new(methods)), Ordering::Relaxed)
Expand Down

0 comments on commit e8936be

Please sign in to comment.