Closed Bug 1557829 Opened 5 years ago Closed 5 years ago

Port bug 1557793 - Adapt to array changes in nsIStringBundle.formatStringFrom{ID|Name|NameCpp}

Categories

(MailNews Core :: General, task)

task
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 69.0

People

(Reporter: jorgk-bmo, Assigned: jorgk-bmo)

References

Details

Attachments

(3 files, 7 obsolete files)

Assignee: nobody → jorgk
Status: NEW → ASSIGNED
Attached patch 1557829-formatStringFromName.patch - WIP (obsolete) (deleted) — Splinter Review

This fixed mailnews/addrbook/ - mach build comm/mailnews/addrbook/

More to come, of course.

Attached patch 1557829-formatStringFromName.patch (obsolete) (deleted) — Splinter Review

This wasn't so much fun to write and it won't be fun to review. Let me know if I should find a TB reviewer. Some notes:

  1. Wherever the array isn't sized by initialising it, I used AutoTArray<nsString, NN>. I didn't see a pattern in D34196, there is AutoTArray<nsString, 1> strings = {path}; but also nsTArray<nsString> formatStrings = {mHostPort};.
  2. I used nsTArray<nsString> when initialising the array.
  3. In some cases, strings are passed in as raw strings or nsAString&. I used nsString(xx) in this case to stuff them in to the format strings. Look for nsString( in the patch.
  4. I tried to remove as many "...toUTF16" conversions into temporary variables as possible.
  5. I didn't do the JS part yet.
Attachment #9070926 - Attachment is obsolete: true
Attachment #9071090 - Flags: review?(bzbarsky)
Comment on attachment 9071090 [details] [diff] [review] 1557829-formatStringFromName.patch Review of attachment 9071090 [details] [diff] [review]: ----------------------------------------------------------------- ::: mailnews/import/applemail/src/nsAppleMailImport.cpp @@ +588,2 @@ > nsresult rv = mBundle->FormatStringFromName( > + NS_ConvertUTF16toUTF8(aErrorName).get(), &fmt, outString); Needs to be `fmt`. I don't compile on Mac.
Attached patch 1557829-formatStringFromName.patch (v2) (obsolete) (deleted) — Splinter Review

Removed more temporary variables.

Attachment #9071090 - Attachment is obsolete: true
Attachment #9071090 - Flags: review?(bzbarsky)
Attachment #9071118 - Flags: review?(bzbarsky)

Wherever the array isn't sized by initialising it, I used AutoTArray<nsString, NN>. I didn't see a pattern in D34196, there is AutoTArray<nsString, 1> strings = {path}; but also nsTArray<nsString> formatStrings = {mHostPort};.

Should have been AutoTArray consistently; the nsTArray there is an oversight.

I used nsTArray<nsString> when initialising the array.

That's fine, but does an extra heap-allocation compared to using AutoTArray. Maybe it doesn't matter in practice, but it was easier for me to do the faster thing instead of analyzing all the callsites.

I didn't do the JS part yet.

The nice thing with the JS part is that if the C++ part lands without the JS part that's not a problem: the JS part will just be passing an extra arg for the length which will get ignored...

Oh, I did use nsTArray instead of AutoTArray in the one place where I std::move things, because nsTArray can be moved cheaply while AutoTArray of course cannot.

Comment on attachment 9071118 [details] [diff] [review] 1557829-formatStringFromName.patch (v2) I'd really appreciate it if someone on the Thunderbird team could review this, ideally in a separate bug. It requires careful reading, and I'm not sure I have time for that right now...
Attachment #9071118 - Flags: review?(bzbarsky)

Thanks for the comment, Boris. I'll make it AutoTArray everywhere. We actually are in a separate bug here, I kept out of your bug 1557793 since I knew that this would create some noise :-)

One last question, is there a better way to do this:

         const char16_t delimiter[2] = {(char16_t)m_hierarchyDelimiter, '\0'};
-        const char16_t *formatStrings[] = {delimiter};
+        AutoTArray<nsString, 1> formatStrings = {nsDependentString(delimiter)};

EDIT: One very last question: How to deal with strings coming in as nsAString, like so:

-    const char16_t *formatStrings[] = {aAccountname.BeginReading()};
+    AutoTArray<nsString, 1> formatStrings = {PromiseFlatString(aAccountname)};
Flags: needinfo?(bzbarsky)
Attached patch 1557829-formatStringFromName.patch (v3) (obsolete) (deleted) — Splinter Review

First reviewer wins. Note: This will land as bustage-fix as soon as bug 1557793 lands.

Attachment #9071118 - Attachment is obsolete: true
Attachment #9071202 - Flags: review?(mkmelin+mozilla)
Attachment #9071202 - Flags: review?(geoff)
Attachment #9071202 - Flags: review?(benc)
Attachment #9071202 - Flags: review?(acelists)
Attached patch 1557829-formatStringFromName.patch (v3b) (obsolete) (deleted) — Splinter Review

Another tweak.

Attachment #9071202 - Attachment is obsolete: true
Attachment #9071202 - Flags: review?(mkmelin+mozilla)
Attachment #9071202 - Flags: review?(geoff)
Attachment #9071202 - Flags: review?(benc)
Attachment #9071202 - Flags: review?(acelists)
Attachment #9071256 - Flags: review?(geoff)
Attachment #9071256 - Flags: review?(benc)
Attachment #9071256 - Flags: review?(acelists)

One last question, is there a better way to do this:

  AutoTArray<nsString, 1> formatStrings;
  formatString.AppendElement(nsDependentSubstring(&m_hierarchyDelimiter, 1));

ought to work.

EDIT: One very last question: How to deal with strings coming in as nsAString, like so:

  AutoTArray<nsString, 1> formatStrings;
  formatString.AppendElement(aAccountname);

though you could also do:

    AutoTArray<nsString, 1> formatStrings = {nsString(aAccountname)};

and it's probably equivalent in terms of the actual code that runs.

Flags: needinfo?(bzbarsky)

Thanks, Boris. The first solution doesn't work since m_hierarchyDelimiter is just a char*.

Attached patch 1557829-formatStringFromName.patch (v3c) (obsolete) (deleted) — Splinter Review

Final string tweak, first reviewer wins. Bug 1557793 has all the reviews and will land soon.

Attachment #9071256 - Attachment is obsolete: true
Attachment #9071256 - Flags: review?(geoff)
Attachment #9071256 - Flags: review?(benc)
Attachment #9071256 - Flags: review?(acelists)
Attachment #9071303 - Flags: review?(geoff)
Attachment #9071303 - Flags: review?(benc)
Attachment #9071303 - Flags: review?(acelists)
Attached patch 1557829-formatStringFromName.patch (v3c) (obsolete) (deleted) — Splinter Review

Sigh, there go another 100KB which will be stored for eternity. Forgot to refresh.

Attachment #9071303 - Attachment is obsolete: true
Attachment #9071303 - Flags: review?(geoff)
Attachment #9071303 - Flags: review?(benc)
Attachment #9071303 - Flags: review?(acelists)
Attachment #9071304 - Flags: review?(geoff)
Attachment #9071304 - Flags: review?(benc)
Attachment #9071304 - Flags: review?(acelists)

Thanks, Boris. The first solution doesn't work since m_hierarchyDelimiter is just a char*.

In that case, just:

  AutoTArray<nsString, 1> formatStrings;
  formatString.AppendElement()->Append(m_hierarchyDelimiter);

should work. (I assume you meant it's a char, not a char *.)

Attachment #9071304 - Attachment is obsolete: true
Attachment #9071304 - Flags: review?(geoff)
Attachment #9071304 - Flags: review?(benc)
Attachment #9071304 - Flags: review?(acelists)
Attachment #9071322 - Flags: review?(geoff)
Attachment #9071322 - Flags: review?(benc)
Attachment #9071322 - Flags: review?(acelists)
Pushed by mozilla@jorgk.com: https://hg.mozilla.org/comm-central/rev/323c1caa59c5 Port bug 1557793 - Adapt to array changes in nsIStringBundle.formatStringFromName. rs=bustage-fix
Target Milestone: --- → Thunderbird 69.0
Attached patch Follow-up for Linux/Mac. (deleted) — Splinter Review
Attachment #9071465 - Flags: review?(geoff)
Pushed by mozilla@jorgk.com: https://hg.mozilla.org/comm-central/rev/18519908af98 Follow-up: Fix Linux/Mac specific code. rs=bustage-fix
Comment on attachment 9071322 [details] [diff] [review] 1557829-formatStringFromName.patch (v3d) Review of attachment 9071322 [details] [diff] [review]: ----------------------------------------------------------------- Just a few things to tidy up. ::: mailnews/addrbook/src/nsAbLDAPListenerBase.cpp @@ +121,5 @@ > > // hostTemp is only necessary to work around a code-generation > // bug in egcs 1.1.2 (the version of gcc that comes with Red Hat 6.2), > // which is the default compiler for Mozilla on linux at the moment. > // This comment is out-of-date. ::: mailnews/addrbook/src/nsAbView.cpp @@ +1256,4 @@ > NS_ENSURE_SUCCESS(rv, rv); > nameString[0] = fn.get(); > nameString[1] = ln.get(); > + rv = bundle->FormatStringFromName(formatString, nameString, dnFnLn); Missed this bit? ::: mailnews/extensions/smime/src/nsMsgComposeSecure.h @@ +56,5 @@ > nsIMsgSendReport *sendReport, bool aEncrypt, > bool aSign, nsIMsgIdentity *aIdentity); > bool InitializeSMIMEBundle(); > nsresult SMIMEBundleFormatStringFromName(const char *name, > + nsTArray<nsString> &paramsparams, paramsparams?
Attachment #9071322 - Flags: review?(geoff)
Attachment #9071322 - Flags: review?(benc)
Attachment #9071322 - Flags: review?(acelists)
Attachment #9071322 - Flags: review+
Attachment #9071465 - Flags: review?(geoff) → review+
Attachment #9071511 - Flags: review?(philipp)
Attachment #9071511 - Flags: review?(mkmelin+mozilla)
Attachment #9071511 - Flags: review?(acelists)
Comment on attachment 9071511 [details] [diff] [review] 1557829-format-string-from-1.diff (JS changes) Is this a "first reviewer wins" case? I doubt you need three reviews for removing all those last parameters. Leaving Philipp since Calendar is affected.
Attachment #9071511 - Flags: review?(mkmelin+mozilla)
Attachment #9071511 - Flags: review?(acelists)
Attachment #9071511 - Flags: review+

Thanks.

(In reply to Geoff Lankow (:darktrojan) from comment #21)

Missed this bit?

I'm surprised that compiled.

Keywords: leave-open

Pushed by mozilla@jorgk.com:
https://hg.mozilla.org/comm-central/rev/285cab894a6e
Follow-up: Address review comments. r=me
https://hg.mozilla.org/comm-central/rev/f7a7d54671d6
Port bug 1557793: Adapt to array changes in nsIStringBundle.formatStringFromName (JS changes). r=jorgk

Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Attachment #9071511 - Flags: review?(philipp) → review+
Regressions: 1571813
Type: defect → task
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: