Skip to content

Commit 59166ca

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 avialable 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 01aa282 commit 59166ca

File tree

7 files changed

+28
-33
lines changed

7 files changed

+28
-33
lines changed

ext/extconf.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +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
319314
have_func 'timegm'
320315
have_func 'rb_io_wait' # since ruby-3.0
321316
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: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ pgconn_backend_pid(VALUE self)
10131013
return INT2NUM(PQbackendPID(pg_get_pgconn(self)));
10141014
}
10151015

1016-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
1016+
#ifndef LIBPQ_HAS_CHUNK_MODE
10171017
typedef struct
10181018
{
10191019
struct sockaddr_storage addr;
@@ -1588,7 +1588,7 @@ pgconn_sync_describe_portal(VALUE self, VALUE stmt_name)
15881588
}
15891589

15901590

1591-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
1591+
#ifdef LIBPQ_HAS_CHUNK_MODE
15921592
/*
15931593
* call-seq:
15941594
* conn.sync_close_prepared( stmt_name ) -> PG::Result
@@ -1892,7 +1892,7 @@ pgconn_set_single_row_mode(VALUE self)
18921892
return self;
18931893
}
18941894

1895-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
1895+
#ifdef LIBPQ_HAS_CHUNK_MODE
18961896
/*
18971897
* call-seq:
18981898
* conn.set_chunked_rows_mode -> self
@@ -2207,7 +2207,7 @@ pgconn_send_describe_portal(VALUE self, VALUE portal)
22072207
"PQsendDescribePortal");
22082208
}
22092209

2210-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
2210+
#ifdef LIBPQ_HAS_CHUNK_MODE
22112211
/*
22122212
* call-seq:
22132213
* conn.send_close_prepared( statement_name ) -> nil
@@ -2333,7 +2333,7 @@ pgconn_sync_flush(VALUE self)
23332333
return (ret) ? Qfalse : Qtrue;
23342334
}
23352335

2336-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
2336+
#ifndef LIBPQ_HAS_CHUNK_MODE
23372337
static VALUE
23382338
pgconn_sync_cancel(VALUE self)
23392339
{
@@ -3632,7 +3632,7 @@ pgconn_async_describe_prepared(VALUE self, VALUE stmt_name)
36323632
return pgconn_async_describe_close_prepared_potral(self, stmt_name, pgconn_send_describe_prepared);
36333633
}
36343634

3635-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
3635+
#ifdef LIBPQ_HAS_CHUNK_MODE
36363636
/*
36373637
* call-seq:
36383638
* conn.close_prepared( statement_name ) -> PG::Result
@@ -3754,7 +3754,7 @@ pgconn_ssl_attribute_names(VALUE self)
37543754

37553755

37563756

3757-
#ifdef HAVE_PQENTERPIPELINEMODE
3757+
#ifdef LIBPQ_HAS_PIPELINING
37583758
/*
37593759
* call-seq:
37603760
* conn.pipeline_status -> Integer
@@ -3847,7 +3847,7 @@ pgconn_sync_pipeline_sync(VALUE self)
38473847
}
38483848

38493849

3850-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
3850+
#ifdef LIBPQ_HAS_CHUNK_MODE
38513851
/*
38523852
* call-seq:
38533853
* conn.send_pipeline_sync -> nil
@@ -4738,7 +4738,7 @@ init_pg_connection(void)
47384738
rb_define_method(rb_cPGconn, "socket", pgconn_socket, 0);
47394739
rb_define_method(rb_cPGconn, "socket_io", pgconn_socket_io, 0);
47404740
rb_define_method(rb_cPGconn, "backend_pid", pgconn_backend_pid, 0);
4741-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
4741+
#ifndef LIBPQ_HAS_CHUNK_MODE
47424742
rb_define_method(rb_cPGconn, "backend_key", pgconn_backend_key, 0);
47434743
#endif
47444744
rb_define_method(rb_cPGconn, "connection_needs_password", pgconn_connection_needs_password, 0);
@@ -4752,7 +4752,7 @@ init_pg_connection(void)
47524752
rb_define_method(rb_cPGconn, "sync_exec_prepared", pgconn_sync_exec_prepared, -1);
47534753
rb_define_method(rb_cPGconn, "sync_describe_prepared", pgconn_sync_describe_prepared, 1);
47544754
rb_define_method(rb_cPGconn, "sync_describe_portal", pgconn_sync_describe_portal, 1);
4755-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4755+
#ifdef LIBPQ_HAS_CHUNK_MODE
47564756
rb_define_method(rb_cPGconn, "sync_close_prepared", pgconn_sync_close_prepared, 1);
47574757
rb_define_method(rb_cPGconn, "sync_close_portal", pgconn_sync_close_portal, 1);
47584758
#endif
@@ -4763,7 +4763,7 @@ init_pg_connection(void)
47634763
rb_define_method(rb_cPGconn, "exec_prepared", pgconn_async_exec_prepared, -1);
47644764
rb_define_method(rb_cPGconn, "describe_prepared", pgconn_async_describe_prepared, 1);
47654765
rb_define_method(rb_cPGconn, "describe_portal", pgconn_async_describe_portal, 1);
4766-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4766+
#ifdef LIBPQ_HAS_CHUNK_MODE
47674767
rb_define_method(rb_cPGconn, "close_prepared", pgconn_async_close_prepared, 1);
47684768
rb_define_method(rb_cPGconn, "close_portal", pgconn_async_close_portal, 1);
47694769
#endif
@@ -4775,7 +4775,7 @@ init_pg_connection(void)
47754775
rb_define_alias(rb_cPGconn, "async_exec_prepared", "exec_prepared");
47764776
rb_define_alias(rb_cPGconn, "async_describe_prepared", "describe_prepared");
47774777
rb_define_alias(rb_cPGconn, "async_describe_portal", "describe_portal");
4778-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4778+
#ifdef LIBPQ_HAS_CHUNK_MODE
47794779
rb_define_alias(rb_cPGconn, "async_close_prepared", "close_prepared");
47804780
rb_define_alias(rb_cPGconn, "async_close_portal", "close_portal");
47814781
#endif
@@ -4788,7 +4788,7 @@ init_pg_connection(void)
47884788
rb_define_method(rb_cPGconn, "escape_bytea", pgconn_s_escape_bytea, 1);
47894789
rb_define_method(rb_cPGconn, "unescape_bytea", pgconn_s_unescape_bytea, 1);
47904790
rb_define_method(rb_cPGconn, "set_single_row_mode", pgconn_set_single_row_mode, 0);
4791-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4791+
#ifdef LIBPQ_HAS_CHUNK_MODE
47924792
rb_define_method(rb_cPGconn, "set_chunked_rows_mode", pgconn_set_chunked_rows_mode, 1);
47934793
#endif
47944794

@@ -4810,7 +4810,7 @@ init_pg_connection(void)
48104810
rb_define_method(rb_cPGconn, "discard_results", pgconn_discard_results, 0);
48114811

48124812
/****** PG::Connection INSTANCE METHODS: Cancelling Queries in Progress ******/
4813-
#ifndef HAVE_PQSETCHUNKEDROWSMODE
4813+
#ifndef LIBPQ_HAS_CHUNK_MODE
48144814
rb_define_method(rb_cPGconn, "sync_cancel", pgconn_sync_cancel, 0);
48154815
#endif
48164816

