Skip to content

Fix memory management in header-translator #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 14, 2023
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
6 changes: 2 additions & 4 deletions crates/header-translator/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl ClassCache {
fn all_methods_data(&self) -> impl Iterator<Item = (bool, &str)> {
self.to_emit
.iter()
.flat_map(|cache| cache.methods.iter().map(|m| (m.is_class, &*m.selector)))
.flat_map(|cache| cache.methods.iter().map(|m| m.id()))
}
}

Expand Down Expand Up @@ -147,9 +147,7 @@ impl<'a> Cache<'a> {
let mut methods: Vec<_> = cache
.methods
.iter()
.filter(|method| {
!seen_methods.contains(&(method.is_class, &method.selector))
})
.filter(|method| !seen_methods.contains(&method.id()))
.filter_map(|method| {
method.clone().update(ClassData::get_method_data(
data,
Expand Down
9 changes: 5 additions & 4 deletions crates/header-translator/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::fmt::Write;
use clang::token::TokenKind;
use clang::{Entity, EntityKind, EntityVisitResult};

use crate::context::Context;
use crate::immediate_children;
use crate::unexposed_macro::UnexposedMacro;
use crate::unexposed_attr::UnexposedAttr;

#[derive(Clone, Debug, PartialEq)]
pub enum Expr {
Expand Down Expand Up @@ -36,7 +37,7 @@ impl Expr {
}
}

pub fn parse_enum_constant(entity: &Entity<'_>) -> Option<Self> {
pub fn parse_enum_constant(entity: &Entity<'_>, context: &Context<'_>) -> Option<Self> {
let mut declaration_references = Vec::new();

entity.visit_children(|entity, _parent| {
Expand All @@ -51,8 +52,8 @@ impl Expr {

immediate_children(entity, |entity, _span| match entity.get_kind() {
EntityKind::UnexposedAttr => {
if let Some(macro_) = UnexposedMacro::parse(&entity) {
panic!("parsed macro in expr: {macro_:?}, {entity:?}");
if let Some(attr) = UnexposedAttr::parse(&entity, context) {
error!(?attr, "unknown attribute");
}
}
_ => {
Expand Down
3 changes: 1 addition & 2 deletions crates/header-translator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ mod library;
mod method;
mod objc2_utils;
mod output;
mod property;
mod rust_type;
mod stmt;
mod unexposed_macro;
mod unexposed_attr;

pub use self::cache::Cache;
pub use self::config::Config;
Expand Down
Loading