Re: Proposal for Prototype Implementation to Enhance C/C++ Interoperability in PostgreSQL

From: 盏一 <w(at)hidva(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposal for Prototype Implementation to Enhance C/C++ Interoperability in PostgreSQL
Date: 2023-05-08 02:56:51
Message-ID: tencent_5E4A400F23994D0D5C93CAE7@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

(Sorry, there was a problem with the format of the previous email content. I will send it in plain text format this time

> It seems extremely specific to one particular C++ implementation

To perform a force unwind during longjmp, the _Unwind_ForcedUnwind function is used. This function is defined in the [Itanium C++ ABI Standard](https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#base-throw), which is followed by all C++ implementations. Additionally, the glibc [nptl/unwind.c](https://elixir.bootlin.com/glibc/latest/source/nptl/unwind.c#L130) file shows that on all platforms, pthread_exit is also implemented using _Unwind_ForcedUnwind.

Furthermore, the Itanium C++ ABI specification also defines _Unwind_RaiseException as the entry point for all C++ exceptions thrown.

> you've thrown in a new dependency on pthreads

The reason for the dependence on pthread is due to the overloading of _Unwind_RaiseException, which serves as the entry point for all C++ throwing exceptions. Some third-party C++ libraries may create threads internally and throw exceptions.

Overloading _Unwind_RaiseException is done to convert uncaught exceptions into elog(ERROR). If we require that all exceptions must be caught, we can remove the overloading of _Unwind_RaiseException and all pthread dependencies.

The overloading of _Unwind_RaiseException is just a fallback measure to prevent uncaught exceptions from terminating the process. In our code, this path is rarely taken, and once we encounter an exception that is not caught, we will fix the code to catch the exception.

> doesn't this require us to move our minimum language requirement to C++-something?

No, all code has no dependency on C++.

regards, 盏一

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2023-05-08 03:07:35 Re: [DOC] Update ALTER SUBSCRIPTION documentation
Previous Message Amit Kapila 2023-05-08 02:42:12 Re: Add two missing tests in 035_standby_logical_decoding.pl