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

support a pgx extension compiling with no_std #385

Merged
merged 8 commits into from
Feb 1, 2022
Merged

Conversation

eeeebbbbrrrr
Copy link
Contributor

@eeeebbbbrrrr eeeebbbbrrrr commented Jan 18, 2022

This plumbs through changes to allow a pgx extension to declare itself #![no_std] and still have it to compile correctly.

Use of extern crate alloc, however, is required.

There's an example in pgx-examples/nostd that demonstrates that all the things we officially support at least compile.

A release note:

  • Code that implements the pgx::InOutFuncs or pgx:PgVarlenaInOutFuncs traits to provide custom input/output functions for a custom #[derive(PostgresType)] will need to update the signatures to reference pgx::cstr_core::CStr instead of std::ffi::CStr.

@eeeebbbbrrrr eeeebbbbrrrr added the enhancement New feature or request label Jan 18, 2022
This file is auto generated by pgx.

The ordering of items is not stable, it is driven by a dependency graph.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is an old sql file. We can delete this.

@@ -290,12 +290,12 @@ extension_sql!(r#"\
);

#[pg_extern(immutable)]
fn complex_in(input: &std::ffi::CStr) -> PgBox<Complex> {
fn complex_in(input: &pgx::cstr_core::CStr) -> PgBox<Complex> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm it'd be nice if we could provide like a from impl for this in std code so that users could just .into() it.

if is_null {
None
} else if datum == 0 {
panic!("a cstring Datum was flagged as non-null but the datum is zero");
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh... We should probably make a TryFromDatum at some point so users could safely handle this.

@Hoverbear Hoverbear changed the base branch from develop to master February 1, 2022 17:16
@Hoverbear Hoverbear changed the base branch from master to develop February 1, 2022 17:16
namedatalen: pgx::pg_sys::NAMEDATALEN as c_int,
float4byval: pgx::pg_sys::USE_FLOAT4_BYVAL as c_int,
float8byval: pgx::pg_sys::USE_FLOAT8_BYVAL as c_int,
len: size_of::<pgx::pg_sys::Pg_magic_struct>() as i32,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is mildly dangerous for portability... according to https://doc.rust-lang.org/std/os/raw/type.c_int.html, this is almost always an i32, but it's possible it is not... Ref: rust-lang/rfcs#3012

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will be fine as long as we don't end up with like avr or msp430 users.

@Hoverbear Hoverbear merged commit 10e133e into develop Feb 1, 2022
@Hoverbear Hoverbear deleted the nostd-support branch February 1, 2022 19:00
@Hoverbear Hoverbear mentioned this pull request Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants