Update to Python XPCOM for recent breaking changes:

* Freeze/Modifications to nsIObserver and nsIServiceManager
* Header file re-organization.

Thanks to Christof Meerwald for the basis of this patch.

Not part of the build.
This commit is contained in:
markh%activestate.com 2001-11-07 04:32:37 +00:00
parent fc97e27fd5
commit 7cbbc4f2f5
7 changed files with 21 additions and 136 deletions

View File

@ -153,7 +153,7 @@ class _Class:
import xpcom.client
return xpcom.client.Component(self.contractid, _get_good_iid(iid))
def getService(self, iid = None):
return _xpcom.GetGlobalServiceManager().getService(self.contractid, _get_good_iid(iid))
return _xpcom.GetGlobalServiceManager().getServiceByContractID(self.contractid, _get_good_iid(iid))
class _Classes(_ComponentCollection):
def __init__(self):
@ -185,17 +185,19 @@ 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):
def observe(self, service, topic, extra):
global manager
global interfaceInfoManager
global _shutdownObserver
manager = interfaceInfoManager = _shutdownObserver = None
xpcom.client._shutdown()
svc = _xpcom.GetGlobalServiceManager().GetService("@mozilla.org/observer-service;1", interfaces.nsIObserverService)
svc = _xpcom.GetGlobalServiceManager().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)
svc.addObserver(_shutdownObserver, "xpcom-shutdown", false)
# 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

View File

@ -48,7 +48,7 @@ PYTHON_SRC=/usr/local/ActivePython-2.0
MOZ_SRC=../../../..
MOZCOMPONENTSDIR=$(MOZ_SRC)/mozilla/dist/bin/components
MOZINCLUDES=-I$(MOZ_SRC)/mozilla/dist/include -I$(MOZ_SRC)/mozilla/dist/include/nspr
MOZINCLUDES=-I$(MOZ_SRC)/mozilla/dist/include -I$(MOZ_SRC)/mozilla/dist/include/nspr -I$(MOZ_SRC)/mozilla/dist/include/string -I$(MOZ_SRC)/mozilla/dist/include/xpcom
MOZLIBDIR=$(MOZ_SRC)/mozilla/dist/lib
# this is setup to use the *installed* Python directory structure
@ -124,7 +124,6 @@ XPCOM_SRC_OBJECTS = \
src/PyIID.o \
src/PyIInterfaceInfo.o \
src/PyIInterfaceInfoManager.o \
src/PyIServiceManager.o \
src/PyISimpleEnumerator.o \
src/PyISupports.o \
src/Pyxpt_info.o \

View File

@ -52,7 +52,7 @@ def FindCOMComponents(py_module):
def register_self(klass, compMgr, location, registryLocation, componentType):
pcl = PythonComponentLoader
from xpcom import _xpcom
svc = _xpcom.GetGlobalServiceManager().GetService("@mozilla.org/categorymanager;1", components.interfaces.nsICategoryManager)
svc = _xpcom.GetGlobalServiceManager().getServiceByContractID("@mozilla.org/categorymanager;1", components.interfaces.nsICategoryManager)
svc.addCategoryEntry("component-loader", pcl._reg_component_type_, pcl._reg_contractid_, 1, 1)
class PythonComponentLoader:

View File

@ -1,117 +0,0 @@
/*
* 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 ActiveState Tool Corp. are Copyright (C) 2000, 2001
* ActiveState Tool Corp. All Rights Reserved.
*
* Contributor(s): Mark Hammond <MarkH@ActiveState.com> (original author)
*
*/
//
// 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"
#include <nsIServiceManager.h>
static nsIServiceManager *GetI(PyObject *self) {
nsIID iid = NS_GET_IID(nsIServiceManager);
if (!Py_nsISupports::Check(self, iid)) {
PyErr_SetString(PyExc_TypeError, "This object is not the correct interface");
return NULL;
}
return (nsIServiceManager *)Py_nsISupports::GetI(self);
}
static PyObject *PyRegisterService(PyObject *self, PyObject *args)
{
nsIServiceManager *pI = GetI(self);
if (pI==NULL)
return NULL;
PyObject *obCID, *obInterface;
if (!PyArg_ParseTuple(args, "OO", &obCID, &obInterface))
return NULL;
nsCOMPtr<nsISupports> pis;
if (!Py_nsISupports::InterfaceFromPyObject(obInterface, NS_GET_IID(nsISupports), getter_AddRefs(pis), PR_FALSE))
return NULL;
nsresult r;
if (PyString_Check(obCID)) {
const char *val = PyString_AsString(obCID);
Py_BEGIN_ALLOW_THREADS;
r = pI->RegisterService(val, pis);
Py_END_ALLOW_THREADS;
} else {
nsCID cid;
if (!Py_nsIID::IIDFromPyObject(obCID, &cid))
return NULL;
Py_BEGIN_ALLOW_THREADS;
r = pI->RegisterService(cid, pis);
Py_END_ALLOW_THREADS;
}
if ( NS_FAILED(r) )
return PyXPCOM_BuildPyException(r);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *PyGetService(PyObject *self, PyObject *args)
{
nsIServiceManager *pI = GetI(self);
if (pI==NULL)
return NULL;
PyObject *obIID, *obCID;
if (!PyArg_ParseTuple(args, "OO", &obCID, &obIID))
return NULL;
nsIID cid, iid;
if (!Py_nsIID::IIDFromPyObject(obIID, &iid))
return NULL;
nsISupports *pis;
nsresult r;
if (PyString_Check(obCID)) {
char *val = PyString_AsString(obCID);
Py_BEGIN_ALLOW_THREADS;
r = pI->GetService(val, iid, &pis);
Py_END_ALLOW_THREADS;
} else {
if (!Py_nsIID::IIDFromPyObject(obCID, &cid))
return NULL;
Py_BEGIN_ALLOW_THREADS;
r = pI->GetService(cid, iid, &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);
}
struct PyMethodDef
PyMethods_IServiceManager[] =
{
{ "GetService", PyGetService, 1},
{ "getService", PyGetService, 1},
{ "RegisterService", PyRegisterService, 1},
{ "registerService", PyRegisterService, 1},
{NULL}
};

View File

@ -19,6 +19,10 @@
#
DEPTH=..\..\..\..\..
REQUIRES=xpcom string \
$(NULL)
include <$(DEPTH)/config/config.mak>
MODULE=pyloader

View File

@ -22,7 +22,11 @@ DIRS = \
loader \
$(NULL)
REQUIRES=xpcom string \
$(NULL)
DEPTH=..\..\..\..
include <$(DEPTH)/config/config.mak>
DLLNAME=_xpcom
@ -46,7 +50,6 @@ CPP_OBJS= \
.\$(OBJDIR)\PyIID.obj \
.\$(OBJDIR)\PyIInterfaceInfo.obj \
.\$(OBJDIR)\PyIInterfaceInfoManager.obj \
.\$(OBJDIR)\PyIServiceManager.obj \
.\$(OBJDIR)\PyISimpleEnumerator.obj \
.\$(OBJDIR)\PyISupports.obj \
.\$(OBJDIR)\Pyxpt_info.obj \

View File

@ -61,7 +61,6 @@ PyXPCOM_INTERFACE_DEFINE(Py_nsIInterfaceInfoManager, nsIInterfaceInfoManager, Py
PyXPCOM_INTERFACE_DEFINE(Py_nsIEnumerator, nsIEnumerator, PyMethods_IEnumerator)
PyXPCOM_INTERFACE_DEFINE(Py_nsISimpleEnumerator, nsISimpleEnumerator, PyMethods_ISimpleEnumerator)
PyXPCOM_INTERFACE_DEFINE(Py_nsIInterfaceInfo, nsIInterfaceInfo, PyMethods_IInterfaceInfo)
PyXPCOM_INTERFACE_DEFINE(Py_nsIServiceManager, nsIServiceManager, PyMethods_IServiceManager)
PyXPCOM_INTERFACE_DEFINE(Py_nsIInputStream, nsIInputStream, PyMethods_IInputStream)
PyXPCOM_INTERFACE_DEFINE(Py_nsIClassInfo, nsIClassInfo, PyMethods_IClassInfo)
@ -179,21 +178,16 @@ PyXPCOMMethod_GetGlobalServiceManager(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
nsIServiceManagerObsolete* sm;
nsIServiceManager* sm;
nsresult rv;
Py_BEGIN_ALLOW_THREADS;
rv = nsServiceManager::GetGlobalServiceManager((nsIServiceManager**)&sm);
rv = NS_GetServiceManager(&sm);
Py_END_ALLOW_THREADS;
if ( NS_FAILED(rv) )
return PyXPCOM_BuildPyException(rv);
// NOTE - GetGlobalServiceManager DOES NOT ADD A REFCOUNT
// (naughty, naughty) - we we explicitly ask our converter to
// add one, even tho this is not the common pattern.
// Return a type based on the IID
// Can not auto-wrap the interface info manager as it is critical to
// building the support we need for autowrap.
return Py_nsISupports::PyObjectFromInterface(sm, NS_GET_IID(nsIServiceManager), PR_TRUE, PR_FALSE);
// Return a type based on the IID.
return Py_nsISupports::PyObjectFromInterface(sm, NS_GET_IID(nsIServiceManager), PR_FALSE);
}
@ -589,6 +583,7 @@ init_xpcom() {
REGISTER_IID(nsIWeakReference);
REGISTER_IID(nsISupportsWeakReference);
REGISTER_IID(nsIClassInfo);
REGISTER_IID(nsIServiceManager);
// Register our custom interfaces.
Py_nsISupports::InitType();
@ -597,7 +592,6 @@ init_xpcom() {
Py_nsIEnumerator::InitType(dict);
Py_nsISimpleEnumerator::InitType(dict);
Py_nsIInterfaceInfo::InitType(dict);
Py_nsIServiceManager::InitType(dict);
Py_nsIInputStream::InitType(dict);
Py_nsIClassInfo::InitType(dict);