pgcentralfoundation / pgrx

Build Postgres Extensions with Rust!
Other
3.57k stars 242 forks source link

Support `#[link_name]` (and other attributes?) in `#[pg_guard]` wrapper. #794

Open thomcc opened 1 year ago

thomcc commented 1 year ago

In https://github.com/tcdi/pgx/pull/793#issuecomment-1285718887 I wanted to do

    #[pgx_macros::pg_guard]
    extern "C" {
        #[link_name = "pgx_SpinLockInit"]
        pub fn SpinLockInit(lock: *mut pg_sys::slock_t);
        // ...
    }

But couldn't because #[pg_guard] doesn't preserve attributes. It would be relatively simple to preserve them here: https://github.com/tcdi/pgx/blob/98ff0729c24f415b84814eb6c539d387146e4326/pgx-utils/src/rewriter.rs#L109-L111, although perhaps there's an argument that some should go on the parent (like #[doc]).

This is a pretty small nit, so I'm punting on it for now, but wanted to file the issue so I could come back to it later.

thomcc commented 1 year ago

A rough cut of this is https://github.com/thomcc/pgx/tree/attr-pg_guard. For some reason, it hits linker errors in other functions -- it's likely this approach is slightly too clever.

I have other things I wanted to work on today, so I'll come back to this later (maybe later today or tomorrow).

workingjubilee commented 1 year ago

As an update, this works on the top level but the wrapper still seems to wonkify the argument if any attempt to apply attributes to the arguments (like cfg, in https://github.com/tcdi/pgx/pull/800) is done.