diff --git a/mozilla/extensions/python/xpcom/Makefile.in b/mozilla/extensions/python/xpcom/Makefile.in index 555dcdf45df..c8fade7c7ea 100644 --- a/mozilla/extensions/python/xpcom/Makefile.in +++ b/mozilla/extensions/python/xpcom/Makefile.in @@ -54,6 +54,7 @@ PYSRCS_XPCOM = \ file.py \ nsError.py \ register.py \ + shutdown.py \ xpcom_consts.py \ xpt.py \ $(NULL) diff --git a/mozilla/extensions/python/xpcom/components.py b/mozilla/extensions/python/xpcom/components.py index 9ea64fc2100..448b70d7103 100644 --- a/mozilla/extensions/python/xpcom/components.py +++ b/mozilla/extensions/python/xpcom/components.py @@ -220,21 +220,15 @@ del _ComponentCollection # The ID function ID = _xpcom.IID -# A helper to cleanup our namespace as xpcom shuts down. -class _ShutdownObserver: - _com_interfaces_ = interfaces.nsIObserver - def observe(self, service, topic, extra): - global manager, registrar, classes, interfaces, interfaceInfoManager, _shutdownObserver, serviceManager, _constants_by_iid_map - manager = registrar = classes = interfaces = interfaceInfoManager = _shutdownObserver = serviceManager = _constants_by_iid_map = None - xpcom.client._shutdown() - xpcom.server._shutdown() +def _on_shutdown(): + global manager, registrar, classes, interfaces, interfaceInfoManager, serviceManager, _constants_by_iid_map + manager = registrar = classes = interfaces = interfaceInfoManager = serviceManager = _constants_by_iid_map = None + # for historical reasons we call these manually. + xpcom.client._shutdown() + xpcom.server._shutdown() -svc = _xpcom.GetServiceManager().getServiceByContractID("@mozilla.org/observer-service;1", interfaces.nsIObserverService) -# Observers will be QI'd for a weak-reference, so we must keep the -# observer alive ourself, and must keep the COM object alive, -# _not_ just the Python instance!!! -_shutdownObserver = xpcom.server.WrapObject(_ShutdownObserver(), interfaces.nsIObserver) -# Say we want a weak ref due to an assertion failing. If this is fixed, we can pass 0, -# and remove the lifetime hacks above! See http://bugzilla.mozilla.org/show_bug.cgi?id=99163 -svc.addObserver(_shutdownObserver, "xpcom-shutdown", 1) -del svc, _ShutdownObserver +# import xpcom.shutdown late as it depends on us! +import shutdown +shutdown.register(_on_shutdown) + +del _on_shutdown, shutdown diff --git a/mozilla/extensions/python/xpcom/server/__init__.py b/mozilla/extensions/python/xpcom/server/__init__.py index 39905b4f1b6..16042cf90ec 100644 --- a/mozilla/extensions/python/xpcom/server/__init__.py +++ b/mozilla/extensions/python/xpcom/server/__init__.py @@ -72,16 +72,13 @@ def UnwrapObject(ob): ret = tracer_unwrap(ret) return ret -# Create the main module for the Python loader. -# This is a once only init process, and the returned object -# if used to load all other Python components. - -# This means that we keep all factories, modules etc implemented in -# Python! +# Create the (Python implemented) module for the Python loader. This +# Python loader will then (indirectly) create other modules for any found +# .py file components def NS_GetModule( serviceManager, nsIFile ): - import loader + import loader, module iid = _xpcom.IID_nsIModule - return WrapObject(loader.MakePythonComponentLoaderModule(serviceManager, nsIFile), iid, bWrapClient = 0) + return WrapObject(module.Module([loader.ModuleLoader]), iid, bWrapClient = 0) def _shutdown(): from policy import _shutdown diff --git a/mozilla/extensions/python/xpcom/server/loader.py b/mozilla/extensions/python/xpcom/server/loader.py index 190750bd6c8..bb7c1ccac2c 100644 --- a/mozilla/extensions/python/xpcom/server/loader.py +++ b/mozilla/extensions/python/xpcom/server/loader.py @@ -37,18 +37,11 @@ import xpcom from xpcom import components +import xpcom.shutdown import module -import glob, os, types -import traceback - -from xpcom.client import Component - -# Until we get interface constants. -When_Startup = 0 -When_Component = 1 -When_Timer = 2 +import os, types def _has_good_attr(object, attr): # Actually allows "None" to be specified to disable inherited attributes. @@ -66,26 +59,37 @@ def FindCOMComponents(py_module): return comps def register_self(klass, compMgr, location, registryLocation, componentType): - pcl = PythonComponentLoader + pcl = ModuleLoader from xpcom import _xpcom svc = _xpcom.GetServiceManager().getServiceByContractID("@mozilla.org/categorymanager;1", components.interfaces.nsICategoryManager) - svc.addCategoryEntry("component-loader", pcl._reg_component_type_, pcl._reg_contractid_, 1, 1) + # The category 'module-loader' is special - the component manager uses it + # to create the nsIModuleLoader for a given component type. + svc.addCategoryEntry("module-loader", pcl._reg_component_type_, pcl._reg_contractid_, 1, 1) -class PythonComponentLoader: - _com_interfaces_ = components.interfaces.nsIComponentLoader - _reg_clsid_ = "{63B68B1E-3E62-45f0-98E3-5E0B5797970C}" # Never copy these! - _reg_contractid_ = "moz.pyloader.1" - _reg_desc_ = "Python component loader" +# The Python module loader. Called by the component manager when it finds +# a component of type self._reg_component_type_. Responsible for returning +# an nsIModule for the file. +class ModuleLoader: + _com_interfaces_ = components.interfaces.nsIModuleLoader + _reg_clsid_ = "{945BFDA9-0226-485e-8AE3-9A2F68F6116A}" # Never copy these! + _reg_contractid_ = "@mozilla.org/module-loader/python;1" + _reg_desc_ = "Python module loader" # Optional function which performs additional special registration - # Appears that no special unregistration is needed for ComponentLoaders, hence no unregister function. + # Appears that no special unregistration is needed for ModuleLoaders, hence no unregister function. _reg_registrar_ = (register_self,None) - # Custom attributes for ComponentLoader registration. - _reg_component_type_ = "script/python" + # Custom attributes for ModuleLoader registration. + _reg_component_type_ = "application/x-python" def __init__(self): self.com_modules = {} # Keyed by module's FQN as obtained from nsIFile.path self.moduleFactory = module.Module - self.num_modules_this_register = 0 + xpcom.shutdown.register(self._on_shutdown) + + def _on_shutdown(self): + self.com_modules.clear() + + def loadModule(self, aFile): + return self._getCOMModuleForLocation(aFile) def _getCOMModuleForLocation(self, componentFile): fqn = componentFile.path @@ -98,7 +102,7 @@ class PythonComponentLoader: module_name_in_sys = "component:%s" % (base_name,) stuff = loader.find_module(base_name, [componentFile.parent.path]) - assert stuff is not None, "Couldnt find the module '%s'" % (base_name,) + assert stuff is not None, "Couldn't find the module '%s'" % (base_name,) py_mod = loader.load_module( module_name_in_sys, stuff ) # Make and remember the COM module. @@ -107,119 +111,3 @@ class PythonComponentLoader: self.com_modules[fqn] = mod return mod - - def getFactory(self, clsid, location, type): - # return the factory - assert type == self._reg_component_type_, "Being asked to create an object not of my type:%s" % (type,) - # FIXME: how to do this without obsolete component manager? - cmo = components.manager.queryInterface(components.interfaces.nsIComponentManagerObsolete) - file_interface = cmo.specForRegistryLocation(location) - # delegate to the module. - m = self._getCOMModuleForLocation(file_interface) - return m.getClassObject(components.manager, clsid, components.interfaces.nsIFactory) - - def init(self, comp_mgr, registry): - # void - self.comp_mgr = comp_mgr - if xpcom.verbose: - print "Python component loader init() called" - - # Called when a component of the appropriate type is registered, - # to give the component loader an opportunity to do things like - # annotate the registry and such. - def onRegister (self, clsid, type, className, proId, location, replace, persist): - if xpcom.verbose: - print "Python component loader - onRegister() called" - - def autoRegisterComponents (self, when, directory): - directory_path = directory.path - self.num_modules_this_register = 0 - if xpcom.verbose: - print "Auto-registering all Python components in", directory_path - - # ToDo - work out the right thing here - # eg - do we recurse? - # - do we support packages? - entries = directory.directoryEntries - while entries.HasMoreElements(): - entry = entries.GetNext(components.interfaces.nsIFile) - if os.path.splitext(entry.path)[1]==".py": - try: - self.autoRegisterComponent(when, entry) - # Handle some common user errors - except xpcom.COMException, details: - from xpcom import nsError - # If the interface name does not exist, suppress the traceback - if details.errno==nsError.NS_ERROR_NO_INTERFACE: - print "** Registration of '%s' failed\n %s" % (entry.leafName,details.message,) - else: - print "** Registration of '%s' failed!" % (entry.leafName,) - traceback.print_exc() - except SyntaxError, details: - # Syntax error in source file - no useful traceback here either. - print "** Registration of '%s' failed!" % (entry.leafName,) - traceback.print_exception(SyntaxError, details, None) - except: - # All other exceptions get the full traceback. - print "** Registration of '%s' failed!" % (entry.leafName,) - traceback.print_exc() - - def autoRegisterComponent (self, when, componentFile): - # bool return - - # Check if we actually need to do anything - modtime = componentFile.lastModifiedTime - loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager) - if not loader_mgr.hasFileChanged(componentFile, None, modtime): - return 1 - - if self.num_modules_this_register == 0: - # New components may have just installed new Python - # modules into the main python directory (including new .pth files) - # So we ask Python to re-process our site directory. - # Note that the pyloader does the equivalent when loading. - try: - from xpcom import _xpcom - import site - NS_XPCOM_CURRENT_PROCESS_DIR="XCurProcD" - dirname = _xpcom.GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR) - dirname.append("python") - site.addsitedir(dirname.path) - except: - print "PyXPCOM loader failed to process site directory before component registration" - traceback.print_exc() - - self.num_modules_this_register += 1 - - # auto-register via the module. - m = self._getCOMModuleForLocation(componentFile) - m.registerSelf(components.manager, componentFile, None, self._reg_component_type_) - loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager) - loader_mgr.saveFileInfo(componentFile, None, modtime) - return 1 - - def autoUnregisterComponent (self, when, componentFile): - # bool return - # auto-unregister via the module. - m = self._getCOMModuleForLocation(componentFile) - loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager) - try: - m.unregisterSelf(components.manager, componentFile) - finally: - loader_mgr.removeFileInfo(componentFile, None) - return 1 - - def registerDeferredComponents (self, when): - # bool return - if xpcom.verbose: - print "Python component loader - registerDeferred() called" - return 0 # no more to register - def unloadAll (self, when): - if xpcom.verbose: - print "Python component loader being asked to unload all components!" - self.comp_mgr = None - self.com_modules = {} - -def MakePythonComponentLoaderModule(serviceManager, nsIFile): - import module - return module.Module( [PythonComponentLoader] ) diff --git a/mozilla/extensions/python/xpcom/server/module.py b/mozilla/extensions/python/xpcom/server/module.py index 094abc29b31..73318f5b971 100644 --- a/mozilla/extensions/python/xpcom/server/module.py +++ b/mozilla/extensions/python/xpcom/server/module.py @@ -100,9 +100,8 @@ class Module: if ok: print "Successfully unregistered", klass.__name__ else: - print "Unregistration of", klass.__name__, "failed. (probably just not already registered)" - + print "Unregistration of", klass.__name__, "failed (not previously registered?)" + def canUnload(self, compMgr): # single bool result return 0 # we can never unload! - diff --git a/mozilla/extensions/python/xpcom/server/policy.py b/mozilla/extensions/python/xpcom/server/policy.py index 98b2c38b597..3f6c6319cf5 100644 --- a/mozilla/extensions/python/xpcom/server/policy.py +++ b/mozilla/extensions/python/xpcom/server/policy.py @@ -140,7 +140,10 @@ class DefaultPolicy: self._iid_ = iid if ni is None: raise ValueError, "The object '%r' can not be used as a COM object" % (instance,) - # This is really only a check for the user + # This is really only a check for the user - the same thing is + # done by the framework. + # XXXmarkh - this should probably die now we have better error + # reporting in the framework! if __debug__: if iid != IID_nsISupports and iid not in ni: # The object may delegate QI. diff --git a/mozilla/extensions/python/xpcom/shutdown.py b/mozilla/extensions/python/xpcom/shutdown.py new file mode 100644 index 00000000000..19d3cc30d06 --- /dev/null +++ b/mozilla/extensions/python/xpcom/shutdown.py @@ -0,0 +1,74 @@ +# Utilities for registering functions to be called at xpcom shutdown. +# +# Pass xpcom.shutdown.register a function (and optionally args) that should +# be called as xpcom shutsdown. Relies on xpcom itself sending the +# standard shutdown notification. + +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Python XPCOM language bindings. +# +# The Initial Developer of the Original Code is Mark Hammond. +# Portions created by the Initial Developer are Copyright (C) 2000 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** +# + +import xpcom.server +from xpcom import _xpcom +from xpcom.components import interfaces + +import logging + +_handlers = [] + +class _ShutdownObserver: + _com_interfaces_ = interfaces.nsIObserver + def observe(self, service, topic, extra): + logger = logging.getLogger('xpcom') + while _handlers: + func, args, kw = _handlers.pop() + try: + logger.debug("Calling shutdown handler '%s'(*%s, **%s)", + func, args, kw) + func(*args, **kw) + except: + logger.exception("Shutdown handler '%s' failed", func) + +def register(func, *args, **kw): + _handlers.append( (func, args, kw) ) + +# Register +svc = _xpcom.GetServiceManager().getServiceByContractID( + "@mozilla.org/observer-service;1", + interfaces.nsIObserverService) + +svc.addObserver(_ShutdownObserver(), "xpcom-shutdown", 0) + +del svc, _ShutdownObserver diff --git a/mozilla/extensions/python/xpcom/src/Makefile.in b/mozilla/extensions/python/xpcom/src/Makefile.in index 860ec8e4216..78eac19c07f 100644 --- a/mozilla/extensions/python/xpcom/src/Makefile.in +++ b/mozilla/extensions/python/xpcom/src/Makefile.in @@ -68,7 +68,6 @@ CPPSRCS= \ PyGWeakReference.cpp \ PyIClassInfo.cpp \ PyIComponentManager.cpp \ - PyIComponentManagerObsolete.cpp \ PyIInputStream.cpp \ PyIEnumerator.cpp \ PyIID.cpp \ diff --git a/mozilla/extensions/python/xpcom/src/PyGBase.cpp b/mozilla/extensions/python/xpcom/src/PyGBase.cpp index 83a7d0512d9..7cc69fd4f0f 100644 --- a/mozilla/extensions/python/xpcom/src/PyGBase.cpp +++ b/mozilla/extensions/python/xpcom/src/PyGBase.cpp @@ -48,7 +48,6 @@ #include "PyXPCOM_std.h" #include -#include #include static PRInt32 cGateways = 0; @@ -58,7 +57,6 @@ PRInt32 _PyXPCOM_GetGatewayCount(void) } extern PyG_Base *MakePyG_nsIModule(PyObject *); -extern PyG_Base *MakePyG_nsIComponentLoader(PyObject *instance); extern PyG_Base *MakePyG_nsIInputStream(PyObject *instance); static char *PyXPCOM_szDefaultGatewayAttributeName = "_com_instance_default_gateway_"; @@ -77,8 +75,6 @@ PyG_Base::CreateNew(PyObject *pPyInstance, const nsIID &iid, void **ppResult) // Hack for few extra gateways we support. if (iid.Equals(NS_GET_IID(nsIModule))) ret = MakePyG_nsIModule(pPyInstance); - else if (iid.Equals(NS_GET_IID(nsIComponentLoader))) - ret = MakePyG_nsIComponentLoader(pPyInstance); else if (iid.Equals(NS_GET_IID(nsIInputStream))) ret = MakePyG_nsIInputStream(pPyInstance); else diff --git a/mozilla/extensions/python/xpcom/src/PyGModule.cpp b/mozilla/extensions/python/xpcom/src/PyGModule.cpp index bb2124320a7..5cc638c1644 100644 --- a/mozilla/extensions/python/xpcom/src/PyGModule.cpp +++ b/mozilla/extensions/python/xpcom/src/PyGModule.cpp @@ -53,7 +53,7 @@ #include "PyXPCOM_std.h" #include -#include +#include class PyG_nsIModule : public PyG_Base, public nsIModule { @@ -156,142 +156,3 @@ PyG_nsIModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) Py_XDECREF(ret); return nr; } - -/////////////////////////////////////////////////////////////////////////////////// - -class PyG_nsIComponentLoader : public PyG_Base, public nsIComponentLoader -{ -public: - PyG_nsIComponentLoader(PyObject *instance) : PyG_Base(instance, NS_GET_IID(nsIComponentLoader)) {;} - PYGATEWAY_BASE_SUPPORT(nsIComponentLoader, PyG_Base); - - NS_DECL_NSICOMPONENTLOADER -}; - -PyG_Base *MakePyG_nsIComponentLoader(PyObject *instance) -{ - return new PyG_nsIComponentLoader(instance); -} - -/* nsIFactory getFactory (in nsIIDRef aCID, in string aLocation, in string aType); */ -NS_IMETHODIMP PyG_nsIComponentLoader::GetFactory(const nsIID & aCID, const char *aLocation, const char *aType, nsIFactory **_retval) -{ - CEnterLeavePython _celp; - const char *methodName = "getFactory"; - PyObject *iid = Py_nsIID::PyObjectFromIID(aCID); - PyObject *ret = NULL; - nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "Ozz", - iid, - aLocation, - aType); - Py_XDECREF(iid); - if (NS_SUCCEEDED(nr)) { - Py_nsISupports::InterfaceFromPyObject(ret, NS_GET_IID(nsIFactory), (nsISupports **)_retval, PR_FALSE); - if (PyErr_Occurred()) - nr = HandleNativeGatewayError(methodName); - } - Py_XDECREF(ret); - return nr; -} - -/* void init (in nsIComponentManager aCompMgr, in nsISupports aRegistry); */ -NS_IMETHODIMP PyG_nsIComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aRegistry) -{ - CEnterLeavePython _celp; - const char *methodName = "init"; - PyObject *c = Py_nsISupports::PyObjectFromInterface(aCompMgr, NS_GET_IID(nsIComponentManager), PR_TRUE); - PyObject *r = Py_nsISupports::PyObjectFromInterface(aRegistry, NS_GET_IID(nsISupports), PR_TRUE); - nsresult nr = InvokeNativeViaPolicy(methodName, NULL, "OO", c, r); - Py_XDECREF(c); - Py_XDECREF(r); - return nr; -} - -/* void onRegister (in nsIIDRef aCID, in string aType, in string aClassName, in string aContractID, in string aLocation, in boolean aReplace, in boolean aPersist); */ -NS_IMETHODIMP PyG_nsIComponentLoader::OnRegister(const nsIID & aCID, const char *aType, const char *aClassName, const char *aContractID, const char *aLocation, PRBool aReplace, PRBool aPersist) -{ - CEnterLeavePython _celp; - const char *methodName = "onRegister"; - PyObject *iid = Py_nsIID::PyObjectFromIID(aCID); - nsresult nr = InvokeNativeViaPolicy(methodName, NULL, "Ossssii", - iid, - aType, - aClassName, - aContractID, - aLocation, - aReplace, - aPersist); - Py_XDECREF(iid); - return nr; -} - -/* void autoRegisterComponents (in long aWhen, in nsIFile aDirectory); */ -NS_IMETHODIMP PyG_nsIComponentLoader::AutoRegisterComponents(PRInt32 aWhen, nsIFile *aDirectory) -{ - CEnterLeavePython _celp; - const char *methodName = "autoRegisterComponents"; - PyObject *c = Py_nsISupports::PyObjectFromInterface(aDirectory, NS_GET_IID(nsIFile), PR_TRUE); - nsresult nr = InvokeNativeViaPolicy(methodName, NULL, "iO", aWhen, c); - Py_XDECREF(c); - return nr; -} - -/* boolean autoRegisterComponent (in long aWhen, in nsIFile aComponent); */ -NS_IMETHODIMP PyG_nsIComponentLoader::AutoRegisterComponent(PRInt32 aWhen, nsIFile *aComponent, PRBool *_retval) -{ - CEnterLeavePython _celp; - const char *methodName = "autoRegisterComponent"; - PyObject *ret = NULL; - PyObject *c = Py_nsISupports::PyObjectFromInterface(aComponent, NS_GET_IID(nsIFile), PR_TRUE); - nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "iO", aWhen, c); - Py_XDECREF(c); - if (NS_SUCCEEDED(nr)) { - *_retval = PyInt_AsLong(ret); - if (PyErr_Occurred()) - nr = HandleNativeGatewayError(methodName); - } - Py_XDECREF(ret); - return nr; -} - -/* boolean autoUnregisterComponent (in long aWhen, in nsIFile aComponent); */ -NS_IMETHODIMP PyG_nsIComponentLoader::AutoUnregisterComponent(PRInt32 aWhen, nsIFile *aComponent, PRBool *_retval) -{ - CEnterLeavePython _celp; - const char *methodName = "autoUnregisterComponent"; - PyObject *ret = NULL; - PyObject *c = Py_nsISupports::PyObjectFromInterface(aComponent, NS_GET_IID(nsIFile), PR_TRUE); - nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "iO", aWhen, c); - Py_XDECREF(c); - if (NS_SUCCEEDED(nr)) { - *_retval = PyInt_AsLong(ret); - if (PyErr_Occurred()) - nr = HandleNativeGatewayError(methodName); - } - Py_XDECREF(ret); - return nr; -} - -/* boolean registerDeferredComponents (in long aWhen); */ -NS_IMETHODIMP PyG_nsIComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, PRBool *_retval) -{ - CEnterLeavePython _celp; - const char *methodName = "registerDeferredComponents"; - PyObject *ret = NULL; - nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "i", aWhen); - if (NS_SUCCEEDED(nr)) { - *_retval = PyInt_AsLong(ret); - if (PyErr_Occurred()) - nr = HandleNativeGatewayError(methodName); - } - Py_XDECREF(ret); - return nr; -} - -/* void unloadAll (in long aWhen); */ -NS_IMETHODIMP PyG_nsIComponentLoader::UnloadAll(PRInt32 aWhen) -{ - CEnterLeavePython _celp; - const char *methodName = "unloadAll"; - return InvokeNativeViaPolicy(methodName, NULL, "i", aWhen); -} diff --git a/mozilla/extensions/python/xpcom/src/PyIComponentManagerObsolete.cpp b/mozilla/extensions/python/xpcom/src/PyIComponentManagerObsolete.cpp deleted file mode 100644 index 8e524c1c5b5..00000000000 --- a/mozilla/extensions/python/xpcom/src/PyIComponentManagerObsolete.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is the Python XPCOM language bindings. - * - * The Initial Developer of the Original Code is - * ActiveState Tool Corp. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Mark Hammond (original author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// -// This code is part of the XPCOM extensions for Python. -// -// Written May 2000 by Mark Hammond. -// -// Based heavily on the Python COM support, which is -// (c) Mark Hammond and Greg Stein. -// -// (c) 2000, ActiveState corp. - -#include "PyXPCOM_std.h" - -static nsIComponentManagerObsolete *GetI(PyObject *self) { - static const nsIID iid = NS_GET_IID(nsIComponentManagerObsolete); - - if (!Py_nsISupports::Check(self, iid)) { - PyErr_SetString(PyExc_TypeError, "This object is not the correct interface"); - return NULL; - } - return (nsIComponentManagerObsolete *)Py_nsISupports::GetI(self); -} - -static PyObject *PyCreateInstanceByContractID(PyObject *self, PyObject *args) -{ - char *pid, *notyet = NULL; - PyObject *obIID = NULL; - if (!PyArg_ParseTuple(args, "s|zO", &pid, ¬yet, &obIID)) - return NULL; - if (notyet != NULL) { - PyErr_SetString(PyExc_ValueError, "2nd arg must be none"); - return NULL; - } - nsIComponentManagerObsolete *pI = GetI(self); - if (pI==NULL) - return NULL; - - nsIID iid; - if (obIID==NULL) - iid = NS_GET_IID(nsISupports); - else - if (!Py_nsIID::IIDFromPyObject(obIID, &iid)) - return NULL; - - nsISupports *pis; - nsresult r; - Py_BEGIN_ALLOW_THREADS; - r = pI->CreateInstanceByContractID(pid, NULL, iid, (void **)&pis); - Py_END_ALLOW_THREADS; - if ( NS_FAILED(r) ) - return PyXPCOM_BuildPyException(r); - - /* Return a type based on the IID (with no extra ref) */ - return Py_nsISupports::PyObjectFromInterface(pis, iid, PR_FALSE, PR_FALSE); -} - -static PyObject *PyContractIDToClassID(PyObject *self, PyObject *args) -{ - char *pid; - if (!PyArg_ParseTuple(args, "s", &pid)) - return NULL; - nsIComponentManagerObsolete *pI = GetI(self); - if (pI==NULL) - return NULL; - - nsIID iid; - nsresult r; - Py_BEGIN_ALLOW_THREADS; - r = pI->ContractIDToClassID(pid, &iid); - Py_END_ALLOW_THREADS; - if ( NS_FAILED(r) ) - return PyXPCOM_BuildPyException(r); - - return Py_nsIID::PyObjectFromIID(iid); -} - -static PyObject *PyCLSIDToContractID(PyObject *self, PyObject *args) -{ - PyObject *obIID; - if (!PyArg_ParseTuple(args, "O", &obIID)) - return NULL; - - nsIID iid; - if (!Py_nsIID::IIDFromPyObject(obIID, &iid)) - return NULL; - char *ret_pid = nsnull; - char *ret_class = nsnull; - nsIComponentManagerObsolete *pI = GetI(self); - if (pI==NULL) - return NULL; - - nsresult r; - Py_BEGIN_ALLOW_THREADS; - r = pI->CLSIDToContractID(iid, &ret_class, &ret_pid); - Py_END_ALLOW_THREADS; - if ( NS_FAILED(r) ) - return PyXPCOM_BuildPyException(r); - - PyObject *ob_pid = PyString_FromString(ret_pid); - PyObject *ob_class = PyString_FromString(ret_class); - PyObject *ret = Py_BuildValue("OO", ob_pid, ob_class); - nsMemory::Free(ret_pid); - nsMemory::Free(ret_class); - Py_XDECREF(ob_pid); - Py_XDECREF(ob_class); - return ret; -} - -static PyObject *PyEnumerateCLSIDs(PyObject *self, PyObject *args) -{ - if (!PyArg_ParseTuple(args, "")) - return NULL; - - nsIComponentManagerObsolete *pI = GetI(self); - if (pI==NULL) - return NULL; - - nsIEnumerator *pRet; - nsresult r; - Py_BEGIN_ALLOW_THREADS; - r = pI->EnumerateCLSIDs(&pRet); - Py_END_ALLOW_THREADS; - if ( NS_FAILED(r) ) - return PyXPCOM_BuildPyException(r); - - return Py_nsISupports::PyObjectFromInterface(pRet, NS_GET_IID(nsIEnumerator), PR_FALSE); -} - -static PyObject *PyEnumerateContractIDs(PyObject *self, PyObject *args) -{ - if (!PyArg_ParseTuple(args, "")) - return NULL; - - nsIComponentManagerObsolete *pI = GetI(self); - if (pI==NULL) - return NULL; - - nsIEnumerator *pRet; - nsresult r; - Py_BEGIN_ALLOW_THREADS; - r = pI->EnumerateContractIDs(&pRet); - Py_END_ALLOW_THREADS; - if ( NS_FAILED(r) ) - return PyXPCOM_BuildPyException(r); - - return Py_nsISupports::PyObjectFromInterface(pRet, NS_GET_IID(nsIEnumerator), PR_FALSE); -} - -struct PyMethodDef -PyMethods_IComponentManagerObsolete[] = -{ - { "CreateInstanceByContractID", PyCreateInstanceByContractID, 1}, - { "createInstanceByContractID", PyCreateInstanceByContractID, 1}, - { "EnumerateCLSIDs", PyEnumerateCLSIDs, 1}, - { "enumerateCLSIDs", PyEnumerateCLSIDs, 1}, - { "EnumerateContractIDs", PyEnumerateContractIDs, 1}, - { "enumerateContractIDs", PyEnumerateContractIDs, 1}, - { "ContractIDToClassID", PyContractIDToClassID, 1}, - { "contractIDToClassID", PyContractIDToClassID, 1}, - { "CLSIDToContractID", PyCLSIDToContractID, 1}, - {NULL} -}; diff --git a/mozilla/extensions/python/xpcom/src/TypeObject.cpp b/mozilla/extensions/python/xpcom/src/TypeObject.cpp index 3faed3e6c19..a20276791d8 100644 --- a/mozilla/extensions/python/xpcom/src/TypeObject.cpp +++ b/mozilla/extensions/python/xpcom/src/TypeObject.cpp @@ -102,7 +102,6 @@ PyXPCOM_TypeObject::Py_setattr(PyObject *op, char *name, PyObject *v) /*static*/int PyXPCOM_TypeObject::Py_cmp(PyObject *self, PyObject *other) { - // @comm NOTE: Copied from COM - have not confirmed these rules are true for XPCOM // @comm As per the XPCOM rules for object identity, both objects are queried for nsISupports, and these values compared. // The only meaningful test is for equality - the result of other comparisons is undefined // (ie, determined by the object's relative addresses in memory. diff --git a/mozilla/extensions/python/xpcom/src/loader/pyloader.cpp b/mozilla/extensions/python/xpcom/src/loader/pyloader.cpp index 2cd3556d59e..64a18ef4672 100644 --- a/mozilla/extensions/python/xpcom/src/loader/pyloader.cpp +++ b/mozilla/extensions/python/xpcom/src/loader/pyloader.cpp @@ -49,7 +49,6 @@ #undef HAVE_LONG_LONG #endif -#include "nsIComponentLoader.h" #include "nsISupports.h" #include "nsIModule.h" #include "nsDirectoryServiceDefs.h" diff --git a/mozilla/extensions/python/xpcom/src/xpcom.cpp b/mozilla/extensions/python/xpcom/src/xpcom.cpp index 64a7b79541c..b21d3a4047f 100644 --- a/mozilla/extensions/python/xpcom/src/xpcom.cpp +++ b/mozilla/extensions/python/xpcom/src/xpcom.cpp @@ -53,7 +53,6 @@ #include "nsIFile.h" #include "nsILocalFile.h" #include "nsIComponentRegistrar.h" -#include "nsIComponentManagerObsolete.h" #ifdef XP_WIN #ifndef WIN32_LEAN_AND_MEAN @@ -85,8 +84,6 @@ PyXPCOM_INTERFACE_DEFINE(Py_nsIInterfaceInfo, nsIInterfaceInfo, PyMethods_IInter PyXPCOM_INTERFACE_DEFINE(Py_nsIInputStream, nsIInputStream, PyMethods_IInputStream) PyXPCOM_INTERFACE_DEFINE(Py_nsIClassInfo, nsIClassInfo, PyMethods_IClassInfo) PyXPCOM_INTERFACE_DEFINE(Py_nsIVariant, nsIVariant, PyMethods_IVariant) -// deprecated, but retained for backward compatibility: -PyXPCOM_INTERFACE_DEFINE(Py_nsIComponentManagerObsolete, nsIComponentManagerObsolete, PyMethods_IComponentManagerObsolete) //////////////////////////////////////////////////////////// // This is the main entry point called by the Python component @@ -149,29 +146,6 @@ done: // "boot-strap" methods - interfaces we need to get the base // interface support! -/* deprecated, included for backward compatibility */ -static PyObject * -PyXPCOMMethod_NS_GetGlobalComponentManager(PyObject *self, PyObject *args) -{ - if (PyErr_Warn(PyExc_DeprecationWarning, "Use GetComponentManager instead") < 0) - return NULL; - if (!PyArg_ParseTuple(args, "")) - return NULL; - nsIComponentManager* cm; - nsresult rv; - Py_BEGIN_ALLOW_THREADS; - rv = NS_GetComponentManager(&cm); - Py_END_ALLOW_THREADS; - if ( NS_FAILED(rv) ) - return PyXPCOM_BuildPyException(rv); - - nsCOMPtr ocm(do_QueryInterface(cm, &rv)); - if ( NS_FAILED(rv) ) - return PyXPCOM_BuildPyException(rv); - - return Py_nsISupports::PyObjectFromInterface(cm, NS_GET_IID(nsIComponentManagerObsolete), PR_FALSE, PR_FALSE); -} - static PyObject * PyXPCOMMethod_GetComponentManager(PyObject *self, PyObject *args) { @@ -205,16 +179,6 @@ PyXPCOMMethod_GetServiceManager(PyObject *self, PyObject *args) return Py_nsISupports::PyObjectFromInterface(sm, NS_GET_IID(nsIServiceManager), PR_FALSE); } -/* deprecated, included for backward compatibility */ -static PyObject * -PyXPCOMMethod_GetGlobalServiceManager(PyObject *self, PyObject *args) -{ - if (PyErr_Warn(PyExc_DeprecationWarning, "Use GetServiceManager instead") < 0) - return NULL; - - return PyXPCOMMethod_GetComponentManager(self, args); -} - static PyObject * PyXPCOMMethod_XPTI_GetInterfaceInfoManager(PyObject *self, PyObject *args) { @@ -467,11 +431,9 @@ extern PyObject *PyXPCOMMethod_IID(PyObject *self, PyObject *args); static struct PyMethodDef xpcom_methods[]= { {"GetComponentManager", PyXPCOMMethod_GetComponentManager, 1}, - {"NS_GetGlobalComponentManager", PyXPCOMMethod_NS_GetGlobalComponentManager, 1}, // deprecated {"XPTI_GetInterfaceInfoManager", PyXPCOMMethod_XPTI_GetInterfaceInfoManager, 1}, {"XPTC_InvokeByIndex", PyXPCOMMethod_XPTC_InvokeByIndex, 1}, {"GetServiceManager", PyXPCOMMethod_GetServiceManager, 1}, - {"GetGlobalServiceManager", PyXPCOMMethod_GetGlobalServiceManager, 1}, // deprecated {"IID", PyXPCOMMethod_IID, 1}, // IID is wrong - deprecated - not just IID, but CID, etc. {"ID", PyXPCOMMethod_IID, 1}, // This is the official name. {"NS_ShutdownXPCOM", PyXPCOMMethod_NS_ShutdownXPCOM, 1}, @@ -628,8 +590,6 @@ init_xpcom() { Py_nsIInputStream::InitType(dict); Py_nsIClassInfo::InitType(dict); Py_nsIVariant::InitType(dict); - // for backward compatibility: - Py_nsIComponentManagerObsolete::InitType(dict); // We have special support for proxies - may as well add their constants! REGISTER_INT(PROXY_SYNC);