Closed
Bug 436051
Opened 17 years ago
Closed 17 years ago
nsIMsgFolder::getFoldersWithFlag abuses idl interface conventions
Categories
(MailNews Core :: Backend, defect)
MailNews Core
Backend
Tracking
(Not tracked)
RESOLVED
FIXED
mozilla1.9.1a1
People
(Reporter: standard8, Assigned: neil)
References
Details
Attachments
(1 file, 4 obsolete files)
37.44 KB,
patch
|
standard8
:
review+
Bienvenu
:
superreview+
|
Details | Diff | Splinter Review |
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.
Assignee | ||
Comment 1•17 years ago
|
||
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
Reporter | ||
Comment 2•17 years ago
|
||
Note:
nsMsgDBFolder *dbFolder = static_cast<nsMsgDBFolder *>(mSubFolders[i]);
dbFolder->ListFoldersWithFlag(flag,array);
could also do with a tidy up.
Assignee | ||
Comment 3•17 years ago
|
||
I've changed my mind. Get rid of get/ListFoldersWithFlag, and implement void listFoldersWithFlags(in unsigned long flags, in nsIMutableArray folders);
Assignee | ||
Comment 4•17 years ago
|
||
Note: I deliberately didn't use mSubFolders for this WIP patch because I've got a feeling its type will change soon ;-)
Reporter | ||
Comment 5•17 years ago
|
||
(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.
Assignee | ||
Comment 6•17 years ago
|
||
(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.
Assignee | ||
Comment 7•17 years ago
|
||
How's this for the implementation?
Attachment #322872 -
Attachment is obsolete: true
Attachment #323208 -
Flags: review?(bugzilla)
Assignee | ||
Comment 8•17 years ago
|
||
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.
Reporter | ||
Comment 9•17 years ago
|
||
(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.
Assignee | ||
Comment 10•17 years ago
|
||
Out parameters are already null-checked by xpconnect so the C++ often doesn't.
Reporter | ||
Comment 11•17 years ago
|
||
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)
Assignee | ||
Comment 12•17 years ago
|
||
(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.
Assignee | ||
Comment 14•17 years ago
|
||
* Not including mail UI yet
* Not including flag constant idl changes yet
Assignee | ||
Comment 15•17 years ago
|
||
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 16•17 years ago
|
||
Comment on attachment 324671 [details] [diff] [review]
Proposed patch
is this the right patch?
Assignee | ||
Comment 17•17 years ago
|
||
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 18•17 years ago
|
||
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+
Reporter | ||
Updated•17 years ago
|
Attachment #324676 -
Flags: review?(bugzilla) → review+
Assignee | ||
Comment 19•17 years ago
|
||
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Comment 20•17 years ago
|
||
(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
}}
Updated•17 years ago
|
OS: Mac OS X → All
Hardware: PC → All
Target Milestone: --- → mozilla1.9.1a1
Updated•17 years ago
|
Product: Core → MailNews Core
You need to log in
before you can comment on or make changes to this bug.
Description
•