1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::cast_ptr_alignment)]
#[macro_use]
extern crate bitflags;
extern crate alloc;
extern crate core;
pub use pgx_macros;
pub use pgx_macros::*;
pub mod prelude;
pub mod aggregate;
pub mod array;
pub mod atomics;
pub mod bgworkers;
pub mod callbacks;
pub mod datum;
pub mod enum_helper;
pub mod fcinfo;
pub mod ffi;
pub mod guc;
pub mod heap_tuple;
#[cfg(feature = "cshim")]
pub mod hooks;
pub mod htup;
pub mod inoutfuncs;
pub mod itemptr;
pub mod iter;
#[cfg(feature = "cshim")]
pub mod list;
pub mod lwlock;
pub mod memcxt;
pub mod misc;
#[cfg(feature = "cshim")]
pub mod namespace;
pub mod nodes;
pub mod pgbox;
pub mod rel;
pub mod shmem;
pub mod spi;
#[cfg(feature = "cshim")]
pub mod spinlock;
pub mod srf;
pub mod stringinfo;
pub mod trigger_support;
pub mod tupdesc;
pub mod varlena;
pub mod wrappers;
pub mod xid;
#[doc(hidden)]
pub use once_cell;
mod layout;
mod slice;
pub use aggregate::*;
pub use atomics::*;
pub use callbacks::*;
pub use datum::*;
pub use enum_helper::*;
pub use fcinfo::*;
pub use guc::*;
#[cfg(feature = "cshim")]
pub use hooks::*;
pub use htup::*;
pub use inoutfuncs::*;
pub use itemptr::*;
#[cfg(feature = "cshim")]
pub use list::*;
pub use lwlock::*;
pub use memcxt::*;
#[cfg(feature = "cshim")]
pub use namespace::*;
pub use nodes::*;
pub use pgbox::*;
pub use rel::*;
pub use shmem::*;
pub use spi::Spi; pub use stringinfo::*;
pub use trigger_support::*;
pub use tupdesc::*;
pub use varlena::*;
pub use wrappers::*;
pub use xid::*;
pub use pgx_pg_sys as pg_sys; pub use pg_sys::elog::PgLogLevel;
pub use pg_sys::errcodes::PgSqlErrorCode;
pub use pg_sys::oids::PgOid;
pub use pg_sys::panic::pgx_extern_c_guard;
pub use pg_sys::pg_try::PgTryBuilder;
pub use pg_sys::utils::name_data_to_str;
pub use pg_sys::PgBuiltInOids;
pub use pg_sys::{
check_for_interrupts, debug1, debug2, debug3, debug4, debug5, ereport, error, function_name,
info, log, notice, warning, FATAL, PANIC,
};
#[doc(hidden)]
pub use pgx_sql_entity_graph;
#[cfg(all(feature = "pg15", not(feature = "unsafe-postgres")))]
const _: () = {
const fn same_slice(a: &[u8], b: &[u8]) -> bool {
if a.len() != b.len() {
return false;
}
let mut i = 0;
while i < a.len() {
if a[i] != b[i] {
return false;
}
i += 1;
}
true
}
assert!(
same_slice(pg_sys::FMGR_ABI_EXTRA, b"PostgreSQL\0"),
"Unsupported Postgres ABI. Perhaps you need `--features unsafe-postgres`?",
);
};
#[macro_export]
macro_rules! pg_module_magic {
() => {
$crate::pg_magic_func!();
$crate::pg_sql_graph_magic!();
};
}
#[macro_export]
macro_rules! pg_magic_func {
() => {
#[no_mangle]
#[allow(non_snake_case)]
#[allow(unused)]
#[link_name = "Pg_magic_func"]
#[doc(hidden)]
pub extern "C" fn Pg_magic_func() -> &'static pgx::pg_sys::Pg_magic_struct {
use core::mem::size_of;
use pgx;
#[cfg(any(feature = "pg11", feature = "pg12"))]
const MY_MAGIC: pgx::pg_sys::Pg_magic_struct = pgx::pg_sys::Pg_magic_struct {
len: size_of::<pgx::pg_sys::Pg_magic_struct>() as i32,
version: pgx::pg_sys::PG_VERSION_NUM as i32 / 100,
funcmaxargs: pgx::pg_sys::FUNC_MAX_ARGS as i32,
indexmaxkeys: pgx::pg_sys::INDEX_MAX_KEYS as i32,
namedatalen: pgx::pg_sys::NAMEDATALEN as i32,
float4byval: pgx::pg_sys::USE_FLOAT4_BYVAL as i32,
float8byval: cfg!(target_pointer_width = "64") as i32,
};
#[cfg(any(feature = "pg13", feature = "pg14"))]
const MY_MAGIC: pgx::pg_sys::Pg_magic_struct = pgx::pg_sys::Pg_magic_struct {
len: size_of::<pgx::pg_sys::Pg_magic_struct>() as i32,
version: pgx::pg_sys::PG_VERSION_NUM as i32 / 100,
funcmaxargs: pgx::pg_sys::FUNC_MAX_ARGS as i32,
indexmaxkeys: pgx::pg_sys::INDEX_MAX_KEYS as i32,
namedatalen: pgx::pg_sys::NAMEDATALEN as i32,
float8byval: cfg!(target_pointer_width = "64") as i32,
};
#[cfg(any(feature = "pg15"))]
const MY_MAGIC: pgx::pg_sys::Pg_magic_struct = pgx::pg_sys::Pg_magic_struct {
len: size_of::<pgx::pg_sys::Pg_magic_struct>() as i32,
version: pgx::pg_sys::PG_VERSION_NUM as i32 / 100,
funcmaxargs: pgx::pg_sys::FUNC_MAX_ARGS as i32,
indexmaxkeys: pgx::pg_sys::INDEX_MAX_KEYS as i32,
namedatalen: pgx::pg_sys::NAMEDATALEN as i32,
float8byval: cfg!(target_pointer_width = "64") as i32,
abi_extra: {
let magic = pgx::pg_sys::FMGR_ABI_EXTRA;
let mut abi = [0 as ::pgx::ffi::c_char; 32];
let mut i = 0;
while i < magic.len() {
abi[i] = magic[i] as _;
i += 1;
}
abi
},
};
pgx::initialize();
&MY_MAGIC
}
};
}
#[macro_export]
macro_rules! pg_sql_graph_magic {
() => {
#[no_mangle]
#[doc(hidden)]
#[rustfmt::skip] pub extern "Rust" fn __pgx_marker(
_: (),
) -> $crate::pgx_sql_entity_graph::ControlFile {
use ::core::convert::TryFrom;
let package_version = env!("CARGO_PKG_VERSION");
let context = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/",
env!("CARGO_CRATE_NAME"),
".control"
))
.replace("@CARGO_VERSION@", package_version);
let control_file =
$crate::pgx_sql_entity_graph::ControlFile::try_from(context.as_str())
.expect("Could not parse control file, is it valid?");
control_file
}
};
}
#[allow(unused)]
pub fn initialize() {
pg_sys::panic::register_pg_guard_panic_hook();
}