-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
Conversation
pgx-examples/nostd/sql/nostd-1.0.sql
Outdated
This file is auto generated by pgx. | ||
|
||
The ordering of items is not stable, it is driven by a dependency graph. | ||
*/ |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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:
pgx::InOutFuncs
orpgx:PgVarlenaInOutFuncs
traits to provide custom input/output functions for a custom#[derive(PostgresType)]
will need to update the signatures to referencepgx::cstr_core::CStr
instead ofstd::ffi::CStr
.