Closed Bug 25886 Opened 25 years ago Closed 2 years ago

|NS_DEFINE_IID| is bad; use |NS_GET_IID| instead

Categories

(Core :: XPCOM, task, P3)

task

Tracking

()

RESOLVED FIXED
Future
Tracking Status
firefox101 --- fixed

People

(Reporter: scc-obsolete, Assigned: mccr8)

References

()

Details

Attachments

(3 files, 1 obsolete file)

|NS_DEFINE_IID| is the old space-wasting scheme.  |NS_GET_IID| is the (not so) 
new, accepted, more efficient (on most platforms) scheme.  We need to root out 
all the old instances of |NS_DEFINE_IID| and replace the uses of their defined 
IIDs with |NS_GET_IID(type)|.
We've already agreed this is a P1; see
  <http://www.mozilla.org/projects/xpcom/XPCOM_plans.html>

There are thousands of occurances.  I don't think we can get them all by M14; but 
I'll have to do work on them in M14 to get them done by M15.  Probably need to 
file individual bugs on different sections of the code to get this done.
Status: NEW → ASSIGNED
Priority: P3 → P1
Target Milestone: M15
Blocks: 21326
Another one of those sweeping changes that fits in between everything else.  
There are still more instances than lxr is willing to display.
Target Milestone: M15 → M20
mass re-assigning to my new bugzilla account
Assignee: scc → scc
Status: ASSIGNED → NEW
Status: NEW → ASSIGNED
dp is no longer @netscape.com. changing qa contact to default for this product
QA Contact: dp → kandrot
I've been hoping that we could move even further and try to minimize the number
of places where we need to use NS_GET_IID as well.  NS_GET_IID forces the
programmer to specify the type of a variable in two different places and does
not check that the types are the same -- it is therefore not typesafe, and I
think we should prefer the typesafe functions available that will reduce the
risk of serious errors:  the nsCOMPtr helpers (do_QueryInterface,
do_CreateInstance, do_GetService, do_QueryReferent) and the function templates
for out parameters (CallQueryInterface, CallCreateInstance, CallGetService,
CallQueryReferent).  Many of the other uses of NS_GET_IID are in hand-written
QueryInterface methods that would be better written using the NS_IMPL_ISUPPORTSn
macros.
I grep'ed my tree for NS_DEFINE_.ID, parsed the output so I had a list of
(filename, cidVariableName), then did a grep -c to get the count of the
variable name in that file. If the count is 1, that means the file only has the
NS_DEFINE_.ID in it, and it can be stripped (unless it's a header, had to do
some manual checking there and undo a few removals). Initially I manually
removed these NS_DEFINE_.IDs and removed a few unneeded #includes in the
process, but that took forever so I wrote a little script to remove it for me
(hence no further #include clean-up).
Attachment #128085 - Flags: superreview?(dbaron)
Attachment #128085 - Flags: review?(caillon)
Attachment #128085 - Flags: superreview?(dbaron) → superreview+
jag: great work.

Do we need to deprecate NS_DEFINE_IID harder, or are all the occurrences old?

/be
I don't know, I could find out. It doesn't seem too hard to completely get rid
of NS_DEFINE_IID, I might go play with that this week.
Comment on attachment 128085 [details] [diff] [review]
Get rid of a bunch of unused NS_DEFINE_IID, NS_DEFINE_CID

r=caillon
Attachment #128085 - Flags: review?(caillon) → review+
*** Bug 61624 has been marked as a duplicate of this bug. ***
Assignee: scc → jag
Status: ASSIGNED → NEW
QA Contact: kandrot → jag
Assignee: jag → nobody
QA Contact: jag → xpcom
I have a patch locally that leaves me with this:

ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp:static NS_DEFINE_IID(kDConnectStubID, DCONNECT_STUB_ID);
layout/mathml/base/src/nsIMathMLFrame.h:static NS_DEFINE_IID(kIMathMLFrameIID, NS_IMATHMLFRAME_IID);
layout/tables/nsTableRowGroupFrame.cpp:  static NS_DEFINE_IID(kITableRowGroupIID, NS_ITABLEROWGROUPFRAME_IID);
xpcom/proxy/src/nsProxyEvent.cpp:NS_DEFINE_IID(kFilterIID, NS_PROXYEVENT_FILTER_IID);
xpcom/proxy/src/nsProxyEventObject.cpp:NS_DEFINE_IID(kFilterIID, NS_PROXYEVENT_FILTER_IID);
xpcom/reflect/xptcall/tests/eVC4/TestXPTCInvokeInIDE.cpp:static NS_DEFINE_IID(kTheCID, INVOKETESTTARGETINTERFACE_IID);

I've removed them if they were unused, replaced QueryInterface implementations with NS_IMPL_ISUPPORTSx, replaced QueryInterface calls with {do_,Call}QueryInterface, replaced NS_DEFINE_IID() for CIDs with NS_DEFINE_CID(), and replaced the rest with NS_GET_IID()

Oh, and 'coz I couldn't help myself I've thrown in some random clean-up. I don't think there's too much, but I'll remove any you'd rather see in a different bug.

Once my tree finishes building I'll attach a patch.
Status: NEW → ASSIGNED
Assignee: nobody → jag
Status: ASSIGNED → NEW
Attached patch Backup. This compiles on Mac. (obsolete) — Splinter Review
Comment on attachment 276974 [details] [diff] [review]
Backup. This compiles on Mac.

ns4xPlugin.cpp(878) : error C2065: 'kCPluginManagerCID' : undeclared identifier
ns4xPlugin.cpp(2284) : error C3861: 'kCPluginManagerCID': identifier not found, even with argument-dependent lookup
make[5]: *** [ns4xPlugin.obj] Error 2
Comment on attachment 276974 [details] [diff] [review]
Backup. This compiles on Mac.

nsScriptablePeer.cpp(85) : error C2039: 'nsIScriptable' : is not a member of 'operator``global namespace'''
make[5]: *** [nsScriptablePeer.obj] Error 2
Oooh, thanks Neil.

Changed all kPluginManagerCIDs in ns4xPlugin.cpp to kCPluginManagerCID, and fixed all three copies of that nsScriptablePeer to have nsIScriptable be nsIScriptablePluginSample.
Comment on attachment 276974 [details] [diff] [review]
Backup. This compiles on Mac.

nsOEImport.cpp(589) : error C2065: 'kISupportsIID' : undeclared identifier
make[4]: *** [nsOEImport.obj] Error 2
Fixed, dropped the QI to nsISupports and instead I'm just AppendElement()ing pID directly.
Priority: P1 → P3
Target Milestone: --- → Future
Assignee: jag+mozilla → nobody
Depends on: 1763481
Severity: normal → N/A
Type: defect → task
See Also: → 342595
Depends on: 1764370
Assignee: nobody → continuation

There are no remaining uses.

Pushed by amccreight@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/5ea7c27a36a0
Remove NS_DEFINE_IID. r=xpcom-reviewers,nika
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: