Browse Source

MoonchildProductions#1251 - Part 8: Align pointer for char_16t.

https://bugzilla.mozilla.org/show_bug.cgi?id=1352449

Mozilla patch that's been in the code since Firefox 55. Seems like there have been no ill effects from implementing it, and it would only increase the portability of the UXP code. All the Solaris Firefox repos I've seen implement some variation on the jsexn patch, and this seems to be the cleanest version of it.

I can add ifdefs if needed or there are performance concerns associated with this patch, but I get the impression this alignment backlog issue might affect a few platforms other than Solaris, though none were named. Otherwise I think they wouldn't have used "platforms that need it" in plural form or failed to ifdef it.
pull/24/head
athenian200 3 years ago committed by Roy Tam
parent
commit
d145b6b6fd
  1. 19
      js/src/jsexn.cpp

19
js/src/jsexn.cpp

@ -205,7 +205,12 @@ size_t
ExtraMallocSize(JSErrorReport* report)
{
if (report->linebuf())
return (report->linebufLength() + 1) * sizeof(char16_t);
/*
* Mozilla bug 1352449. Count with null
* terminator and alignment. See CopyExtraData for
* the details about alignment.
*/
return (report->linebufLength() + 1) * sizeof(char16_t) + 1;
return 0;
}
@ -220,10 +225,20 @@ bool
CopyExtraData(JSContext* cx, uint8_t** cursor, JSErrorReport* copy, JSErrorReport* report)
{
if (report->linebuf()) {
/*
* Make sure cursor is properly aligned for char16_t for platforms
* which need it and it's at the end of the buffer on exit.
*/
size_t alignment_backlog = 0;
if (size_t(*cursor) % 2)
(*cursor)++;
else
alignment_backlog = 1;
size_t linebufSize = (report->linebufLength() + 1) * sizeof(char16_t);
const char16_t* linebufCopy = (const char16_t*)(*cursor);
js_memcpy(*cursor, report->linebuf(), linebufSize);
*cursor += linebufSize;
*cursor += linebufSize + alignment_backlog;
copy->initBorrowedLinebuf(linebufCopy, report->linebufLength(), report->tokenOffset());
}

Loading…
Cancel
Save