Skip to content

Commit dd1248c

Browse files
committed
Trust libpq-fe.h's defines over probing in extconf.rb
The headers of libpq already give us nice defines for almost all features we want to support based when available so let's just trust libpq-fe.h to simplify our code. The only exception is PQresultMemorySize() which we need to check for manually since it was added in PostgreSQL 12, before libq-fe.h started adding defines for new features.
1 parent 1531908 commit dd1248c

7 files changed

Lines changed: 30 additions & 36 deletions

File tree

ext/extconf.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,6 @@ module PG
311311
"of this gem or upgrade your database to at least PostgreSQL-10."
312312
# optional headers/functions
313313
have_func 'PQresultMemorySize', 'libpq-fe.h' # since PostgreSQL-12
314-
have_func 'PQenterPipelineMode', 'libpq-fe.h' do |src| # since PostgreSQL-14
315-
# Ensure header files fit as well
316-
src + " int con(){ return PGRES_PIPELINE_SYNC; }"
317-
end
318-
have_func 'PQsetChunkedRowsMode', 'libpq-fe.h' # since PostgreSQL-17
319-
have_func 'PQfullProtocolVersion', 'libpq-fe.h' # since PostgreSQL-18
320314
have_func 'timegm'
321315
have_func 'rb_io_wait' # since ruby-3.0
322316
have_func 'rb_io_descriptor' # since ruby-3.1

ext/gvl_wrappers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "pg.h"
77

88

9-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
9+
#ifndef LIBPQ_HAS_CHUNK_MODE
1010
PGresult *PQclosePrepared(PGconn *conn, const char *stmtName){return NULL;}
1111
PGresult *PQclosePortal(PGconn *conn, const char *portalName){return NULL;}
1212
int PQsendClosePrepared(PGconn *conn, const char *stmtName){return 0;}
@@ -16,7 +16,7 @@ int PQcancelBlocking(PGcancelConn *cancelConn){return 0;}
1616
int PQcancelStart(PGcancelConn *cancelConn){return 0;}
1717
PostgresPollingStatusType PQcancelPoll(PGcancelConn *cancelConn){return PGRES_POLLING_FAILED;}
1818
#endif
19-
#ifndef HAVE_PQENTERPIPELINEMODE
19+
#ifndef LIBPQ_HAS_PIPELINING
2020
int PQpipelineSync(PGconn *conn){return 0;}
2121
#endif
2222

ext/gvl_wrappers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# include RUBY_EXTCONF_H
2222
#endif
2323

24-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
24+
#ifndef LIBPQ_HAS_CHUNK_MODE
2525
typedef struct pg_cancel_conn PGcancelConn;
2626
#endif
2727

ext/pg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ Init_pg_ext(void)
508508
rb_define_const(rb_mPGconstants, "PGRES_COPY_BOTH", INT2FIX(PGRES_COPY_BOTH));
509509
/* Result#result_status constant - Single tuple from larger resultset. */
510510
rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
511-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
511+
#ifdef LIBPQ_HAS_CHUNK_MODE
512512
/* Result#result_status constant - tuple chunk from larger resultset. */
513513
rb_define_const(rb_mPGconstants, "PGRES_TUPLES_CHUNK", INT2FIX(PGRES_TUPLES_CHUNK));
514514
#endif
515515

516-
#ifdef HAVE_PQENTERPIPELINEMODE
516+
#ifdef LIBPQ_HAS_PIPELINING
517517
/* Result#result_status constant - The PG::Result represents a synchronization point in pipeline mode, requested by Connection#pipeline_sync.
518518
*
519519
* This status occurs only when pipeline mode has been selected. */
@@ -643,7 +643,7 @@ Init_pg_ext(void)
643643
rb_define_const(rb_mPGconstants, "PG_DIAG_CONSTRAINT_NAME", INT2FIX(PG_DIAG_CONSTRAINT_NAME));
644644
#endif
645645