@@ -4852,13 +4852,13 @@ init_pg_connection(void)
48524852
rb_define_method(rb_cPGconn, "ssl_attribute", pgconn_ssl_attribute, 1);
48534853
rb_define_method(rb_cPGconn, "ssl_attribute_names", pgconn_ssl_attribute_names, 0);
48544854

4855-
#ifdef HAVE_PQENTERPIPELINEMODE
4855+
#ifdef LIBPQ_HAS_PIPELINING
48564856
rb_define_method(rb_cPGconn, "pipeline_status", pgconn_pipeline_status, 0);
48574857
rb_define_method(rb_cPGconn, "enter_pipeline_mode", pgconn_enter_pipeline_mode, 0);
48584858
rb_define_method(rb_cPGconn, "exit_pipeline_mode", pgconn_exit_pipeline_mode, 0);
48594859
rb_define_method(rb_cPGconn, "sync_pipeline_sync", pgconn_sync_pipeline_sync, 0);
48604860
rb_define_method(rb_cPGconn, "send_flush_request", pgconn_send_flush_request, 0);
4861-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
4861+
#ifdef LIBPQ_HAS_CHUNK_MODE
48624862
rb_define_method(rb_cPGconn, "send_pipeline_sync", pgconn_send_pipeline_sync, 0);
48634863
#endif
48644864
#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) );
@@ -1579,7 +1579,7 @@ pgresult_stream_any(VALUE self, int (*yielder)(VALUE, int, int, void*), void* da
15791579
return self;
15801580
rb_raise( rb_eInvalidResultStatus, "PG::Result is not in single row mode");
15811581
case PGRES_SINGLE_TUPLE:
1582-
#ifdef HAVE_PQSETCHUNKEDROWSMODE
1582+
#ifdef LIBPQ_HAS_CHUNK_MODE
15831583
case PGRES_TUPLES_CHUNK:
15841584
#endif
15851585
break;

0 commit comments

Comments
 (0)