Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/py_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ macro_rules! impl_py_gc_traverse {
}
}
};
($name:ty { $($fields:ident),* }) => {
($name:ty { $($fields:ident),* $(,)? }) => {
impl crate::py_gc::PyGcTraverse for $name {
fn py_gc_traverse(&self, visit: &pyo3::PyVisit<'_>) -> Result<(), pyo3::PyTraverseError> {
$(self.$fields.py_gc_traverse(visit)?;)*
Expand Down
8 changes: 8 additions & 0 deletions src/serializers/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ pub(crate) struct ExtraOwned {
exclude: Option<Py<PyAny>>,
}

impl_py_gc_traverse!(ExtraOwned {
model,
fallback,
context,
include,
exclude,
});

#[derive(Clone)]
enum FieldNameOwned {
Root,
Expand Down
15 changes: 8 additions & 7 deletions src/serializers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ pub struct SchemaSerializer {
py_config: Option<Py<PyDict>>,
}

impl_py_gc_traverse!(SchemaSerializer {
serializer,
definitions,
py_schema,
py_config,
});

#[pymethods]
impl SchemaSerializer {
#[new]
Expand Down Expand Up @@ -186,13 +193,7 @@ impl SchemaSerializer {
}

fn __traverse__(&self, visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
visit.call(&self.py_schema)?;
if let Some(ref py_config) = self.py_config {
visit.call(py_config)?;
}
self.serializer.py_gc_traverse(&visit)?;
self.definitions.py_gc_traverse(&visit)?;
Ok(())
self.py_gc_traverse(&visit)
}
}

Expand Down
34 changes: 14 additions & 20 deletions src/serializers/type_serializers/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use pyo3::PyTraverseError;
use pyo3::types::PyString;

use crate::definitions::DefinitionsBuilder;
use crate::py_gc::PyGcTraverse;
use crate::serializers::SerializationState;
use crate::tools::SchemaDict;
use crate::tools::{function_name, py_err, py_error_type};
Expand Down Expand Up @@ -437,6 +438,11 @@ pub(crate) struct SerializationCallable {
filter: AnyFilter,
}

impl_py_gc_traverse!(SerializationCallable {
serializer,
extra_owned
});

impl SerializationCallable {
pub fn new(serializer: &Arc<CombinedSerializer>, state: &SerializationState<'_, '_>) -> Self {
Self {
Expand All @@ -447,16 +453,7 @@ impl SerializationCallable {
}

fn __traverse__(&self, visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
if let Some(model) = &self.extra_owned.model {
visit.call(model)?;
}
if let Some(fallback) = &self.extra_owned.fallback {
visit.call(fallback)?;
}
if let Some(context) = &self.extra_owned.context {
visit.call(context)?;
}
Ok(())
self.py_gc_traverse(&visit)
}

fn __clear__(&mut self) {
Expand Down Expand Up @@ -542,6 +539,12 @@ struct SerializationInfo {
serialize_as_any: bool,
}

impl_py_gc_traverse!(SerializationInfo {
include,
exclude,
context
});

impl SerializationInfo {
fn new(state: &SerializationState<'_, '_>, is_field_serializer: bool) -> PyResult<Self> {
let extra = &state.extra;
Expand Down Expand Up @@ -584,16 +587,7 @@ impl SerializationInfo {
}

fn __traverse__(&self, visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
if let Some(include) = &self.include {
visit.call(include)?;
}
if let Some(exclude) = &self.exclude {
visit.call(exclude)?;
}
if let Some(context) = &self.context {
visit.call(context)?;
}
Ok(())
self.py_gc_traverse(&visit)
}

fn __clear__(&mut self) {
Expand Down
18 changes: 8 additions & 10 deletions src/serializers/type_serializers/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use pyo3::PyTraverseError;
use serde::ser::SerializeSeq;

use crate::definitions::DefinitionsBuilder;
use crate::py_gc::PyGcTraverse;
use crate::serializers::SerializationState;
use crate::tools::SchemaDict;

Expand Down Expand Up @@ -144,6 +145,12 @@ pub(crate) struct SerializationIterator {
filter: SchemaFilter<usize>,
}

impl_py_gc_traverse!(SerializationIterator {
iterator,
item_serializer,
extra_owned,
});

impl SerializationIterator {
pub fn new(
py_iter: &Bound<'_, PyIterator>,
Expand All @@ -161,16 +168,7 @@ impl SerializationIterator {
}

fn __traverse__(&self, visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
if let Some(model) = &self.extra_owned.model {
visit.call(model)?;
}
if let Some(fallback) = &self.extra_owned.fallback {
visit.call(fallback)?;
}
if let Some(context) = &self.extra_owned.context {
visit.call(context)?;
}
Ok(())
self.py_gc_traverse(&visit)
}

fn __clear__(&mut self) {
Expand Down
13 changes: 8 additions & 5 deletions src/validators/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,13 @@ pub struct ValidationInfo {
mode: InputType,
}

impl_py_gc_traverse!(ValidationInfo {
config,
context,
data,
field_name
});

impl ValidationInfo {
fn new(py: Python, extra: &Extra<'_, '_>, config: &Py<PyAny>, field_name: Option<Py<PyString>>) -> Self {
Self {
Expand All @@ -548,11 +555,7 @@ impl ValidationInfo {
}

fn __traverse__(&self, visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
visit.call(&self.config)?;
if let Some(context) = &self.context {
visit.call(context)?;
}
Ok(())
self.py_gc_traverse(&visit)
}

fn __clear__(&mut self) {
Expand Down
14 changes: 8 additions & 6 deletions src/validators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ pub struct SchemaValidator {
cache_str: StringCacheMode,
}

impl_py_gc_traverse!(SchemaValidator {
validator,
definitions,
py_schema,
py_config,
});

#[pymethods]
impl SchemaValidator {
#[new]
Expand Down Expand Up @@ -403,12 +410,7 @@ impl SchemaValidator {
}

fn __traverse__(&self, visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
self.validator.py_gc_traverse(&visit)?;
visit.call(&self.py_schema)?;
if let Some(ref py_config) = self.py_config {
visit.call(py_config)?;
}
Ok(())
self.py_gc_traverse(&visit)
}
}

Expand Down
Loading