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

How to deal with Postgres macros? #316

Open
ccleve opened this issue Dec 1, 2021 · 2 comments
Open

How to deal with Postgres macros? #316

ccleve opened this issue Dec 1, 2021 · 2 comments
Labels
ffi-bindgen question Further information is requested

Comments

@ccleve
Copy link
Contributor

ccleve commented Dec 1, 2021

This is more of a question than an issue.

Postgres is full of C macros, for example,
#define HeapTupleIsValid(tuple) PointerIsValid(tuple), which references
#define PointerIsValid(pointer) ((const void*)(pointer) != NULL), which references
#define NULL ((void *)0).

How do you deal with this in Rust? These macros can change from pg version to version, so you probably want to use them somehow, but I don't see any reference to them in pgx-pg-sys, and bindgen doesn't seem to do anything with them.

Just bypass them and do tuple.is_null()?

@eeeebbbbrrrr
Copy link
Contributor

eeeebbbbrrrr commented Dec 1, 2021

https://github.com/zombodb/pgx/tree/master/pgx-pg-sys/cshim

Some have been wrapped as C functions. Others I’ve hand-ported to Rust.

In general tho, we don’t have a good solution here. I’ve often wondered how hard it would be to write something to programmatically convert the simple ones from C to Rust. Kinda a bindgen but for (simple) C macros.

@workingjubilee
Copy link
Member

This isn't "really" bindgen related... but it's also bindgen related (specifically regarding how bindgen is not quite enough for our needs). See #798 and #730 for other examples of that. So, tagging until a better tag comes up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ffi-bindgen question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants