Skip to content

Commit

Permalink
Pass std::source_location into libpqxx functions. (#947)
Browse files Browse the repository at this point in the history
I'm trying to ensure that every libpqxx function that may throw an exception has a `source_location` parameter, and that it passes this to any functions it calls that may throw.

The end result would ideally be that any exception thrown by libpqxx would include the location of the original call into libpqxx.  (Unless you pass your own choice of source location, of course).

In practice, this ideal is not quite attainable...
* Parameter packs make it hard — you can't just make a function accept any number of arguments of any type, and then add a `source_location` parameter _after_ that.
* With overloaded operators it's completely impossible — there's no way of adding parameters to a function with a fixed, language-dictated signature.
* Destructors take no arguments at all, so they're out as well.
* Callbacks and string conversions are a problem as well, because their existing definitions don't include `source_location`.

I do have a plan for that last item though.  I can probably update the signatures and use compile-time introspection (probably using function concepts) to detect whether the given user-defined function supports the old API or the new API.  That's a separate job though.

Oh, and because I don't want to grow all my function signatures with an additional tedious `std::source_location location = std::source_location::current()` etc, I created a type alias `sl`.  Hate how cryptic this makes the functions, but I really need these to be brief.
  • Loading branch information
jtv authored Feb 15, 2025
1 parent f887ca5 commit 7e1434e
Show file tree
Hide file tree
Showing 76 changed files with 2,065 additions and 1,567 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Conversion from string to `char const *` is no longer allowed.
- Binary data can be any `std::contiguous_range` of `std::byte`. (#925)
- Generic `quote()` takes `always_null` into account.
- The libpqxx exceptions now have a `std::source_location`.
- More getters are now `noexcept`.
- Retired `binarystring` and its headers. Use `blob` instead.
- Retired `connection_base` type alias. Use `connection`.
- Retired `pqxx::encrypt_password()`. Use the ones in `pqxx::connection`.
Expand All @@ -21,6 +23,7 @@
- Assume compiler supports `std::filesystem::path`.
- Assume compiler supports `[[likely]]` & `[[unlikely]]`.
- Assume compiler supports `ssize()`.
- Assume compiler supports `std::source_location`.
- Assume compiler supports ISO-646 without needing `<ciso646>` header.
7.10.1
- Fix string conversion buffer budget for arrays containing nulls. (#921)
Expand Down
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 install-sh ltmain.sh missing mkinstalldirs
config.sub depcomp install-sh ltmain.sh missing mkinstalldirs
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
Expand Down
Loading

0 comments on commit 7e1434e

Please sign in to comment.