Closed
Bug 243484
Opened 21 years ago
Closed 21 years ago
Add PRUint32 length out param to ToNewUTF8String() and UTF8ToNewUnicode()
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
People
(Reporter: jst, Assigned: jst)
Details
(Keywords: fixed-aviary1.0, fixed1.7.5)
Attachments
(3 files, 1 obsolete file)
5.03 KB,
patch
|
dbaron
:
review+
darin.moz
:
superreview+
|
Details | Diff | Splinter Review |
Make XPConnect use UTF8ToNewUnicode() now that it can w/o doing extra work to get the string length.
1.75 KB,
patch
|
darin.moz
:
review+
darin.moz
:
superreview+
|
Details | Diff | Splinter Review |
16.14 KB,
patch
|
peterv
:
review+
peterv
:
superreview+
|
Details | Diff | Splinter Review |
Right now it's impossible to create a new UTF-8 string (char *) from a UTF-16
string and know the length of the resulting UTF-8 string w/o extra work. Same
goes for going the other way. This could be solved by adding a versions of
ToNewUTF8String() and UTF8ToNewUnicode() that take a PRUint32 out param that
gets the length of the result. Patch coming up.
Assignee | ||
Comment 1•21 years ago
|
||
This essentially adds new methods that take the out param, and makes the
methods with the old signature inline, calling the new methods with a null out
param.
Assignee | ||
Updated•21 years ago
|
Attachment #148381 -
Flags: superreview?(darin)
Attachment #148381 -
Flags: review?(dbaron)
Comment 2•21 years ago
|
||
Comment on attachment 148381 [details] [diff] [review]
Add PRUint32 out params.
nit: you say that these extra return values give character counts, but in
reality they specify the number of storage units returned. i.e., the number of
bytes in the case of aUTF8Count, and the number of double-bytes in the case of
aUTF16Count.
otherwise, it looks good to me.
i presume that you are thinking of places where this extra argument would be
especially handy, right?
sr=darin with that comment change (and assuming dbaron is happy)
Attachment #148381 -
Flags: superreview?(darin) → superreview+
Comment on attachment 148381 [details] [diff] [review]
Add PRUint32 out params.
The comments definitely need to be fixed, as darin said. But also, why not use
default params rather than extra inline methods?
Assignee | ||
Comment 4•21 years ago
|
||
I initially did that, but that'll change the signature of the methods, so
external libraries compiled with current XPCOM won't like XPCOM after this
change lands. If we don't care about that, I'm happy to change to default
parameters.
The comment now talks about "8-bit code units" and "16-bit code units", taken
from the CopyUnicodeTo() comments. Good enough?
Comment 5•21 years ago
|
||
(In reply to comment #4)
> I initially did that, but that'll change the signature of the methods, so
> external libraries compiled with current XPCOM won't like XPCOM after this
> change lands. If we don't care about that, I'm happy to change to default
> parameters.
changing the signature of the methods is probably a good thing...
consider what happens if these methods are called without anything passed for
the second argument. then our new functions will possibly dereference a random
address and assign to that address (assuming the random value passed in is not 0).
> The comment now talks about "8-bit code units" and "16-bit code units", taken
> from the CopyUnicodeTo() comments. Good enough?
yeah, sounds good. "storage units" is also used in other places.
Comment 6•21 years ago
|
||
also, these are not frozen functions :-)
How does this patch not change the signature of the methods?
Assignee | ||
Comment 8•21 years ago
|
||
With this patch char *ToNewUTF8String(const nsAString& aSource) still exists,
with it's old signature. Doesn't NS_COM force it to be available as a non-inline
method in XPCOM?
If not, then I'll just change the signature and call it a day.
Comment 9•21 years ago
|
||
ok, mixing inline with NS_COM is a bad idea :)
i think the cold medicine is getting to me.... thanks dbaron!
Assignee | ||
Comment 10•21 years ago
|
||
Ok, I'm on crack. New patch coming up.
Assignee | ||
Comment 11•21 years ago
|
||
Attachment #148381 -
Attachment is obsolete: true
Assignee | ||
Updated•21 years ago
|
Attachment #148393 -
Flags: superreview?(darin)
Attachment #148393 -
Flags: review?(dbaron)
Assignee | ||
Updated•21 years ago
|
Attachment #148381 -
Flags: superreview+
Attachment #148381 -
Flags: review?(dbaron)
Comment on attachment 148393 [details] [diff] [review]
Use default arguments, no more inlines
r=dbaron, although I probably prefer just "units" to "code units"
Attachment #148393 -
Flags: review?(dbaron) → review+
Updated•21 years ago
|
Attachment #148393 -
Flags: superreview?(darin) → superreview+
Assignee | ||
Comment 13•21 years ago
|
||
Fix checked in. I've got a patch to make XPConnect use this too, I'll roll that
in here as well.
Assignee | ||
Comment 14•21 years ago
|
||
Assignee | ||
Updated•21 years ago
|
Attachment #148440 -
Flags: superreview?(darin)
Attachment #148440 -
Flags: review?(darin)
Assignee | ||
Updated•21 years ago
|
Attachment #148440 -
Attachment description: Make XPConnect use UTF8ToNewUnicode() now that it can w/o doing extra work to the the string length. → Make XPConnect use UTF8ToNewUnicode() now that it can w/o doing extra work to get the string length.
Comment 15•21 years ago
|
||
I think you could fix this one too:
http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsVariant.cpp#1110
Comment 16•21 years ago
|
||
Comment on attachment 148440 [details] [diff] [review]
Make XPConnect use UTF8ToNewUnicode() now that it can w/o doing extra work to get the string length.
>Index: js/src/xpconnect/src/xpcconvert.cpp
>+ jschar *p = (jschar *)UTF8ToNewUnicode(*cString, &len);
...
>+ JSString* jsString = JS_NewUCString(cx, p, len);
hmm... doesn't this technically mix allocators? should you use
JS_NewExternalString
with a finalizer that calls nsMemory::Free? or do we already make assumptions
in
XPConnect that nsMemory::Free is equivalent to |free|. brendan says "yes, we
do",
so i guess we can ignore this issue here.
r+sr=darin
Attachment #148440 -
Flags: superreview?(darin)
Attachment #148440 -
Flags: superreview+
Attachment #148440 -
Flags: review?(darin)
Attachment #148440 -
Flags: review+
Assignee | ||
Comment 17•21 years ago
|
||
Assignee | ||
Updated•21 years ago
|
Attachment #148470 -
Flags: superreview?(peterv)
Attachment #148470 -
Flags: review?(peterv)
Updated•21 years ago
|
Attachment #148470 -
Flags: superreview?(peterv)
Attachment #148470 -
Flags: superreview+
Attachment #148470 -
Flags: review?(peterv)
Attachment #148470 -
Flags: review+
Assignee | ||
Comment 18•21 years ago
|
||
nsVariant.cpp changes checked in now too. Marking FIXED.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Comment 19•21 years ago
|
||
Mix allocators... *snort*.
We should get rid of bogus layering on malloc and free.
/be
Comment 20•21 years ago
|
||
yeah, nsMemory::* should only be used by external code :-)
Assignee | ||
Updated•21 years ago
|
Keywords: fixed-aviary1.0
Assignee | ||
Updated•20 years ago
|
Keywords: fixed1.7.5
Updated•4 years ago
|
Component: String → XPCOM
You need to log in
before you can comment on or make changes to this bug.
Description
•