Date: Thu, 7 Nov 2024 11:08:32 +0000
On Thu, Nov 7, 2024 at 10:35 AM Giuseppe D'Angelo wrote:
>
> > (2) It's possible for two classes to have identical layout but to
> > still have differing and incompatible implementations.
>
> Bingo. Say that your magic function tells you that vector<int> is made
> up of 3 pointer-sized fields. What are they?
>
> * begin, end, capacity
> * begin, end, pointer to physical end
> * begin, size, capacity
> * begin, size, pointer to metadata/bookkeeping
> ...
>
>
> And even if they match, who tells you they're used in a consistent way?
>
> You need something *beyond* C++ to deal with ABI incompatibilities and
> with the unsafety of plugin loading in general.
Maybe I'm going off into fairytale land with it here, but we could
compute a hash sum for all of the members, so for example let's say
the class is:
class Monkey {
int n;
char *p;
void DoSomething(void);
};
Then you would take the names of all of the members, i.e. n + p +
DoSomething, and you concatenate them to give the string:
"npDoSomething"
and then you feed that into a hash algorithm such as sha256 to give a
256-Bit digest. So then you compare the two digests to see if you're
dealing with the same implementations.
>
> > (2) It's possible for two classes to have identical layout but to
> > still have differing and incompatible implementations.
>
> Bingo. Say that your magic function tells you that vector<int> is made
> up of 3 pointer-sized fields. What are they?
>
> * begin, end, capacity
> * begin, end, pointer to physical end
> * begin, size, capacity
> * begin, size, pointer to metadata/bookkeeping
> ...
>
>
> And even if they match, who tells you they're used in a consistent way?
>
> You need something *beyond* C++ to deal with ABI incompatibilities and
> with the unsafety of plugin loading in general.
Maybe I'm going off into fairytale land with it here, but we could
compute a hash sum for all of the members, so for example let's say
the class is:
class Monkey {
int n;
char *p;
void DoSomething(void);
};
Then you would take the names of all of the members, i.e. n + p +
DoSomething, and you concatenate them to give the string:
"npDoSomething"
and then you feed that into a hash algorithm such as sha256 to give a
256-Bit digest. So then you compare the two digests to see if you're
dealing with the same implementations.
Received on 2024-11-07 11:08:40