Philipp Stephani wrote:
> the Windows API uses this approach extensively
> for version checking, and has been forward- and backward-compatible fo=
r
> decades with it.
This sort of approach might work in the MS-Windows world, which has a singl=
e
dominant supplier.=C2=A0 It's not clear that it would work in the GNU/L=
inux world,
where different suppliers have different ABIs.=C2=A0 And even if one takes =
exactly
the same Emacs source and module source and runs on the same operating syst=
em,
one can easily build Emacs executables that won't interoperate with mod=
ules,
simply by using different compiler flags.
D=
o you refer to different structure layouts due to padding differences? That=
would need to be ruled out somehow, maybe by making the padding explicit i=
n emacs-module.h.
I also don't see how version checks should =
be able to protect against this. If a module expects a structure member at =
a certain offset, it has to be placed at that offset. There is no way in C =
how to check for that at runtime.
=C2=A0
=C2=A0 The sizes might match, but the code
won't.=C2=A0 So I don't think sizes will suffice, at least, not out=
side of MS-Windows.
I honestly can't think of a situat=
ion where version checking would work but size checking wouldn't. Given=
that users will use modules compiled with arbitrary versions of emacs-modu=
le.h together with arbitrary Emacsen, the following compatibility constrain=
ts have to be fulfilled:
- Types of structure members may n=
ever change.
- Structure members may never be reordered.
- Stru=
cture members may never be removed.
- New structure members can only =
be added at the end.
Otherwise we'd need to export differ=
ent versions of the structures and module authors would have to pick the co=
rrect version at runtime, which is more error-prone. Given these constraint=
s, version number checks are equivalent to size checks. This isn't real=
ly related to Windows; these are ABI compatibility constraints that always =
occur when passing structures.
=C2=A0
Daniel's message pointed to JNI for an inspiration. JNI uses version nu=
mbers
here (its GetVersion method), not sizes, I assume partly for the reasons
discussed above. Shouldn't we do the same?=C2=A0
<=
/div>
Not necessarily. Daniel had good reasons to deviate from the JNI =
design in this respect: size checks are simpler and less error-prone becaus=
e users don't need to remember or look up which member is present in wh=
ich version.=C2=A0