646-
#ifdef HAVE_PQENTERPIPELINEMODE
646+
#ifdef LIBPQ_HAS_PIPELINING
647647
/* Connection#pipeline_status constant
648648
*
649649
* The libpq connection is in pipeline mode.

ext/pg_cancel_connection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515

16-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
16+
#ifdef LIBPQ_HAS_CHUNK_MODE
1717

1818
static VALUE rb_cPG_Cancon;
1919
static ID s_id_autoclose_set;
@@ -340,7 +340,7 @@ pg_cancon_finish(VALUE self)
340340
void
341341
init_pg_cancon(void)
342342
{
343-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
343+
#ifdef LIBPQ_HAS_CHUNK_MODE
344344
s_id_autoclose_set = rb_intern("autoclose=");
345345

346346
rb_cPG_Cancon = rb_define_class_under( rb_mPG, "CancelConnection", rb_cObject );

ext/pg_connection.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ pgconn_protocol_version(VALUE self)
865865
return INT2NUM(protocol_version);
866866
}
867867

868-
#ifdef HAVE_PQFULLPROTOCOLVERSION
868+
#ifdef LIBPQ_HAS_FULL_PROTOCOL_VERSION
869869
/*
870870
* call-seq:
871871
* conn.full_protocol_version -> Integer
@@ -1038,7 +1038,7 @@ pgconn_backend_pid(VALUE self)
10381038
return INT2NUM(PQbackendPID(pg_get_pgconn(self)));
10391039
}
10401040

1041-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
1041+
#ifndef LIBPQ_HAS_CHUNK_MODE
10421042
typedef struct
10431043
{
10441044
struct sockaddr_storage addr;
@@ -1613,7 +1613,7 @@ pgconn_sync_describe_portal(VALUE self, VALUE stmt_name)
16131613
}
16141614

16151615

1616-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
1616+
#ifdef LIBPQ_HAS_CHUNK_MODE
16171617
/*
16181618
* call-seq:
16191619
* conn.sync_close_prepared( stmt_name ) -> PG::Result
@@ -1917,7 +1917,7 @@ pgconn_set_single_row_mode(VALUE self)
19171917
return self;
19181918
}
19191919

1920-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
1920+
#ifdef LIBPQ_HAS_CHUNK_MODE
19211921
/*
19221922
* call-seq:
19231923
* conn.set_chunked_rows_mode -> self
@@ -2232,7 +2232,7 @@ pgconn_send_describe_portal(VALUE self, VALUE portal)
22322232
"PQsendDescribePortal");
22332233
}
22342234

2235-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
2235+
#ifdef LIBPQ_HAS_CHUNK_MODE
22362236
/*
22372237
* call-seq:
22382238
* conn.send_close_prepared( statement_name ) -> nil
@@ -2358,7 +2358,7 @@ pgconn_sync_flush(VALUE self)
23582358
return (ret) ? Qfalse : Qtrue;
23592359
}
23602360

2361-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
2361+
#ifndef LIBPQ_HAS_CHUNK_MODE
23622362
static VALUE
23632363
pgconn_sync_cancel(VALUE self)
23642364
{
@@ -3657,7 +3657,7 @@ pgconn_async_describe_prepared(VALUE self, VALUE stmt_name)
36573657
return pgconn_async_describe_close_prepared_potral(self, stmt_name, pgconn_send_describe_prepared);
36583658
}
36593659

3660-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
3660+
#ifdef LIBPQ_HAS_CHUNK_MODE
36613661
/*
36623662
* call-seq:
36633663
* conn.close_prepared( statement_name ) -> PG::Result
@@ -3779,7 +3779,7 @@ pgconn_ssl_attribute_names(VALUE self)
37793779

37803780

37813781

3782-
#ifdef HAVE_PQENTERPIPELINEMODE
3782+
#ifdef LIBPQ_HAS_PIPELINING
37833783
/*
37843784
* call-seq:
37853785
* conn.pipeline_status -> Integer
@@ -3872,7 +3872,7 @@ pgconn_sync_pipeline_sync(VALUE self)
38723872
}
38733873

38743874

3875-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
3875+
#ifdef LIBPQ_HAS_CHUNK_MODE
38763876
/*
38773877
* call-seq:
38783878
* conn.send_pipeline_sync -> nil
@@ -4754,15 +4754,15 @@ init_pg_connection(void)
47544754
rb_define_method(rb_cPGconn, "transaction_status", pgconn_transaction_status, 0);
47554755
rb_define_method(rb_cPGconn, "parameter_status", pgconn_parameter_status, 1);
47564756
rb_define_method(rb_cPGconn, "protocol_version", pgconn_protocol_version, 0);
4757-
#ifdef HAVE_PQFULLPROTOCOLVERSION
4757+
#ifdef LIBPQ_HAS_FULL_PROTOCOL_VERSION
47584758
rb_define_method(rb_cPGconn, "full_protocol_version", pgconn_full_protocol_version, 0);
47594759
#endif
47604760
rb_define_method(rb_cPGconn, "server_version", pgconn_server_version, 0);
47614761
rb_define_method(rb_cPGconn, "error_message", pgconn_error_message, 0);
47624762
rb_define_method(rb_cPGconn, "socket", pgconn_socket, 0);
47634763
rb_define_method(rb_cPGconn, "socket_io", pgconn_socket_io, 0);
47644764
rb_define_method(rb_cPGconn, "backend_pid", pgconn_backend_pid, 0);
4765-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
4765+
#ifndef LIBPQ_HAS_CHUNK_MODE
47664766
rb_define_method(rb_cPGconn, "backend_key", pgconn_backend_key, 0);
47674767
#endif
47684768
rb_define_method(rb_cPGconn, "connection_needs_password", pgconn_connection_needs_password, 0);
@@ -4776,7 +4776,7 @@ init_pg_connection(void)
47764776
rb_define_method(rb_cPGconn, "sync_exec_prepared", pgconn_sync_exec_prepared, -1);
47774777
rb_define_method(rb_cPGconn, "sync_describe_prepared", pgconn_sync_describe_prepared, 1);
47784778
rb_define_method(rb_cPGconn, "sync_describe_portal", pgconn_sync_describe_portal, 1);
4779-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4779+
#ifdef LIBPQ_HAS_CHUNK_MODE
47804780
rb_define_method(rb_cPGconn, "sync_close_prepared", pgconn_sync_close_prepared, 1);
47814781
rb_define_method(rb_cPGconn, "sync_close_portal", pgconn_sync_close_portal, 1);
47824782
#endif
@@ -4787,7 +4787,7 @@ init_pg_connection(void)
47874787
rb_define_method(rb_cPGconn, "exec_prepared", pgconn_async_exec_prepared, -1);
47884788
rb_define_method(rb_cPGconn, "describe_prepared", pgconn_async_describe_prepared, 1);
47894789
rb_define_method(rb_cPGconn, "describe_portal", pgconn_async_describe_portal, 1);
4790-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4790+
#ifdef LIBPQ_HAS_CHUNK_MODE
47914791
rb_define_method(rb_cPGconn, "close_prepared", pgconn_async_close_prepared, 1);
47924792
rb_define_method(rb_cPGconn, "close_portal", pgconn_async_close_portal, 1);
47934793
#endif
@@ -4799,7 +4799,7 @@ init_pg_connection(void)
47994799
rb_define_alias(rb_cPGconn, "async_exec_prepared", "exec_prepared");
48004800
rb_define_alias(rb_cPGconn, "async_describe_prepared", "describe_prepared");
48014801
rb_define_alias(rb_cPGconn, "async_describe_portal", "describe_portal");
4802-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4802+
#ifdef LIBPQ_HAS_CHUNK_MODE
48034803
rb_define_alias(rb_cPGconn, "async_close_prepared", "close_prepared");
48044804
rb_define_alias(rb_cPGconn, "async_close_portal", "close_portal");
48054805
#endif
@@ -4812,7 +4812,7 @@ init_pg_connection(void)
48124812
rb_define_method(rb_cPGconn, "escape_bytea", pgconn_s_escape_bytea, 1);
48134813
rb_define_method(rb_cPGconn, "unescape_bytea", pgconn_s_unescape_bytea, 1);
48144814
rb_define_method(rb_cPGconn, "set_single_row_mode", pgconn_set_single_row_mode, 0);
4815-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4815+
#ifdef LIBPQ_HAS_CHUNK_MODE
48164816
rb_define_method(rb_cPGconn, "set_chunked_rows_mode", pgconn_set_chunked_rows_mode, 1);
48174817
#endif
48184818

@@ -4834,7 +4834,7 @@ init_pg_connection(void)
48344834
rb_define_method(rb_cPGconn, "discard_results", pgconn_discard_results, 0);
48354835

48364836
/****** PG::Connection INSTANCE METHODS: Cancelling Queries in Progress ******/
4837-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
4837+
#ifndef LIBPQ_HAS_CHUNK_MODE
48384838
rb_define_method(rb_cPGconn, "sync_cancel", pgconn_sync_cancel, 0);
48394839
#endif
48404840

