C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A drift for c++ decorators;

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 27 Oct 2024 16:01:07 -0700
On Sunday 27 October 2024 15:41:26 Pacific Daylight Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> Next let's say we have a variable called 'obj' of type 'MyClass', and
> we want to tweak this object so that every invocation of any of its
> methods gets intercepted (we want to lock a mutex before the call, and
> unlock the mutex after the call). Well. . . here's what you could do:
> (1) Copy the MyClass VTable
> (2) Edit the copied VTable so that each function pointer is replaced
> with a pointer to an interceptor
> (3) Write the machine code for each interceptor into a buffer of
> executable memory
> (4) Change the VTable pointer inside the object 'obj'

How about using reflection?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2024-10-27 23:01:13