Closed Bug 436051 Opened 17 years ago Closed 17 years ago

nsIMsgFolder::getFoldersWithFlag abuses idl interface conventions

Categories

(MailNews Core :: Backend, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla1.9.1a1

People

(Reporter: standard8, Assigned: neil)

References

Details

Attachments

(1 file, 4 obsolete files)

This is the current specification of nsIMsgFolder::getFoldersWithFlag nsIMsgFolder getFoldersWithFlag(in unsigned long flags, in unsigned long resultsize, out unsigned long numFolders); When I look at the code, we have this function prototype: NS_IMETHODIMP nsMsgDBFolder::GetFoldersWithFlag(PRUint32 flags, PRUint32 resultsize, PRUint32 *numFolders, nsIMsgFolder **result) The function will treat "result" as an array for resultsize > 1. This is not a good idea - from js it will probably cause a crash. Thankfully all our code so far doesn't seem to set resultsize > 1 from js. From c++ this is awkward and unintuitive. We also have the function nsIMsgFolder::GetAllFoldersWithFlag. My proposal is to rework how we use this two functions to come up with something reasonable that doesn't abuse interfaces.
First, we should create nsIMsgFolder getFolderWithFlag(in unsigned long flag); and switch all the consumers of getFoldersWithFlag(flag, 1, {}) to use that. Second, we should change to void getFoldersWithFlag(in unsigned long flags, out unsigned long numFolders, [array, size_is(numFolders)]out nsIMsgFolder folders) and just dump getAllFoldersWithFlag. I'd like bug 436044 to be fixed first to avoid changing consumers twice ;-)
Depends on: 436044
Note: nsMsgDBFolder *dbFolder = static_cast<nsMsgDBFolder *>(mSubFolders[i]); dbFolder->ListFoldersWithFlag(flag,array); could also do with a tidy up.
I've changed my mind. Get rid of get/ListFoldersWithFlag, and implement void listFoldersWithFlags(in unsigned long flags, in nsIMutableArray folders);
Attached patch Proof of concept (obsolete) — Splinter Review
Note: I deliberately didn't use mSubFolders for this WIP patch because I've got a feeling its type will change soon ;-)
(In reply to comment #3) > I've changed my mind. Get rid of get/ListFoldersWithFlag, and implement void > listFoldersWithFlags(in unsigned long flags, in nsIMutableArray folders); > I would much rather have this as: nsIArray listFoldersWithFlags(in unsigned long flags); and then have the equivalent c++ function, plus an internal/private function: nsresult nsMsgDBFolder::ListFoldersWithFlags(PRInt32 flags, nsIMutableArray *folders); Although this means an extra function, it will greatly simplify getting the array from javascript (for extensions etc) and it won't affect the c++ callers that much.
(In reply to comment #5) > I would much rather have this as: > > nsIArray listFoldersWithFlags(in unsigned long flags); > > and then have the equivalent c++ function, plus an internal/private function: I can't make it private without using static casts ;-) But I can easily add the nsIArray version.
Attached patch WIP (obsolete) — Splinter Review
How's this for the implementation?
Attachment #322872 - Attachment is obsolete: true
Attachment #323208 - Flags: review?(bugzilla)
Comment on attachment 323208 [details] [diff] [review] WIP Bah, GetSubFolders(nsnull) crashes :-( I could null-check the implementations. Or I could write EnsureSubFolders(). Or I could just needlessly create enumerators like everyone else does.
(In reply to comment #8) > (From update of attachment 323208 [details] [diff] [review]) > Bah, GetSubFolders(nsnull) crashes :-( > I could null-check the implementations. Even if we don't allow nsnull it shouldn't crash... > Or I could write EnsureSubFolders(). Possibility. > Or I could just needlessly create enumerators like everyone else does. Bah, if only I had realised this when I did the GetSubFolders implementation.
Out parameters are already null-checked by xpconnect so the C++ often doesn't.
Comment on attachment 323208 [details] [diff] [review] WIP Ignoring the GetSubFolders(nsnull) issue, the implementation looks reasonable, one comment though: + void listFoldersWithFlags(in unsigned long flags, + in nsIMutableArray folders); Should folders be an inout param?
Attachment #323208 - Flags: review?(bugzilla)
(In reply to comment #11) (From update of attachment 323208 [details] [diff] [review]) >>+ void listFoldersWithFlags(in unsigned long flags, >>+ in nsIMutableArray folders); >Should folders be an inout param? No, you only use that if you might return a different instance of object. Here making it a mutable array allows me to modify the passed-in object.
Attached patch WIP (obsolete) — Splinter Review
* Not including mail UI yet * Not including flag constant idl changes yet
Assignee: bugzilla → neil
Attachment #323208 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attached patch Proposed patch (obsolete) — Splinter Review
I only changed some of the call sites over to the new nsMsgFolderFlags constants because I wasn't sure what the best way to do that in JS was.
Attachment #323541 - Attachment is obsolete: true
Attachment #324671 - Flags: superreview?(bienvenu)
Attachment #324671 - Flags: review?(bugzilla)
Comment on attachment 324671 [details] [diff] [review] Proposed patch is this the right patch?
Attached patch Correct patchSplinter Review
Oops, I'd only diffed the newest changes by mistake.
Attachment #324671 - Attachment is obsolete: true
Attachment #324676 - Flags: superreview?(bienvenu)
Attachment #324676 - Flags: review?(bugzilla)
Attachment #324671 - Flags: superreview?(bienvenu)
Attachment #324671 - Flags: review?(bugzilla)
Comment on attachment 324676 [details] [diff] [review] Correct patch just a couple nits: in nsMsgAccountManager::SaveVirtualFolders, I was wondering why you didn't need to change the code that uses virtualFolders, and I encountered this: nsCOMPtr <nsIRDFResource> folderRes (do_QueryElementAt(virtualFolders, folderIndex)); nsCOMPtr <nsIMsgFolder> msgFolder = do_QueryInterface(folderRes); const char *uri; we don't need folderRes, do we? Some K&R braces style snuck into nsMsgDBFolder and nsImapIncomingServer which were relatively uninfected before :-)
Attachment #324676 - Flags: superreview?(bienvenu) → superreview+
Attachment #324676 - Flags: review?(bugzilla) → review+
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
(In reply to comment #19) > Fix checked in. FTR, used a wrong bug number.: {{ 2008-06-13 03:41 neil%parkwaycc.co.uk ... Bug 326051 nsIMsgFolder::getFoldersWithFlag abuses xpcom conventions r=Standard8 sr=bienvenu }}
OS: Mac OS X → All
Hardware: PC → All
Target Milestone: --- → mozilla1.9.1a1
Depends on: 441191
Product: Core → MailNews Core
Depends on: 457545
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: