Skip to content

Commit

Permalink
Move config check to compile time. Support assume. (#805)
Browse files Browse the repository at this point in the history
Add support for `[[assume(...)]]`.

Streamline some feature checks: ones that don't affect ABI can still happen at compile time, speeding up configure.
  • Loading branch information
jtv committed Mar 24, 2024
1 parent 1465d95 commit d7e22ac
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 101 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
7.9.1
- Move `[[likely]]` feature check back to compile time, to speed up configure.
- Support `[[assume(...)]]`.
7.9.0
- Support standard libraries without `std::basic_string<std::byte>` etc.
- `std::basic_string<std::byte` becomes `pqxx::bytes`. (#726)
Expand Down
4 changes: 0 additions & 4 deletions cmake/pqxx_cxx_feature_checks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ try_compile(
PQXX_HAVE_THREAD_LOCAL ${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/PQXX_HAVE_THREAD_LOCAL.cxx
)
try_compile(
PQXX_HAVE_UNREACHABLE ${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/PQXX_HAVE_UNREACHABLE.cxx
)
try_compile(
PQXX_HAVE_YEAR_MONTH_DAY ${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/PQXX_HAVE_YEAR_MONTH_DAY.cxx
Expand Down
11 changes: 0 additions & 11 deletions config-tests/PQXX_HAVE_UNREACHABLE.cxx

This file was deleted.

2 changes: 1 addition & 1 deletion config/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ am__can_run_installinfo = \
esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
am__DIST_COMMON = $(srcdir)/Makefile.in compile config.guess \
config.sub depcomp install-sh ltmain.sh missing mkinstalldirs
config.sub install-sh ltmain.sh missing mkinstalldirs
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
Expand Down
1 change: 0 additions & 1 deletion configitems
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ PQXX_HAVE_SSIZE public compiler
PQXX_HAVE_STRERROR_R public compiler
PQXX_HAVE_STRERROR_S public compiler
PQXX_HAVE_THREAD_LOCAL internal compiler
PQXX_HAVE_UNREACHABLE public compiler
PQXX_HAVE_YEAR_MONTH_DAY public compiler
VERSION internal autotools
68 changes: 14 additions & 54 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.71 for libpqxx 7.9.0.
# Generated by GNU Autoconf 2.71 for libpqxx 7.9.1.
#
# Report bugs to <Jeroen T. Vermeulen>.
#
Expand Down Expand Up @@ -621,8 +621,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='libpqxx'
PACKAGE_TARNAME='libpqxx'
PACKAGE_VERSION='7.9.0'
PACKAGE_STRING='libpqxx 7.9.0'
PACKAGE_VERSION='7.9.1'
PACKAGE_STRING='libpqxx 7.9.1'
PACKAGE_BUGREPORT='Jeroen T. Vermeulen'
PACKAGE_URL=''

Expand Down Expand Up @@ -1385,7 +1385,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures libpqxx 7.9.0 to adapt to many kinds of systems.
\`configure' configures libpqxx 7.9.1 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

Expand Down Expand Up @@ -1456,7 +1456,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of libpqxx 7.9.0:";;
short | recursive ) echo "Configuration of libpqxx 7.9.1:";;
esac
cat <<\_ACEOF

Expand Down Expand Up @@ -1582,7 +1582,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
libpqxx configure 7.9.0
libpqxx configure 7.9.1
generated by GNU Autoconf 2.71

Copyright (C) 2021 Free Software Foundation, Inc.
Expand Down Expand Up @@ -1957,7 +1957,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by libpqxx $as_me 7.9.0, which was
It was created by libpqxx $as_me 7.9.1, which was
generated by GNU Autoconf 2.71. Invocation command line was

$ $0$ac_configure_args_raw
Expand Down Expand Up @@ -3452,7 +3452,7 @@ fi

# Define the identity of the package.
PACKAGE='libpqxx'
VERSION='7.9.0'
VERSION='7.9.1'


printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
Expand Down Expand Up @@ -4108,11 +4108,11 @@ if test x$ac_prog_cxx_stdcxx = xno
then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5
printf %s "checking for $CXX option to enable C++11 features... " >&6; }
if test ${ac_cv_prog_cxx_11+y}
if test ${ac_cv_prog_cxx_cxx11+y}
then :
printf %s "(cached) " >&6
else $as_nop
ac_cv_prog_cxx_11=no
ac_cv_prog_cxx_cxx11=no
ac_save_CXX=$CXX
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
Expand Down Expand Up @@ -4154,11 +4154,11 @@ if test x$ac_prog_cxx_stdcxx = xno
then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5
printf %s "checking for $CXX option to enable C++98 features... " >&6; }
if test ${ac_cv_prog_cxx_98+y}
if test ${ac_cv_prog_cxx_cxx98+y}
then :
printf %s "(cached) " >&6
else $as_nop
ac_cv_prog_cxx_98=no
ac_cv_prog_cxx_cxx98=no
ac_save_CXX=$CXX
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
Expand Down Expand Up @@ -18264,46 +18264,6 @@ fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PQXX_HAVE_THREAD_LOCAL" >&5
printf "%s\n" "$PQXX_HAVE_THREAD_LOCAL" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking PQXX_HAVE_UNREACHABLE" >&5
printf %s "checking PQXX_HAVE_UNREACHABLE... " >&6; }
PQXX_HAVE_UNREACHABLE=yes
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
// Feature check for 'PQXX_HAVE_UNREACHABLE'.

// Generated by generate_cxx_checks.py.

#include <version>

#if !defined(__cpp_lib_unreachable)

# error "No PQXX_HAVE_UNREACHABLE: __cpp_lib_unreachable is not set."

#endif

#if !__cpp_lib_unreachable

# error "No PQXX_HAVE_UNREACHABLE: __cpp_lib_unreachable is false."

#endif



int main() {}


_ACEOF
if ac_fn_cxx_try_compile "$LINENO"
then :

printf "%s\n" "#define PQXX_HAVE_UNREACHABLE 1" >>confdefs.h

else $as_nop
PQXX_HAVE_UNREACHABLE=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PQXX_HAVE_UNREACHABLE" >&5
printf "%s\n" "$PQXX_HAVE_UNREACHABLE" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking PQXX_HAVE_YEAR_MONTH_DAY" >&5
printf %s "checking PQXX_HAVE_YEAR_MONTH_DAY... " >&6; }
PQXX_HAVE_YEAR_MONTH_DAY=yes
Expand Down Expand Up @@ -19546,7 +19506,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by libpqxx $as_me 7.9.0, which was
This file was extended by libpqxx $as_me 7.9.1, which was
generated by GNU Autoconf 2.71. Invocation command line was

CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -19614,7 +19574,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
libpqxx config.status 7.9.0
libpqxx config.status 7.9.1
configured by $0, generated by GNU Autoconf 2.71,
with options \\"\$ac_cs_config\\"

Expand Down
1 change: 0 additions & 1 deletion cxx_features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ PQXX_HAVE_MULTIDIM __cpp_multidimensional_subscript
PQXX_HAVE_SOURCE_LOCATION __cpp_lib_source_location
PQXX_HAVE_SPAN __cpp_lib_span
PQXX_HAVE_SSIZE __cpp_lib_ssize
PQXX_HAVE_UNREACHABLE __cpp_lib_unreachable
10 changes: 6 additions & 4 deletions include/pqxx/array.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ private:
case group::SJIS: parse<group::SJIS>(data); break;
case group::UHC: parse<group::UHC>(data); break;
case group::UTF8: parse<group::UTF8>(data); break;
default: PQXX_UNREACHABLE; break;
}
}

Expand Down Expand Up @@ -301,14 +302,12 @@ private:
std::size_t dim{outer};

// Extent counters, one per "real" dimension.
// Note initialiser syntax; this should zero-initialise all elements.
// Note initialiser syntax; this zero-initialises all elements.
std::array<std::size_t, DIMENSIONS> extents{};
#if !defined(NDEBUG)
for (auto const e : extents) assert(e == 0u);
#endif

// Current parsing position.
std::size_t here{0};
PQXX_ASSUME(here <= sz);
while (here < sz)
{
if (data[here] == '{')
Expand All @@ -321,6 +320,7 @@ private:
"Array text representation closed and reopened its outside "
"brace pair."};
assert(here == 0);
PQXX_ASSUME(here == 0);
}
else
{
Expand Down Expand Up @@ -412,13 +412,15 @@ private:
}
}
here = end;
PQXX_ASSUME(here <= sz);
here = parse_field_end(data, here);
}
}

if (dim != outer)
throw conversion_error{"Malformed array; may be truncated."};
assert(know_extents_from == 0);
PQXX_ASSUME(know_extents_from == 0);

init_factors();
}
Expand Down
3 changes: 0 additions & 3 deletions include/pqxx/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@
/* Define if this feature is available. */
#undef PQXX_HAVE_THREAD_LOCAL

/* Define if this feature is available. */
#undef PQXX_HAVE_UNREACHABLE

/* Define if this feature is available. */
#undef PQXX_HAVE_YEAR_MONTH_DAY

Expand Down
2 changes: 1 addition & 1 deletion include/pqxx/doc/mainpage.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
libpqxx {#mainpage}
=======

@version 7.9.0
@version 7.9.1
@author Jeroen T. Vermeulen
@see http://pqxx.org
@see https://github.com/jtv/libpqxx
Expand Down
7 changes: 4 additions & 3 deletions include/pqxx/field.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,13 @@ public:
* @param c Column number of this field.
*/
[[deprecated(
"Do not construct fields yourself. Get them from the row.")]] field(row const &r, row_size_type c) noexcept;
"Do not construct fields yourself. Get them from the row.")]]
field(row const &r, row_size_type c) noexcept;

/// Constructor. Do not call this yourself; libpqxx will do it for you.
[[deprecated(
"Do not construct fields yourself. Get them from the "
"row.")]] field() noexcept = default;
"Do not construct fields yourself. Get them from the row.")]]
field() noexcept = default;


protected:
Expand Down
14 changes: 14 additions & 0 deletions include/pqxx/internal/array-composite.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ inline std::size_t scan_double_quoted_string(
// TODO: find_char<'"', '\\'>().
using scanner = glyph_scanner<ENC>;
auto next{scanner::call(input, size, pos)};
PQXX_ASSUME(next > pos);
bool at_quote{false};
pos = next;
next = scanner::call(input, size, pos);
PQXX_ASSUME(next > pos);
while (pos < size)
{
if (at_quote)
Expand All @@ -51,6 +53,7 @@ inline std::size_t scan_double_quoted_string(
// Backslash escape. Skip ahead by one more character.
pos = next;
next = scanner::call(input, size, pos);
PQXX_ASSUME(next > pos);
break;

case '"':
Expand All @@ -66,6 +69,7 @@ inline std::size_t scan_double_quoted_string(
}
pos = next;
next = scanner::call(input, size, pos);
PQXX_ASSUME(next > pos);
}
if (not at_quote)
throw argument_error{
Expand All @@ -90,6 +94,8 @@ inline std::string parse_double_quoted_string(
using scanner = glyph_scanner<ENC>;
auto here{scanner::call(input, end, pos)},
next{scanner::call(input, end, here)};
PQXX_ASSUME(here > pos);
PQXX_ASSUME(next > here);
while (here < end - 1)
{
// A backslash here is always an escape. So is a double-quote, since we're
Expand All @@ -101,10 +107,12 @@ inline std::string parse_double_quoted_string(
// Skip escape.
here = next;
next = scanner::call(input, end, here);
PQXX_ASSUME(next > here);
}
output.append(input + here, input + next);
here = next;
next = scanner::call(input, end, here);
PQXX_ASSUME(next > here);
}
return output;
}
Expand All @@ -124,10 +132,12 @@ scan_unquoted_string(char const input[], std::size_t size, std::size_t pos)
{
using scanner = glyph_scanner<ENC>;
auto next{scanner::call(input, size, pos)};
PQXX_ASSUME(next > pos);
while ((pos < size) and ((next - pos) > 1 or ((input[pos] != STOP) and ...)))
{
pos = next;
next = scanner::call(input, size, pos);
PQXX_ASSUME(next > pos);
}
return pos;
}
Expand Down Expand Up @@ -174,6 +184,7 @@ inline void parse_composite_field(
{
assert(index <= last_field);
auto next{glyph_scanner<ENC>::call(std::data(input), std::size(input), pos)};
PQXX_ASSUME(next > pos);
if ((next - pos) != 1)
throw conversion_error{"Non-ASCII character in composite-type syntax."};

Expand All @@ -195,6 +206,7 @@ inline void parse_composite_field(
case '"': {
auto const stop{
scan_double_quoted_string<ENC>(std::data(input), std::size(input), pos)};
PQXX_ASSUME(stop > pos);
auto const text{
parse_double_quoted_string<ENC>(std::data(input), stop, pos)};
field = from_string<T>(text);
Expand All @@ -205,6 +217,7 @@ inline void parse_composite_field(
default: {
auto const stop{scan_unquoted_string<ENC, ',', ')', ']'>(
std::data(input), std::size(input), pos)};
PQXX_ASSUME(stop >= pos);
field =
from_string<T>(std::string_view{std::data(input) + pos, stop - pos});
pos = stop;
Expand All @@ -214,6 +227,7 @@ inline void parse_composite_field(

// Expect a comma or a closing parenthesis.
next = glyph_scanner<ENC>::call(std::data(input), std::size(input), pos);
PQXX_ASSUME(next > pos);

if ((next - pos) != 1)
throw conversion_error{
Expand Down
4 changes: 3 additions & 1 deletion include/pqxx/internal/concat.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace pqxx::internal
template<typename TYPE>
void render_item(TYPE const &item, char *&here, char *end)
{
here = string_traits<TYPE>::into_buf(here, end, item) - 1;
auto const next = string_traits<TYPE>::into_buf(here, end, item) - 1;
PQXX_ASSUME(next >= here);
here = next;
}


Expand Down

0 comments on commit d7e22ac

Please sign in to comment.