Skip to content

Commit 3b20aa2

Browse files
committed
fix SpiClient construction
1 parent 14297cd commit 3b20aa2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pgrx/src/spi/client.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ use std::ptr::NonNull;
55
use crate::pg_sys::{self, PgOid};
66
use crate::spi::{PreparedStatement, Query, Spi, SpiCursor, SpiError, SpiResult, SpiTupleTable};
77

8-
pub struct SpiClient;
8+
pub struct SpiClient {
9+
// We need `SpiClient` to be publicly accessible but not constructable because we rely
10+
// on it being properly constructed in order for its Drop impl, which calles `pg_sys::SPI_finish()`,
11+
// to work as expected
12+
_priv_constructor: (),
13+
}
914

1015
impl SpiClient {
1116
/// Connect to Postgres' SPI system
@@ -16,7 +21,7 @@ impl SpiClient {
1621
// assume it could. The truth seems to be that it never actually does. The one user
1722
// of SpiConnection::connect() returns `spi::Result` anyways, so it's no big deal
1823
Spi::check_status(unsafe { pg_sys::SPI_connect() })?;
19-
Ok(SpiClient)
24+
Ok(SpiClient { _priv_constructor: () })
2025
}
2126

2227
/// Prepares a statement that is valid for the lifetime of the client

0 commit comments

Comments
 (0)