@@ -4876,13 +4876,13 @@ init_pg_connection(void)
48764876
rb_define_method(rb_cPGconn, "ssl_attribute", pgconn_ssl_attribute, 1);
48774877
rb_define_method(rb_cPGconn, "ssl_attribute_names", pgconn_ssl_attribute_names, 0);
48784878

4879-
#ifdef HAVE_PQENTERPIPELINEMODE
4879+
#ifdef LIBPQ_HAS_PIPELINING
48804880
rb_define_method(rb_cPGconn, "pipeline_status", pgconn_pipeline_status, 0);
48814881
rb_define_method(rb_cPGconn, "enter_pipeline_mode", pgconn_enter_pipeline_mode, 0);
48824882
rb_define_method(rb_cPGconn, "exit_pipeline_mode", pgconn_exit_pipeline_mode, 0);
48834883
rb_define_method(rb_cPGconn, "sync_pipeline_sync", pgconn_sync_pipeline_sync, 0);
48844884
rb_define_method(rb_cPGconn, "send_flush_request", pgconn_send_flush_request, 0);
4885-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4885+
#ifdef LIBPQ_HAS_CHUNK_MODE
48864886
rb_define_method(rb_cPGconn, "send_pipeline_sync", pgconn_send_pipeline_sync, 0);
48874887
#endif
48884888
#endif

