sizeof(JSRuntime) != sizeof(JSRuntime)

RESOLVED DUPLICATE of bug 677079

Status

()

RESOLVED DUPLICATE of bug 677079
7 years ago
7 years ago

People

(Reporter: njn, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

7 years ago
sizeof(JSRuntime) is larger in the JS engine than it is in XPConnect, for debug builds at least.  The difference is that the JS engine includes the |gcData| field.  So XPConnect isn't seeing MOZ_GCTIMER and/or JSGC_TESTPILOT defined.  

It's not causing a problem in practice because |gcData| is the last field in JSRuntime.

We should fix this particular case, but it would be even better if this was impossible.
(Reporter)

Updated

7 years ago
Assignee: nnethercote → general
(Reporter)

Comment 1

7 years ago
W.r.t. making this impossible:  I can see how to do it just for JSRuntime -- have a member in JSRuntime like this:

  static const size_t sizeOfMe = sizeof(JSRuntime);

and then assert at XPConnect that sizeOfMe == sizeof(JSRuntime) when the JSRuntime is created.

But it would be better to have something that is a full guarantee for all types.  That would require a guarantee that the JS engine and XPConnect are being compiled with the same #defines, so I guess that would have to be done at the level of the build system.
(In reply to Nicholas Nethercote [:njn] from comment #1)
> W.r.t. making this impossible:  I can see how to do it just for JSRuntime --
> have a member in JSRuntime like this:
> 
>   static const size_t sizeOfMe = sizeof(JSRuntime);
> 
> and then assert at XPConnect that sizeOfMe == sizeof(JSRuntime) when the
> JSRuntime is created.

That's ... tricky.  And even a size comparison won't catch everything.

> But it would be better to have something that is a full guarantee for all
> types.  That would require a guarantee that the JS engine and XPConnect are
> being compiled with the same #defines, so I guess that would have to be done
> at the level of the build system.

I'm not sure that there's any good solution to struct definitions being different in different translation units.  I think it's just one of those hazards of C/C++.

That said, if this particular case is important enough, we can rig up something that at least gets the size checked.

Comment 3

7 years ago
Fixing the immediate problem is good.  I think the real fix is bug 677079.  I'm sure waldo wouldn't mind if you stole it from him :)
(Reporter)

Updated

7 years ago
Status: ASSIGNED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 677079
You need to log in before you can comment on or make changes to this bug.