Closed Bug 243484 Opened 21 years ago Closed 21 years ago

Add PRUint32 length out param to ToNewUTF8String() and UTF8ToNewUnicode()

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: jst, Assigned: jst)

Details

(Keywords: fixed-aviary1.0, fixed1.7.5)

Attachments

(3 files, 1 obsolete file)

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.
Attached patch Add PRUint32 out params. (obsolete) — Splinter Review
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.
Attachment #148381 - Flags: superreview?(darin)
Attachment #148381 - Flags: review?(dbaron)
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?
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?
(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.
also, these are not frozen functions :-)
How does this patch not change the signature of the methods?
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.
ok, mixing inline with NS_COM is a bad idea :) i think the cold medicine is getting to me.... thanks dbaron!
Ok, I'm on crack. New patch coming up.
Attachment #148381 - Attachment is obsolete: true
Attachment #148393 - Flags: superreview?(darin)
Attachment #148393 - Flags: review?(dbaron)
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+
Attachment #148393 - Flags: superreview?(darin) → superreview+
Fix checked in. I've got a patch to make XPConnect use this too, I'll roll that in here as well.
Attachment #148440 - Flags: superreview?(darin)
Attachment #148440 - Flags: review?(darin)
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 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+
Attachment #148470 - Flags: superreview?(peterv)
Attachment #148470 - Flags: review?(peterv)
Attachment #148470 - Flags: superreview?(peterv)
Attachment #148470 - Flags: superreview+
Attachment #148470 - Flags: review?(peterv)
Attachment #148470 - Flags: review+
nsVariant.cpp changes checked in now too. Marking FIXED.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Mix allocators... *snort*. We should get rid of bogus layering on malloc and free. /be
yeah, nsMemory::* should only be used by external code :-)
Keywords: fixed-aviary1.0
Keywords: fixed1.7.5
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: