pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

Odd compiler warning

Open ccleve opened this issue 2 years ago • 7 comments

I just upgraded to v0.11.0 from 0.10.something. I now get this compiler warning:

warning: `extern` block uses type `NodeTag`, which is not FFI-safe
  --> src/cfuncs/bindings.rs:11:16
   |
11 |         index: Relation,
   |                ^^^^^^^^ not FFI-safe
   |
   = note: this enum is non-exhaustive
   = note: `#[warn(improper_ctypes)]` on by default

on this code:

extern "C" {
    pub fn rdb_read_page(
        index: Relation,
        blkno: u32,
        lock_type: ::std::os::raw::c_int,
        pg_buffer: *mut u32,
    ) -> *mut ::std::os::raw::c_char;
}

This points to a function I wrote in C to read/write pages in an index relation.

This warning is a bit odd, because NodeTag doesn't appear in the method signature and I don't know why Relation would not be ffi-safe.

I've been using this code successfully for quite a while now.

ccleve avatar Oct 17 '23 00:10 ccleve

That's... odd. What version of rustc are you using?

workingjubilee avatar Oct 17 '23 01:10 workingjubilee

rustc 1.72.1 (d5c2e9c34 2023-09-13)

Just now, I did a rustup update to 1.73. Same error.

On Mon, Oct 16, 2023 at 8:11 PM Jubilee @.***> wrote:

That's... odd. What version of rustc are you using?

— Reply to this email directly, view it on GitHub https://github.com/pgcentralfoundation/pgrx/issues/1340#issuecomment-1765498848, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAITHKUPVRE6H4IBBLAUI2LX7XLMBAVCNFSM6AAAAAA6C7HFSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRVGQ4TQOBUHA . You are receiving this because you authored the thread.Message ID: @.***>

ccleve avatar Oct 17 '23 02:10 ccleve

It looks like Rust examines the fields recursively and sometimes forgets to check locality.

workingjubilee avatar Oct 17 '23 02:10 workingjubilee

Just to clarify, that's pgrx_pg_sys::Relation which is a *mut pgrx_pg_sys::RelationData, right?

workingjubilee avatar Oct 17 '23 03:10 workingjubilee

Reported as https://github.com/rust-lang/rust/issues/116831

workingjubilee avatar Oct 17 '23 04:10 workingjubilee

It says "use crate::pg_sys::Relation;" at the top of the file. Hover over it in CLion and it says:

pgrx_pg_sys::include::pg16 pub type Relation = *mut RelationData

On Mon, Oct 16, 2023 at 10:14 PM Jubilee @.***> wrote:

Just to clarify, that's pgrx_pg_sys::Relation which is a *mut pgrx_pg_sys::RelationData, right?

— Reply to this email directly, view it on GitHub https://github.com/pgcentralfoundation/pgrx/issues/1340#issuecomment-1765595030, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAITHKXO5GLPVZRMYELDYXTX7XZXXAVCNFSM6AAAAAA6C7HFSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRVGU4TKMBTGA . You are receiving this because you authored the thread.Message ID: @.***>

ccleve avatar Oct 17 '23 13:10 ccleve

The workaround, for now, is to put

#![allow(improper_ctypes)]

in lib.rs.

ccleve avatar Oct 17 '23 14:10 ccleve