ext/pg_result.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,17 @@ pg_result_check( VALUE self )
315315
case PGRES_SINGLE_TUPLE:
316316
case PGRES_EMPTY_QUERY:
317317
case PGRES_COMMAND_OK:
318-
#ifdef HAVE_PQENTERPIPELINEMODE
318+
#ifdef LIBPQ_HAS_PIPELINING
319319
case PGRES_PIPELINE_SYNC:
320320
#endif
321-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
321+
#ifdef LIBPQ_HAS_CHUNK_MODE
322322
case PGRES_TUPLES_CHUNK:
323323
#endif
324324
return self;
325325
case PGRES_BAD_RESPONSE:
326326
case PGRES_FATAL_ERROR:
327327
case PGRES_NONFATAL_ERROR:
328-
#ifdef HAVE_PQENTERPIPELINEMODE
328+
#ifdef LIBPQ_HAS_PIPELINING
329329
case PGRES_PIPELINE_ABORTED:
330330
#endif
331331
error = rb_str_new2( PQresultErrorMessage(this->pgresult) );
@@ -1600,7 +1600,7 @@ pgresult_stream_any(VALUE self, int (*yielder)(VALUE, int, int, void*), void* da
16001600
return self;
16011601
rb_raise( rb_eInvalidResultStatus, "PG::Result is not in single row mode");
16021602
case PGRES_SINGLE_TUPLE:
1603-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
1603+
#ifdef LIBPQ_HAS_CHUNK_MODE
16041604
case PGRES_TUPLES_CHUNK:
16051605
#endif
16061606
break;

0 commit comments

Comments
 (0)