Hi all! I'm still here, I was learning and testing things.
I do not know C, I do not know POSIX, I'm new in making PG extensions.
Here some things I know.
PG extensions works with a single thread, you can use multithread from a extension, but not call PG functions from them.
PG have an API to make it stop from C, which is ereport, still it allow the call of exit(1), in pg is not an issue, this call is done for example, if you deserialising an object and someone put trash/invalid data, is an unrecoverable situation, but this type of situations are a lot more common in PG than Rust, so is not really an issue.
C Bindings implies to work with pointers, there is no way to handle input/output using things like serde, because what matters is the data that points the pointer, this restrict a lot the options.
- Know exactly the data behind each pointer, be able to read from Rust its data to move a object that we can really move out using serde, then build a new pointer with this information.
- Use shared memory, if works use the pointer from there, if fails then no issues with that memory, I have never done something before like this.
- Port the C functions to Rust, which is not ideal, some projects can really be very hard to port, a lot of code, and very far from the idea of C/FFI.
And.. obvs any method used should be cross-platform, not great if a solution only works on linux!
All alternatives seems complex or slow or undesirable.
Use shared data from PGRX is not easy, for some tech reasons, probs because the element is dropped by PG and not Rust, all elements of shared data must be Copy! I have no tested this with the pointers and which would be the behavior, a pointer like *mut i8 is just a usize so should be Copy.. I think, but no idea of the memory behind will still be there without issues to use it like that.
mmm, any thoughts about this?