Skip to content

Commit 2cb1b37

Browse files
authored
improve pg_magic_func (#2088)
Based on #2087, to make CI happy. This patch 1. changes the syntax from `pgrx::pg_module_magic!(c"NAME", c"VERSION")` to `pgrx::pg_module_magic!(name = c"NAME", version = c"VERSION")` 2. allows `pgrx::pg_module_magic!(name, version)` to fill the name and version by package name and version in magic struct 3. allows `pgrx::pg_module_magic!(name, version = c"1.0.0")` to fill the name by package name and the version by specifying one in magic struct 4. allows `pgrx::pg_module_magic!()` to fill the name and version with null pointers in magic struct 5. checks type of `name` and `version`, in order to avoid misuse since `str::as_ptr` also exists
1 parent c0de15d commit 2cb1b37

43 files changed

Lines changed: 176 additions & 226 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cargo-pgrx/src/command/info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl CommandExecute for Info {
7878
}
7979
}
8080

81-
fn version(ver: &str) -> Cow<str> {
81+
fn version(ver: &str) -> Cow<'_, str> {
8282
if ver.starts_with("pg") {
8383
Cow::Borrowed(ver)
8484
} else {

cargo-pgrx/src/command/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ fn compute_sql(package_name: &str, manifest: &Manifest) -> eyre::Result<()> {
594594
Ok(())
595595
}
596596

597-
fn parse_object(data: &[u8]) -> object::Result<object::File> {
597+
fn parse_object(data: &[u8]) -> object::Result<object::File<'_>> {
598598
let kind = object::FileKind::parse(data)?;
599599

600600
match kind {

cargo-pgrx/src/templates/lib_rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use pgrx::prelude::*;
22

3-
::pgrx::pg_module_magic!(c"{name}", pgrx::pg_sys::PG_VERSION);
3+
::pgrx::pg_module_magic!(name, version);
44

55
#[pg_extern]
66
fn hello_{name}() -> &'static str {{

pgrx-examples/aggregate/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use pgrx::StringInfo;
1414
use serde::{Deserialize, Serialize};
1515
use std::str::FromStr;
1616

17-
pgrx::pg_module_magic!(c"aggregate", pgrx::pg_sys::PG_VERSION);
17+
pgrx::pg_module_magic!(name, version);
1818

1919
#[derive(Copy, Clone, PostgresType, Serialize, Deserialize)]
2020
#[pgvarlena_inoutfuncs]

pgrx-examples/arrays/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use pgrx::prelude::*;
1111
use serde::*;
1212

13-
pgrx::pg_module_magic!(c"arrays", pgrx::pg_sys::PG_VERSION);
13+
pgrx::pg_module_magic!(name, version);
1414

1515
#[pg_extern]
1616
fn sq_euclid_pgrx(a: Array<f32>, b: Array<f32>) -> f32 {

pgrx-examples/bad_ideas/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::io::{Read, Write};
1414
use std::panic::catch_unwind;
1515
use std::process::Command;
1616

17-
pgrx::pg_module_magic!(c"bad_ideas", pgrx::pg_sys::PG_VERSION);
17+
pgrx::pg_module_magic!(name, version);
1818

1919
#[pg_extern]
2020
fn panic(s: &str) -> bool {

pgrx-examples/bgworker/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::time::Duration;
2626
this background worker
2727
*/
2828

29-
pgrx::pg_module_magic!(c"bgworker", pgrx::pg_sys::PG_VERSION);
29+
pgrx::pg_module_magic!(name, version);
3030

3131
#[pg_guard]
3232
pub extern "C-unwind" fn _PG_init() {

pgrx-examples/bytea/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use libflate::gzip::{Decoder, Encoder};
1111
use pgrx::prelude::*;
1212
use std::io::{Read, Write};
1313

14-
pgrx::pg_module_magic!(c"bytea", pgrx::pg_sys::PG_VERSION);
14+
pgrx::pg_module_magic!(name, version);
1515

1616
/// gzip bytes. Postgres will automatically convert `text`/`varchar` data into `bytea`
1717
#[pg_extern]

pgrx-examples/composite_type/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using composite types.
2323
use pgrx::{opname, pg_operator, prelude::*};
2424

2525
// All `pgrx` extensions will do this:
26-
pgrx::pg_module_magic!(c"composite_type", pgrx::pg_sys::PG_VERSION);
26+
pgrx::pg_module_magic!(name, version);
2727

2828
/* Composite types must be defined either before they are used.
2929

pgrx-examples/custom_libname/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
1010
use pgrx::prelude::*;
1111

12-
pgrx::pg_module_magic!(c"custom_libname", pgrx::pg_sys::PG_VERSION);
12+
pgrx::pg_module_magic!(name, version);
1313

1414
#[pg_extern]
1515
fn hello_custom_libname() -> &'static str {

0 commit comments

Comments
 (0)