C++ Logo

std-proposals

Advanced search

Re: [std-proposals] "shared libraries are outside the scope of the C++ standard"

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Tue, 18 Jul 2023 09:08:44 +0100
On Thu, 2023-07-13 at 07:17 -0700, Thiago Macieira wrote:
> On Wednesday, 12 July 2023 23:37:50 PDT Lénárd Szolnoki wrote:
> > AFAIK current efforts around contracts are doubling down on this
> > design and
> > propose contract violation handlers to be replaceable function,
> > similarly
> > to to the allocation functions.
>
> Unlike the case of operator new back in pre-C++98 days, the
> developers making
> this requirement are fully aware of the limitations of Windows. It's
> a
> *conscious* choice to allow the override inside of a DLL and not
> across DLLs.
>

How does one replace operator new and other replaceable functions
within a DLL? Is it possible with only the possession of the DLL
itself, or does this require recompiling and/or relinking the library?

AFAIK one of the design goals of contracts is to allow companies to
still only release two builds: one debug and one release build, and
allow users the replace the contract violation handler for the debug
library if they want to do so. I don't know if this is possible with
replaceable functions within DLLs on Windows.

> > Also I strongly disagree for runtime replacement for allocation
> > functions in
> > the style of set_terminate() for the simple reason that new and
> > delete
> > should better come from the same allocator and and it becomes quite
> > hard to
> > guarantee if you replace allocation functions in the middle of your
> > program.
>
> Hmm... good point. It's mighty difficult to ensure that it did get
> replaced
> before any allocation because of static initialisation, and replacing
> the
> allocator after you've allocated anything is problematic too.
>

Received on 2023-07-18 08:08:53