Skip to content
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

Add clippy -Awarnings to CI and fix unsound fn #1357

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
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
SCCACHE_DIR: /home/runner/.cache/sccache

strategy:
fail-fast: false
matrix:
version: ["postgres-12", "postgres-13", "postgres-14", "postgres-15", "postgres-16"]

Expand Down Expand Up @@ -351,6 +350,9 @@ jobs:
- name: Run 'cargo pgrx init' for ${{ matrix.version }}
run: cargo pgrx init --pg$PG_VER download

- name: Clippy -Awarnings
run: cargo clippy -p pgrx --features pg$PG_VER -- -Awarnings

- name: create new sample extension
run: cd /tmp/ && cargo pgrx new sample

Expand Down
90 changes: 54 additions & 36 deletions pgrx-sql-entity-graph/src/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ impl PgAggregate {
#[allow(non_snake_case, clippy::too_many_arguments)]
#pg_extern_attr
fn #fn_name(this: #type_state_without_self, #(#args_with_names),*, fcinfo: ::pgrx::pg_sys::FunctionCallInfo) -> #type_state_without_self {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::state(this, (#(#arg_names),*), fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::state(this, (#(#arg_names),*), fcinfo)
)
}
Comment on lines +302 to +307
Copy link
Member Author

@workingjubilee workingjubilee Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly am not entirely sure if this is actually correct to assert, either, but I think this fn in practice only gets called by Postgres, making this one of the many undocumented unsafe blocks to audit later. ^^;

}
});
fn_name
Expand All @@ -322,10 +324,12 @@ impl PgAggregate {
#[allow(non_snake_case, clippy::too_many_arguments)]
#pg_extern_attr
fn #fn_name(this: #type_state_without_self, v: #type_state_without_self, fcinfo: ::pgrx::pg_sys::FunctionCallInfo) -> #type_state_without_self {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::combine(this, v, fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::combine(this, v, fcinfo)
)
}
}
});
Some(fn_name)
Expand All @@ -351,21 +355,25 @@ impl PgAggregate {
#[allow(non_snake_case, clippy::too_many_arguments)]
#pg_extern_attr
fn #fn_name(this: #type_state_without_self, #(#direct_args_with_names),*, fcinfo: ::pgrx::pg_sys::FunctionCallInfo) -> #type_finalize {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::finalize(this, (#(#direct_arg_names),*), fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::finalize(this, (#(#direct_arg_names),*), fcinfo)
)
}
}
});
} else {
pg_externs.push(parse_quote! {
#[allow(non_snake_case, clippy::too_many_arguments)]
#pg_extern_attr
fn #fn_name(this: #type_state_without_self, fcinfo: ::pgrx::pg_sys::FunctionCallInfo) -> #type_finalize {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::finalize(this, (), fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::finalize(this, (), fcinfo)
)
}
}
});
};
Expand All @@ -388,10 +396,12 @@ impl PgAggregate {
#[allow(non_snake_case, clippy::too_many_arguments)]
#pg_extern_attr
fn #fn_name(this: #type_state_without_self, fcinfo: ::pgrx::pg_sys::FunctionCallInfo) -> Vec<u8> {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::serial(this, fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::serial(this, fcinfo)
)
}
}
});
Some(fn_name)
Expand All @@ -415,10 +425,12 @@ impl PgAggregate {
#[allow(non_snake_case, clippy::too_many_arguments)]
#pg_extern_attr
fn #fn_name(this: #type_state_without_self, buf: Vec<u8>, internal: ::pgrx::pgbox::PgBox<#type_state_without_self>, fcinfo: ::pgrx::pg_sys::FunctionCallInfo) -> ::pgrx::pgbox::PgBox<#type_state_without_self> {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::deserial(this, buf, internal, fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::deserial(this, buf, internal, fcinfo)
)
}
}
});
Some(fn_name)
Expand Down Expand Up @@ -447,10 +459,12 @@ impl PgAggregate {
#(#args_with_names),*,
fcinfo: ::pgrx::pg_sys::FunctionCallInfo,
) -> #type_moving_state {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::moving_state(mstate, (#(#arg_names),*), fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::moving_state(mstate, (#(#arg_names),*), fcinfo)
)
}
}
});
Some(fn_name)
Expand Down Expand Up @@ -483,10 +497,12 @@ impl PgAggregate {
#(#args_with_names),*,
fcinfo: ::pgrx::pg_sys::FunctionCallInfo,
) -> #type_moving_state {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::moving_state_inverse(mstate, (#(#arg_names),*), fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::moving_state_inverse(mstate, (#(#arg_names),*), fcinfo)
)
}
}
});
Some(fn_name)
Expand Down Expand Up @@ -517,10 +533,12 @@ impl PgAggregate {
#[allow(non_snake_case, clippy::too_many_arguments)]
#pg_extern_attr
fn #fn_name(mstate: #type_moving_state, #(#direct_args_with_names),* #maybe_comma fcinfo: ::pgrx::pg_sys::FunctionCallInfo) -> #type_finalize {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::moving_finalize(mstate, (#(#direct_arg_names),*), fcinfo)
)
unsafe {
<#target_path as ::pgrx::aggregate::Aggregate>::in_memory_context(
fcinfo,
move |_context| <#target_path as ::pgrx::aggregate::Aggregate>::moving_finalize(mstate, (#(#direct_arg_names),*), fcinfo)
)
}
}
});
Some(fn_name)
Expand Down
2 changes: 1 addition & 1 deletion pgrx/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ where
}

#[inline(always)]
fn in_memory_context<
unsafe fn in_memory_context<
R,
F: FnOnce(&mut PgMemoryContexts) -> R + std::panic::UnwindSafe + std::panic::RefUnwindSafe,
>(
Expand Down
2 changes: 1 addition & 1 deletion pgrx/src/datum/numeric_support/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<const P: u32, const S: u32> Eq for Numeric<P, S> {}
impl<const P: u32, const S: u32> PartialOrd for Numeric<P, S> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.as_anynumeric().partial_cmp(other.as_anynumeric())
Some(self.cmp(other))
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion pgrx/src/htup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn heap_tuple_header_get_datum_length(htup_header: pg_sys::HeapTupleHeader)

/// convert a HeapTupleHeader to a Datum.
#[inline]
pub fn heap_tuple_get_datum(heap_tuple: pg_sys::HeapTuple) -> pg_sys::Datum {
pub unsafe fn heap_tuple_get_datum(heap_tuple: pg_sys::HeapTuple) -> pg_sys::Datum {
unsafe { pg_sys::HeapTupleHeaderGetDatum((*heap_tuple).t_data) }
}

Expand Down