[Vm-dev] socketRecordSize is probably not 64-bit friendly
David T. Lewis
lewis at mail.msen.com
Sun Mar 22 18:30:01 UTC 2015
On Sun, Mar 22, 2015 at 01:58:05PM -0400, David T. Lewis wrote:
>
> On Sun, Mar 22, 2015 at 05:04:12PM +0100, Nicolas Cellier wrote:
> >
> > Hi,
> > I noticed that SocketPlugin>>socketRecordSize was so defined:
> > socketRecordSize
> > "Return the size of a Smalltalk socket record in bytes."
> >
> > ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]
> >
> >
> > Shouldn't it have been like its brothers in OSProcessPlugin and AioPlugin:
> >
> > socketRecordSize
> > "Return the size of a Smalltalk socket record in bytes."
> >
> > ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk wordSize * 3]
> >
> >
> > I presume we don't use self sizeof: because the Smalltalk side does not
> > have any idea of what a SQSocket is... (an opaque struct/handle)
>
> On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits. I would
> have expected it to be 12 for the 32-bit case, but maybe the compiler is
> aligning it differently for some reason.
>
> In any case, "Smalltalk wordSize * 3" would not be right, because the
> actual data structure is this:
>
> typedef struct
> {
> int sessionID;
> int socketType; /* 0 = TCP, 1 = UDP */
> void *privateSocketPtr;
> } SQSocket, *SocketPtr;
>
>
> In order to cover the common cases, it might be best to just change
> the implementation to this:
>
> ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [16]
Forgive me, I just realized that I was accidentally running a 64-bit
VM when I thought it was a 32-bit VM. So the size of a SQSocket will
typically be 12 bytes on a 32-bit host, and 16 bytes on a 64-bit host,
regardless of whether the image word size is 32-bit or 64-bit.
Dave
More information about the Vm-dev
mailing list