зеркало из https://github.com/mozilla/gecko-dev.git
Merging 1.0 branch onto the trunk (I know this is not the usual
way, but it is just me :) Not part of the build!
This commit is contained in:
Родитель
ebd58c55fd
Коммит
675beee8de
|
@ -12,7 +12,7 @@
|
|||
# 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)
|
||||
# Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
#
|
||||
|
||||
import os
|
||||
|
@ -75,11 +75,14 @@ interface_method_cache = {}
|
|||
|
||||
# Keyed by clsid from nsIClassInfo - everything ever queried for the CID.
|
||||
contractid_info_cache = {}
|
||||
have_shutdown = 0
|
||||
|
||||
def _shutdown():
|
||||
interface_cache.clear()
|
||||
interface_method_cache.clear()
|
||||
contractid_info_cache.clear()
|
||||
global have_shutdown
|
||||
have_shutdown = 1
|
||||
|
||||
# Fully process the named method, generating method code etc.
|
||||
def BuildMethod(method_info, iid):
|
||||
|
@ -112,6 +115,7 @@ FLAGS_TO_IGNORE = XPT_MD_NOTXPCOM | XPT_MD_CTOR | XPT_MD_HIDDEN
|
|||
# Pre-process the interface - generate a list of methods, constants etc,
|
||||
# but don't actually generate the method code.
|
||||
def BuildInterfaceInfo(iid):
|
||||
assert not have_shutdown, "Can't build interface info after a shutdown"
|
||||
ret = interface_cache.get(iid, None)
|
||||
if ret is None:
|
||||
# Build the data for the cache.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
# 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)
|
||||
# Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
#
|
||||
|
||||
# This module provides the JavaScript "components" interface
|
||||
|
@ -201,8 +201,8 @@ ID = _xpcom.IID
|
|||
class _ShutdownObserver:
|
||||
_com_interfaces_ = interfaces.nsIObserver
|
||||
def observe(self, service, topic, extra):
|
||||
global manager, interfaceInfoManager, _shutdownObserver, serviceManager, _constants_by_iid_map
|
||||
manager = interfaceInfoManager = _shutdownObserver = serviceManager = _constants_by_iid_map = None
|
||||
global manager, classes, interfaces, interfaceInfoManager, _shutdownObserver, serviceManager, _constants_by_iid_map
|
||||
manager = classes = interfaces = interfaceInfoManager = _shutdownObserver = serviceManager = _constants_by_iid_map = None
|
||||
xpcom.client._shutdown()
|
||||
xpcom.server._shutdown()
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
# 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)
|
||||
# Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
#
|
||||
|
||||
"""Implementation of Python file objects for Mozilla/xpcom.
|
||||
|
@ -54,18 +54,6 @@ NS_TRUNCATE = components.interfaces.nsIFileChannel.NS_TRUNCATE
|
|||
NS_SYNC = components.interfaces.nsIFileChannel.NS_SYNC
|
||||
NS_EXCL = components.interfaces.nsIFileChannel.NS_EXCL
|
||||
|
||||
# A helper function - you pass a progID, an interface, plus optionally the
|
||||
# name of the "constructor" and its args.
|
||||
def _construct(progid, interface, ctor = None, *args):
|
||||
assert (ctor is None and not args) or (ctor is not None and args), \
|
||||
"no point having a ctor with no args, or if you provide args, there must be a ctor!"
|
||||
instance = components.classes[progid] \
|
||||
.createInstance(interface)
|
||||
if ctor is not None:
|
||||
ctor = getattr(instance, ctor)
|
||||
apply(ctor, args)
|
||||
return instance
|
||||
|
||||
# A helper function that may come in useful
|
||||
def LocalFileToURL(localFileName):
|
||||
"Convert a filename to an XPCOM nsIFileURL object."
|
||||
|
@ -167,11 +155,16 @@ class URIFile(_File):
|
|||
# You open this file using a local file name (as a string) so it really is pointless -
|
||||
# you may as well be using a standard Python file object!
|
||||
class LocalFile(_File):
|
||||
def __init__(self, *args):
|
||||
self.fileIO = None
|
||||
_File.__init__(self, *args)
|
||||
|
||||
def init(self, name, mode = "r"):
|
||||
name = os.path.abspath(name) # Moz libraries under Linux fail with relative paths.
|
||||
self.close()
|
||||
file = _construct('@mozilla.org/file/local;1', "nsILocalFile", "initWithPath", name)
|
||||
self.fileIO = _construct('@mozilla.org/network/file-io;1', "nsIFileIO", "init", file, -1, -1)
|
||||
file = components.classes['@mozilla.org/file/local;1'].createInstance("nsILocalFile")
|
||||
file.initWithPath(name)
|
||||
self.fileIO = components.classes['@mozilla.org/network/file-io;1'].createInstance("nsIFileIO")
|
||||
if mode in ["w","a"]:
|
||||
if mode== "w":
|
||||
if file.exists():
|
||||
|
@ -181,17 +174,24 @@ class LocalFile(_File):
|
|||
moz_mode = NS_APPEND
|
||||
else:
|
||||
assert 0, "Can't happen!"
|
||||
self.fileIO.init(file, moz_mode, -1)
|
||||
self.outputStream = self.fileIO.outputStream
|
||||
|
||||
elif mode == "r":
|
||||
self.contentType, self.contentLength = self.fileIO.open()
|
||||
self.fileIO.init(file, NS_RDONLY, -1)
|
||||
self.inputStream = self.fileIO.inputStream
|
||||
else:
|
||||
raise ValueError, "Unknown mode"
|
||||
|
||||
def close(self):
|
||||
if self.fileIO is not None:
|
||||
self.fileIO.close(0)
|
||||
self.fileIO = None
|
||||
_File.close(self)
|
||||
|
||||
def read(self, n = -1):
|
||||
if n == -1:
|
||||
n = self.contentLength
|
||||
n = self.fileIO.contentLength
|
||||
return _File.read(self, n)
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
# 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)
|
||||
# Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
#
|
||||
|
||||
from xpcom import xpcom_consts, _xpcom, client, nsError, ServerException, COMException
|
||||
|
@ -23,9 +23,19 @@ import operator
|
|||
import types
|
||||
|
||||
IID_nsISupports = _xpcom.IID_nsISupports
|
||||
IID_nsIVariant = _xpcom.IID_nsIVariant
|
||||
XPT_MD_IS_GETTER = xpcom_consts.XPT_MD_IS_GETTER
|
||||
XPT_MD_IS_SETTER = xpcom_consts.XPT_MD_IS_SETTER
|
||||
|
||||
VARIANT_INT_TYPES = xpcom_consts.VTYPE_INT8, xpcom_consts.VTYPE_INT16, xpcom_consts.VTYPE_INT32, \
|
||||
xpcom_consts.VTYPE_UINT8, xpcom_consts.VTYPE_UINT16, xpcom_consts.VTYPE_INT32
|
||||
VARIANT_LONG_TYPES = xpcom_consts.VTYPE_INT64, xpcom_consts.VTYPE_UINT64
|
||||
VARIANT_FLOAT_TYPES = xpcom_consts.VTYPE_FLOAT, xpcom_consts.VTYPE_DOUBLE
|
||||
VARIANT_STRING_TYPES = xpcom_consts.VTYPE_CHAR, xpcom_consts.VTYPE_CHAR_STR, xpcom_consts.VTYPE_STRING_SIZE_IS, \
|
||||
xpcom_consts.VTYPE_CSTRING
|
||||
VARIANT_UNICODE_TYPES = xpcom_consts.VTYPE_WCHAR, xpcom_consts.VTYPE_DOMSTRING, xpcom_consts.VTYPE_WSTRING_SIZE_IS, \
|
||||
xpcom_consts.VTYPE_ASTRING
|
||||
|
||||
_supports_primitives_map_ = {} # Filled on first use.
|
||||
|
||||
_interface_sequence_types_ = types.TupleType, types.ListType
|
||||
|
@ -175,11 +185,47 @@ class DefaultPolicy:
|
|||
if iid is None:
|
||||
iid = self._interface_info_.GetIIDForParam(method_index, param_index)
|
||||
self._interface_iid_map_[(method_index, param_index)] = iid
|
||||
# iid = _xpcom.IID_nsISupports
|
||||
# handle nsIVariant
|
||||
if iid == IID_nsIVariant:
|
||||
interface = interface.QueryInterface(iid)
|
||||
dt = interface.dataType
|
||||
if dt in VARIANT_INT_TYPES:
|
||||
return interface.getAsInt32()
|
||||
if dt in VARIANT_LONG_TYPES:
|
||||
return interface.getAsInt64()
|
||||
if dt in VARIANT_FLOAT_TYPES:
|
||||
return interface.getAsFloat()
|
||||
if dt in VARIANT_STRING_TYPES:
|
||||
return interface.getAsStringWithSize()
|
||||
if dt in VARIANT_UNICODE_TYPES:
|
||||
return interface.getAsWStringWithSize()
|
||||
if dt == xpcom_consts.VTYPE_BOOL:
|
||||
return interface.getAsBool()
|
||||
if dt == xpcom_consts.VTYPE_INTERFACE:
|
||||
return interface.getAsISupports()
|
||||
if dt == xpcom_consts.VTYPE_INTERFACE_IS:
|
||||
return interface.getAsInterface()
|
||||
if dt == xpcom_consts.VTYPE_EMPTY or dt == xpcom_consts.VTYPE_VOID:
|
||||
return None
|
||||
if dt == xpcom_consts.VTYPE_ARRAY:
|
||||
return interface.getAsArray()
|
||||
if dt == xpcom_consts.VTYPE_EMPTY_ARRAY:
|
||||
return []
|
||||
if dt == xpcom_consts.VTYPE_ID:
|
||||
return interface.getAsID()
|
||||
# all else fails...
|
||||
print "Warning: nsIVariant type %d not supported - returning a string" % (dt,)
|
||||
try:
|
||||
return interface.getAsString()
|
||||
except COMException:
|
||||
print "Error: failed to get Variant as a string - returning variant object"
|
||||
traceback.print_exc()
|
||||
return interface
|
||||
|
||||
return client.Component(interface, iid)
|
||||
|
||||
def _CallMethod_(self, com_object, index, info, params):
|
||||
# print "_CallMethod_", index, info, params
|
||||
#print "_CallMethod_", index, info, params
|
||||
flags, name, param_descs, ret = info
|
||||
assert ret[1][0] == xpcom_consts.TD_UINT32, "Expected an nsresult (%s)" % (ret,)
|
||||
if XPT_MD_IS_GETTER(flags):
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -115,7 +115,7 @@ PyG_Base::PyG_Base(PyObject *instance, const nsIID &iid)
|
|||
PyObject *real_repr = PyObject_Repr(real_instance);
|
||||
|
||||
PYXPCOM_LOG_DEBUG("PyG_Base created at %p\n instance_repr=%s\n IID=%s\n", this, PyString_AsString(real_repr), iid_repr);
|
||||
nsAllocator::Free(iid_repr);
|
||||
nsMemory::Free(iid_repr);
|
||||
Py_XDECREF(real_instance);
|
||||
Py_XDECREF(real_repr);
|
||||
}
|
||||
|
@ -281,9 +281,11 @@ done:
|
|||
}
|
||||
Py_XDECREF(obIID);
|
||||
Py_XDECREF(obParamDesc);
|
||||
if (result==NULL) // we had an error.
|
||||
if (result==NULL) { // we had an error.
|
||||
PyErr_Clear(); // but are not reporting it back to Python itself!
|
||||
// return our obISupports. If NULL, we are really hosed and nothing we can do.
|
||||
return obISupports;
|
||||
}
|
||||
// Dont need to return this - we have a better result.
|
||||
Py_XDECREF(obISupports);
|
||||
return result;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -65,7 +65,7 @@ PyG_nsIModule::GetClassObject(nsIComponentManager *aCompMgr,
|
|||
NS_PRECONDITION(r_classObj, "null pointer");
|
||||
*r_classObj = nsnull;
|
||||
CEnterLeavePython _celp;
|
||||
PyObject *cm = MakeInterfaceParam(aCompMgr, &NS_GET_IID(nsIComponentManagerObsolete));
|
||||
PyObject *cm = Py_nsISupports::PyObjectFromInterface(aCompMgr, NS_GET_IID(nsIComponentManagerObsolete), PR_TRUE);
|
||||
PyObject *iid = Py_nsIID::PyObjectFromIID(aIID);
|
||||
PyObject *clsid = Py_nsIID::PyObjectFromIID(aClass);
|
||||
const char *methodName = "getClassObject";
|
||||
|
@ -95,8 +95,8 @@ PyG_nsIModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
|||
NS_PRECONDITION(aCompMgr, "null pointer");
|
||||
NS_PRECONDITION(aPath, "null pointer");
|
||||
CEnterLeavePython _celp;
|
||||
PyObject *cm = MakeInterfaceParam(aCompMgr, &NS_GET_IID(nsIComponentManagerObsolete));
|
||||
PyObject *path = MakeInterfaceParam(aPath, &NS_GET_IID(nsIFile));
|
||||
PyObject *cm = Py_nsISupports::PyObjectFromInterface(aCompMgr, NS_GET_IID(nsIComponentManagerObsolete), PR_TRUE);
|
||||
PyObject *path = Py_nsISupports::PyObjectFromInterface(aPath, NS_GET_IID(nsIFile), PR_TRUE);
|
||||
const char *methodName = "registerSelf";
|
||||
nsresult nr = InvokeNativeViaPolicy(methodName, NULL, "OOzz", cm, path, registryLocation, componentType);
|
||||
Py_XDECREF(cm);
|
||||
|
@ -112,8 +112,8 @@ PyG_nsIModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
|||
NS_PRECONDITION(aCompMgr, "null pointer");
|
||||
NS_PRECONDITION(aPath, "null pointer");
|
||||
CEnterLeavePython _celp;
|
||||
PyObject *cm = MakeInterfaceParam(aCompMgr, &NS_GET_IID(nsIComponentManagerObsolete));
|
||||
PyObject *path = MakeInterfaceParam(aPath, &NS_GET_IID(nsIFile));
|
||||
PyObject *cm = Py_nsISupports::PyObjectFromInterface(aCompMgr, NS_GET_IID(nsIComponentManagerObsolete), PR_TRUE);
|
||||
PyObject *path = Py_nsISupports::PyObjectFromInterface(aPath, NS_GET_IID(nsIFile), PR_TRUE);
|
||||
const char *methodName = "unregisterSelf";
|
||||
nsresult nr = InvokeNativeViaPolicy(methodName, NULL, "OOz", cm, path, registryLocation);
|
||||
Py_XDECREF(cm);
|
||||
|
@ -127,7 +127,8 @@ PyG_nsIModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
|||
NS_PRECONDITION(aCompMgr, "null pointer");
|
||||
NS_PRECONDITION(okToUnload, "null pointer");
|
||||
CEnterLeavePython _celp;
|
||||
PyObject *cm = MakeInterfaceParam(aCompMgr, &NS_GET_IID(nsIComponentManagerObsolete));
|
||||
// we are shutting down - don't ask for a nice wrapped object.
|
||||
PyObject *cm = Py_nsISupports::PyObjectFromInterface(aCompMgr, NS_GET_IID(nsIComponentManagerObsolete), PR_TRUE, PR_FALSE);
|
||||
const char *methodName = "canUnload";
|
||||
PyObject *ret = NULL;
|
||||
nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "O", cm);
|
||||
|
@ -183,8 +184,8 @@ NS_IMETHODIMP PyG_nsIComponentLoader::Init(nsIComponentManager *aCompMgr, nsISup
|
|||
{
|
||||
CEnterLeavePython _celp;
|
||||
const char *methodName = "init";
|
||||
PyObject *c = MakeInterfaceParam(aCompMgr, &NS_GET_IID(nsIComponentManagerObsolete));
|
||||
PyObject *r = MakeInterfaceParam(aRegistry, &NS_GET_IID(nsISupports));
|
||||
PyObject *c = Py_nsISupports::PyObjectFromInterface(aCompMgr, NS_GET_IID(nsIComponentManagerObsolete), 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);
|
||||
|
@ -214,7 +215,7 @@ NS_IMETHODIMP PyG_nsIComponentLoader::AutoRegisterComponents(PRInt32 aWhen, nsIF
|
|||
{
|
||||
CEnterLeavePython _celp;
|
||||
const char *methodName = "autoRegisterComponents";
|
||||
PyObject *c = MakeInterfaceParam(aDirectory, &NS_GET_IID(nsIFile));
|
||||
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;
|
||||
|
@ -226,7 +227,7 @@ NS_IMETHODIMP PyG_nsIComponentLoader::AutoRegisterComponent(PRInt32 aWhen, nsIFi
|
|||
CEnterLeavePython _celp;
|
||||
const char *methodName = "autoRegisterComponent";
|
||||
PyObject *ret = NULL;
|
||||
PyObject *c = MakeInterfaceParam(aComponent, &NS_GET_IID(nsIFile));
|
||||
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)) {
|
||||
|
@ -244,7 +245,7 @@ NS_IMETHODIMP PyG_nsIComponentLoader::AutoUnregisterComponent(PRInt32 aWhen, nsI
|
|||
CEnterLeavePython _celp;
|
||||
const char *methodName = "autoUnregisterComponent";
|
||||
PyObject *ret = NULL;
|
||||
PyObject *c = MakeInterfaceParam(aComponent, &NS_GET_IID(nsIFile));
|
||||
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)) {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -99,7 +99,7 @@ done:
|
|||
// good error reporting is critical for users to know WTF
|
||||
// is going on - especially with TypeErrors etc in their
|
||||
// return values (ie, after the Python code has successfully
|
||||
// existed, but we encountered errors unpacking their
|
||||
// exited, but we encountered errors unpacking the
|
||||
// result values for the COM caller - there is literally no
|
||||
// way to catch these exceptions from Python code, as their
|
||||
// is no Python function on the call-stack)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* Portions created by ActiveState Tool Corp. are Copyright (C) 2001
|
||||
* ActiveState Tool Corp. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Mark Hammond <MarkH@ActiveState.com> (original author)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -111,7 +111,7 @@ Py_nsIClassInfo::getattr(const char *name)
|
|||
Py_END_ALLOW_THREADS;
|
||||
GETATTR_CHECK_RESULT(nr);
|
||||
ret = MakeStringOrNone(str_ret);
|
||||
nsAllocator::Free(str_ret);
|
||||
nsMemory::Free(str_ret);
|
||||
} else if (strcmp(name, "classDescription")==0) {
|
||||
char *str_ret;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
|
@ -119,7 +119,7 @@ Py_nsIClassInfo::getattr(const char *name)
|
|||
Py_END_ALLOW_THREADS;
|
||||
GETATTR_CHECK_RESULT(nr);
|
||||
ret = MakeStringOrNone(str_ret);
|
||||
nsAllocator::Free(str_ret);
|
||||
nsMemory::Free(str_ret);
|
||||
} else if (strcmp(name, "classID")==0) {
|
||||
nsIID *iid;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
|
@ -127,7 +127,7 @@ Py_nsIClassInfo::getattr(const char *name)
|
|||
Py_END_ALLOW_THREADS;
|
||||
GETATTR_CHECK_RESULT(nr);
|
||||
ret = Py_nsIID::PyObjectFromIID(*iid);
|
||||
nsAllocator::Free(iid);
|
||||
nsMemory::Free(iid);
|
||||
} else if (strcmp(name, "implementationLanguage")==0) {
|
||||
PRUint32 i;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -118,8 +118,8 @@ static PyObject *PyCLSIDToContractID(PyObject *self, PyObject *args)
|
|||
PyObject *ob_pid = PyString_FromString(ret_pid);
|
||||
PyObject *ob_class = PyString_FromString(ret_class);
|
||||
PyObject *ret = Py_BuildValue("OO", ob_pid, ob_class);
|
||||
nsAllocator::Free(ret_pid);
|
||||
nsAllocator::Free(ret_class);
|
||||
nsMemory::Free(ret_pid);
|
||||
nsMemory::Free(ret_class);
|
||||
Py_XDECREF(ob_pid);
|
||||
Py_XDECREF(ob_class);
|
||||
return ret;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -81,7 +81,7 @@ Py_nsIID::IIDFromPyObject(PyObject *ob, nsIID *pRet) {
|
|||
PRBool ok = PR_TRUE;
|
||||
nsIID iid;
|
||||
if (ob==NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "The object is invalid!");
|
||||
PyErr_SetString(PyExc_RuntimeError, "The IID object is invalid!");
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (PyString_Check(ob)) {
|
||||
|
@ -161,7 +161,7 @@ Py_nsIID::PyTypeMethod_getattr(PyObject *self, char *name)
|
|||
PyObject *ret;
|
||||
if (iid_repr != nsnull) {
|
||||
ret = PyString_FromString(iid_repr);
|
||||
nsAllocator::Free(iid_repr);
|
||||
nsMemory::Free(iid_repr);
|
||||
} else
|
||||
ret = PyString_FromString("<cant get IID info!>");
|
||||
return ret;
|
||||
|
@ -184,7 +184,7 @@ Py_nsIID::PyTypeMethod_repr(PyObject *self)
|
|||
char buf[256];
|
||||
char *sziid = s_iid->m_iid.ToString();
|
||||
sprintf(buf, "_xpcom.IID('%s')", sziid);
|
||||
nsAllocator::Free(sziid);
|
||||
nsMemory::Free(sziid);
|
||||
return PyString_FromString(buf);
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ Py_nsIID::PyTypeMethod_str(PyObject *self)
|
|||
Py_nsIID *s_iid = (Py_nsIID *)self;
|
||||
char *sziid = s_iid->m_iid.ToString();
|
||||
PyObject *ret = PyString_FromString(sziid);
|
||||
nsAllocator::Free(sziid);
|
||||
nsMemory::Free(sziid);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -72,7 +72,7 @@ static PyObject *DoPyRead_Buffer(nsIInputStream *pI, PyObject *obBuffer, PRUint3
|
|||
|
||||
static PyObject *DoPyRead_Size(nsIInputStream *pI, PRUint32 n)
|
||||
{
|
||||
if (n==-1) {
|
||||
if (n==(PRUint32)-1) {
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->Available(&n);
|
||||
|
@ -80,7 +80,7 @@ static PyObject *DoPyRead_Size(nsIInputStream *pI, PRUint32 n)
|
|||
if (NS_FAILED(r))
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
}
|
||||
char *buf = (char *)nsAllocator::Alloc(n);
|
||||
char *buf = (char *)nsMemory::Alloc(n);
|
||||
if (buf==NULL) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
|
@ -108,7 +108,7 @@ static PyObject *DoPyRead_Size(nsIInputStream *pI, PRUint32 n)
|
|||
}
|
||||
} else
|
||||
PyXPCOM_BuildPyException(r);
|
||||
nsAllocator::Free(buf);
|
||||
nsMemory::Free(buf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -57,7 +57,7 @@ static PyObject *PyGetName(PyObject *self, PyObject *args)
|
|||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
PyObject *ret = PyString_FromString(name);
|
||||
nsAllocator::Free(name);
|
||||
nsMemory::Free(name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ static PyObject *PyGetIID(PyObject *self, PyObject *args)
|
|||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
PyObject *ret = Py_nsIID::PyObjectFromIID(*iid_ret);
|
||||
nsAllocator::Free(iid_ret);
|
||||
nsMemory::Free(iid_ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -117,7 +117,7 @@ static PyObject *PyGetNameForIID(PyObject *self, PyObject *args)
|
|||
return PyXPCOM_BuildPyException(r);
|
||||
|
||||
PyObject *ret = PyString_FromString(ret_name);
|
||||
nsAllocator::Free(ret_name);
|
||||
nsMemory::Free(ret_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ static PyObject *PyGetIIDForName(PyObject *self, PyObject *args)
|
|||
return PyXPCOM_BuildPyException(r);
|
||||
|
||||
PyObject *ret = Py_nsIID::PyObjectFromIID(*iid_ret);
|
||||
nsAllocator::Free(iid_ret);
|
||||
nsMemory::Free(iid_ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ static PyObject *PyFetchBlock(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
memset(fetched, 0, sizeof(nsISupports *) * n_wanted);
|
||||
nsresult r;
|
||||
nsresult r = NS_OK;
|
||||
PRBool more;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
for (;n_fetched<n_wanted;) {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -120,51 +120,11 @@ Py_nsISupports::Constructor(nsISupports *pInitObj, const nsIID &iid)
|
|||
type);
|
||||
}
|
||||
|
||||
/*static*/PRBool
|
||||
Py_nsISupports::InterfaceFromPyObject(PyObject *ob,
|
||||
const nsIID &iid,
|
||||
nsISupports **ppv,
|
||||
PRBool bNoneOK,
|
||||
PRBool bTryAutoWrap /* = PR_TRUE */)
|
||||
PRBool
|
||||
Py_nsISupports::InterfaceFromPyISupports(PyObject *ob,
|
||||
const nsIID &iid,
|
||||
nsISupports **ppv)
|
||||
{
|
||||
if ( ob == NULL )
|
||||
{
|
||||
// don't overwrite an error message
|
||||
if ( !PyErr_Occurred() )
|
||||
PyErr_SetString(PyExc_TypeError, "The Python object is invalid");
|
||||
return PR_FALSE;
|
||||
}
|
||||
if ( ob == Py_None )
|
||||
{
|
||||
if ( bNoneOK )
|
||||
{
|
||||
*ppv = NULL;
|
||||
return PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "None is not a invalid interface object in this context");
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (PyInstance_Check(ob)) {
|
||||
// Get the _comobj_ attribute
|
||||
PyObject *use_ob = PyObject_GetAttrString(ob, "_comobj_");
|
||||
if (use_ob==NULL) {
|
||||
PyErr_Clear();
|
||||
if (bTryAutoWrap)
|
||||
// Try and auto-wrap it - errors will leave Py exception set,
|
||||
return PyXPCOM_XPTStub::AutoWrapPythonInstance(ob, iid, ppv);
|
||||
PyErr_SetString(PyExc_TypeError, "The Python instance can not be converted to an XP COM object");
|
||||
return PR_FALSE;
|
||||
} else
|
||||
ob = use_ob;
|
||||
|
||||
} else {
|
||||
Py_XINCREF(ob);
|
||||
}
|
||||
|
||||
nsISupports *pis;
|
||||
PRBool rc = PR_FALSE;
|
||||
if ( !Check(ob) )
|
||||
|
@ -204,13 +164,82 @@ Py_nsISupports::InterfaceFromPyObject(PyObject *ob,
|
|||
/* note: the QI added a ref for the return value */
|
||||
}
|
||||
}
|
||||
|
||||
rc = PR_TRUE;
|
||||
done:
|
||||
Py_XDECREF(ob);
|
||||
return rc;
|
||||
}
|
||||
|
||||
PRBool
|
||||
Py_nsISupports::InterfaceFromPyObject(PyObject *ob,
|
||||
const nsIID &iid,
|
||||
nsISupports **ppv,
|
||||
PRBool bNoneOK,
|
||||
PRBool bTryAutoWrap /* = PR_TRUE */)
|
||||
{
|
||||
if ( ob == NULL )
|
||||
{
|
||||
// don't overwrite an error message
|
||||
if ( !PyErr_Occurred() )
|
||||
PyErr_SetString(PyExc_TypeError, "The Python object is invalid");
|
||||
return PR_FALSE;
|
||||
}
|
||||
if ( ob == Py_None )
|
||||
{
|
||||
if ( bNoneOK )
|
||||
{
|
||||
*ppv = NULL;
|
||||
return PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "None is not a invalid interface object in this context");
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// support nsIVariant
|
||||
if (iid.Equals(NS_GET_IID(nsIVariant)) || iid.Equals(NS_GET_IID(nsIWritableVariant))) {
|
||||
// Check it is not already nsIVariant
|
||||
if (PyInstance_Check(ob)) {
|
||||
PyObject *sub_ob = PyObject_GetAttrString(ob, "_comobj_");
|
||||
if (sub_ob==NULL) {
|
||||
PyErr_Clear();
|
||||
} else {
|
||||
if (InterfaceFromPyISupports(sub_ob, iid, ppv)) {
|
||||
Py_DECREF(sub_ob);
|
||||
return PR_TRUE;
|
||||
}
|
||||
PyErr_Clear();
|
||||
Py_DECREF(sub_ob);
|
||||
}
|
||||
}
|
||||
*ppv = PyObject_AsVariant(ob);
|
||||
return *ppv != NULL;
|
||||
}
|
||||
// end of variant support.
|
||||
|
||||
if (PyInstance_Check(ob)) {
|
||||
// Get the _comobj_ attribute
|
||||
PyObject *use_ob = PyObject_GetAttrString(ob, "_comobj_");
|
||||
if (use_ob==NULL) {
|
||||
PyErr_Clear();
|
||||
if (bTryAutoWrap)
|
||||
// Try and auto-wrap it - errors will leave Py exception set,
|
||||
return PyXPCOM_XPTStub::AutoWrapPythonInstance(ob, iid, ppv);
|
||||
PyErr_SetString(PyExc_TypeError, "The Python instance can not be converted to an XPCOM object");
|
||||
return PR_FALSE;
|
||||
} else
|
||||
ob = use_ob;
|
||||
|
||||
} else {
|
||||
Py_INCREF(ob);
|
||||
}
|
||||
PRBool rc = InterfaceFromPyISupports(ob, iid, ppv);
|
||||
Py_DECREF(ob);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
// Interface conversions
|
||||
/*static*/void
|
||||
Py_nsISupports::RegisterInterface( const nsIID &iid, PyTypeObject *t)
|
||||
|
@ -226,6 +255,28 @@ Py_nsISupports::RegisterInterface( const nsIID &iid, PyTypeObject *t)
|
|||
}
|
||||
}
|
||||
|
||||
/*static */PyObject *
|
||||
Py_nsISupports::PyObjectFromInterfaceOrVariant(nsISupports *pis,
|
||||
const nsIID &riid,
|
||||
PRBool bAddRef,
|
||||
PRBool bMakeNicePyObject /* = PR_TRUE */)
|
||||
{
|
||||
// Quick exit.
|
||||
if (pis==NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
if (riid.Equals(NS_GET_IID(nsIVariant))) {
|
||||
PyObject *ret = PyObject_FromVariant((nsIVariant *)pis);
|
||||
// If we were asked not to add a reference, then there
|
||||
// will be a spare reference on pis() - remove it.
|
||||
if (!bAddRef)
|
||||
pis->Release();
|
||||
return ret;
|
||||
}
|
||||
return PyObjectFromInterface(pis, riid, bAddRef, bMakeNicePyObject);
|
||||
}
|
||||
|
||||
/*static */PyObject *
|
||||
Py_nsISupports::PyObjectFromInterface(nsISupports *pis,
|
||||
const nsIID &riid,
|
||||
|
@ -241,7 +292,6 @@ Py_nsISupports::PyObjectFromInterface(nsISupports *pis,
|
|||
// If the IID is for nsISupports, dont bother with
|
||||
// a map lookup as we know the type!
|
||||
if (!riid.Equals(NS_GET_IID(nsISupports))) {
|
||||
|
||||
// Look up the map
|
||||
PyObject *obiid = Py_nsIID::PyObjectFromIID(riid);
|
||||
if (!obiid) return NULL;
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* 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 Mark Hammond are Copyright (C) 2000, 2001
|
||||
* Mark Hammond. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
// This code is part of the XPCOM extensions for Python.
|
||||
//
|
||||
// Written April 2002
|
||||
|
||||
#include "PyXPCOM_std.h"
|
||||
#include "nsIVariant.h"
|
||||
|
||||
// Prevents us needing to use an nsIScriptableInputStream
|
||||
// (and even that can't read binary data!!!)
|
||||
|
||||
static nsIVariant *GetI(PyObject *self) {
|
||||
nsIID iid = NS_GET_IID(nsIVariant);
|
||||
|
||||
if (!Py_nsISupports::Check(self, iid)) {
|
||||
PyErr_SetString(PyExc_TypeError, "This object is not the correct interface");
|
||||
return NULL;
|
||||
}
|
||||
return (nsIVariant *)Py_nsISupports::GetI(self);
|
||||
}
|
||||
|
||||
static PyObject *MyBool( PRBool v) {
|
||||
PyObject *ret = v ? Py_True : Py_False;
|
||||
Py_INCREF(ret);
|
||||
return ret;
|
||||
}
|
||||
static PyObject *MyChar( char c) {
|
||||
return PyString_FromStringAndSize(&c, 1);
|
||||
}
|
||||
static PyObject *MyWChar( wchar_t c) {
|
||||
return PyUnicode_FromWideChar(&c, 1);
|
||||
}
|
||||
static PyObject *MyUnicode( PRUnichar *p) {
|
||||
return PyUnicode_FromUnicode(p, nsCRT::strlen(p));
|
||||
}
|
||||
static PyObject *MyISupports( nsISupports *p) {
|
||||
return Py_nsISupports::PyObjectFromInterface(p, NS_GET_IID(nsISupports), PR_FALSE);
|
||||
}
|
||||
|
||||
#define GET_SIMPLE(Type, FuncGet, FuncConvert) \
|
||||
static PyObject *FuncGet(PyObject *self, PyObject *args) { \
|
||||
nsIVariant *pI = GetI(self); \
|
||||
if (pI==NULL) return NULL; \
|
||||
if (!PyArg_ParseTuple(args, ":" #FuncGet)) return NULL; \
|
||||
Type t; \
|
||||
nsresult nr = pI->FuncGet(&t); \
|
||||
if (NS_FAILED(nr)) return PyXPCOM_BuildPyException(nr); \
|
||||
return FuncConvert(t); \
|
||||
}
|
||||
|
||||
#define GET_ALLOCATED(Type, FuncGet, FuncConvert, FuncFree) \
|
||||
static PyObject *FuncGet(PyObject *self, PyObject *args) { \
|
||||
nsIVariant *pI = GetI(self); \
|
||||
if (pI==NULL) return NULL; \
|
||||
if (!PyArg_ParseTuple(args, ":" #FuncGet)) return NULL; \
|
||||
Type t; \
|
||||
nsresult nr = pI->FuncGet(&t); \
|
||||
if (NS_FAILED(nr)) return PyXPCOM_BuildPyException(nr); \
|
||||
PyObject *ret = FuncConvert(t); \
|
||||
FuncFree(t); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define GET_ALLOCATED_SIZE(Type, FuncGet, FuncConvert, FuncFree) \
|
||||
static PyObject *FuncGet(PyObject *self, PyObject *args) { \
|
||||
nsIVariant *pI = GetI(self); \
|
||||
if (pI==NULL) return NULL; \
|
||||
if (!PyArg_ParseTuple(args, ":" #FuncGet)) return NULL; \
|
||||
Type t; PRUint32 size; \
|
||||
nsresult nr = pI->FuncGet(&size, &t); \
|
||||
if (NS_FAILED(nr)) return PyXPCOM_BuildPyException(nr); \
|
||||
PyObject *ret = FuncConvert(t, size); \
|
||||
FuncFree(t); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
GET_SIMPLE(PRUint8, GetAsInt8, PyInt_FromLong);
|
||||
GET_SIMPLE(PRUint8, GetAsUint8, PyInt_FromLong);
|
||||
GET_SIMPLE(PRInt16, GetAsInt16, PyInt_FromLong);
|
||||
GET_SIMPLE(PRUint16, GetAsUint16, PyInt_FromLong);
|
||||
GET_SIMPLE(PRInt32, GetAsInt32, PyInt_FromLong);
|
||||
GET_SIMPLE(PRUint32, GetAsUint32, PyInt_FromLong);
|
||||
GET_SIMPLE(PRInt64, GetAsInt64, PyLong_FromLongLong);
|
||||
GET_SIMPLE(PRUint64, GetAsUint64, PyLong_FromUnsignedLongLong);
|
||||
GET_SIMPLE(float, GetAsFloat, PyFloat_FromDouble);
|
||||
GET_SIMPLE(double, GetAsDouble, PyFloat_FromDouble);
|
||||
GET_SIMPLE(PRBool, GetAsBool, MyBool);
|
||||
GET_SIMPLE(char, GetAsChar, MyChar);
|
||||
GET_SIMPLE(PRUnichar, GetAsWChar, MyWChar);
|
||||
GET_SIMPLE(nsISupports *, GetAsISupports, MyISupports);
|
||||
GET_SIMPLE(nsIID, GetAsID, Py_nsIID::PyObjectFromIID);
|
||||
|
||||
GET_ALLOCATED(char *, GetAsString, PyString_FromString, nsMemory::Free);
|
||||
GET_ALLOCATED(PRUnichar *, GetAsWString, MyUnicode, nsMemory::Free);
|
||||
GET_ALLOCATED_SIZE(char *, GetAsStringWithSize, PyString_FromStringAndSize, nsMemory::Free);
|
||||
GET_ALLOCATED_SIZE(PRUnichar *, GetAsWStringWithSize, PyUnicode_FromUnicode, nsMemory::Free);
|
||||
|
||||
static PyObject *GetAsInterface(PyObject *self, PyObject *args) {
|
||||
nsIVariant *pI = GetI(self);
|
||||
if (pI==NULL) return NULL;
|
||||
if (!PyArg_ParseTuple(args, ":GetAsInterface")) return NULL;
|
||||
nsISupports *p;
|
||||
nsIID *iid;
|
||||
nsresult nr = pI->GetAsInterface(&iid, (void **)&p);
|
||||
if (NS_FAILED(nr)) return PyXPCOM_BuildPyException(nr);
|
||||
return Py_nsISupports::PyObjectFromInterface(p, *iid, PR_FALSE);
|
||||
}
|
||||
|
||||
extern PyObject *PyObject_FromVariantArray( nsIVariant *v);
|
||||
|
||||
static PyObject *GetAsArray(PyObject *self, PyObject *args) {
|
||||
nsIVariant *pI = GetI(self);
|
||||
if (pI==NULL) return NULL;
|
||||
if (!PyArg_ParseTuple(args, ":GetAsArray")) return NULL;
|
||||
return PyObject_FromVariantArray(pI);
|
||||
}
|
||||
|
||||
struct PyMethodDef
|
||||
PyMethods_IVariant[] =
|
||||
{
|
||||
{ "getAsInt8", GetAsInt8, 1},
|
||||
{ "getAsUint8", GetAsUint8, 1},
|
||||
{ "getAsInt16", GetAsInt16, 1},
|
||||
{ "getAsUint16", GetAsUint16, 1},
|
||||
{ "getAsInt32", GetAsInt32, 1},
|
||||
{ "getAsUint32", GetAsUint32, 1},
|
||||
{ "getAsInt64", GetAsInt64, 1},
|
||||
{ "getAsUint64", GetAsUint64, 1},
|
||||
{ "getAsFloat", GetAsFloat, 1},
|
||||
{ "getAsDouble", GetAsDouble, 1},
|
||||
{ "getAsBool", GetAsBool, 1},
|
||||
{ "getAsChar", GetAsChar, 1},
|
||||
{ "getAsWChar", GetAsWChar, 1},
|
||||
{ "getAsString", GetAsString, 1},
|
||||
{ "getAsWString", GetAsWString, 1},
|
||||
{ "getAsStringWithSize", GetAsStringWithSize, 1},
|
||||
{ "getAsWStringWithSize", GetAsWStringWithSize, 1},
|
||||
{ "getAsISupports", GetAsISupports, 1},
|
||||
{ "getAsInterface", GetAsInterface, 1},
|
||||
{ "getAsArray", GetAsArray, 1},
|
||||
{ "getAsID", GetAsID, 1},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
PyObject *
|
||||
Py_nsIVariant::getattr(const char *name)
|
||||
{
|
||||
|
||||
PyObject *ret = NULL;
|
||||
if (strcmp(name, "dataType")==0) {
|
||||
nsIVariant *pI = ::GetI(this);
|
||||
if (pI) {
|
||||
PRUint16 dt;
|
||||
nsresult nr = pI->GetDataType(&dt);
|
||||
if (NS_FAILED(nr)) return PyXPCOM_BuildPyException(nr);
|
||||
ret = PyInt_FromLong(dt);
|
||||
}
|
||||
} else {
|
||||
ret = Py_nsISupports::getattr(name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
Py_nsIVariant::setattr(const char *name, PyObject *v)
|
||||
{
|
||||
return Py_nsISupports::setattr(name, v);
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -176,9 +176,14 @@ public:
|
|||
// see the correct xpcom.client.Interface object even when calling
|
||||
// xpcom function directly.
|
||||
static PyObject *PyObjectFromInterface(nsISupports *ps,
|
||||
const nsIID &iid,
|
||||
PRBool bAddRef,
|
||||
PRBool bMakeNicePyObject = PR_TRUE);
|
||||
const nsIID &iid,
|
||||
PRBool bAddRef,
|
||||
PRBool bMakeNicePyObject = PR_TRUE);
|
||||
|
||||
static PyObject *PyObjectFromInterfaceOrVariant(nsISupports *ps,
|
||||
const nsIID &iid,
|
||||
PRBool bAddRef,
|
||||
PRBool bMakeNicePyObject = PR_TRUE);
|
||||
|
||||
// Given a Python object that is a registered COM type, return a given
|
||||
// interface pointer on its underlying object, with a NEW REFERENCE ADDED.
|
||||
|
@ -187,6 +192,8 @@ public:
|
|||
// provided to stop accidental recursion should the object returned by
|
||||
// the wrap process itself be in instance (where it should already be
|
||||
// a COM object.
|
||||
// If |iid|==nsIVariant, then arbitary Python objects will be wrapped
|
||||
// in an nsIVariant.
|
||||
static PRBool InterfaceFromPyObject(
|
||||
PyObject *ob,
|
||||
const nsIID &iid,
|
||||
|
@ -194,6 +201,13 @@ public:
|
|||
PRBool bNoneOK,
|
||||
PRBool bTryAutoWrap = PR_TRUE);
|
||||
|
||||
// Given a Py_nsISupports, return an interface.
|
||||
// Object *must* be Py_nsISupports - there is no
|
||||
// "autowrap", no "None" support, etc
|
||||
static PRBool InterfaceFromPyISupports(PyObject *ob,
|
||||
const nsIID &iid,
|
||||
nsISupports **ppv);
|
||||
|
||||
static Py_nsISupports *Constructor(nsISupports *pInitObj, const nsIID &iid);
|
||||
// The Python methods
|
||||
static PyObject *QueryInterface(PyObject *self, PyObject *args);
|
||||
|
@ -459,6 +473,7 @@ private:
|
|||
PRUint32 GetSizeIs( int var_index, PRBool is_arg1);
|
||||
PRBool SetSizeIs( int var_index, PRBool is_arg1, PRUint32 new_size);
|
||||
PRBool CanSetSizeIs( int var_index, PRBool is_arg1 );
|
||||
nsIInterfaceInfo *GetInterfaceInfo(); // NOTE: no ref count on result.
|
||||
|
||||
|
||||
nsXPTCMiniVariant* m_params;
|
||||
|
@ -466,7 +481,7 @@ private:
|
|||
int m_method_index;
|
||||
PythonTypeDescriptor *m_python_type_desc_array;
|
||||
int m_num_type_descs;
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfo> m_interface_info;
|
||||
};
|
||||
|
||||
// Misc converters.
|
||||
|
@ -478,6 +493,8 @@ PyObject *PyObject_FromXPTParamDescriptor( const XPTParamDescriptor *d);
|
|||
PyObject *PyObject_FromXPTMethodDescriptor( const XPTMethodDescriptor *d);
|
||||
PyObject *PyObject_FromXPTConstant( const XPTConstDescriptor *d);
|
||||
|
||||
nsIVariant *PyObject_AsVariant( PyObject *ob);
|
||||
PyObject *PyObject_FromVariant( nsIVariant *v);
|
||||
|
||||
// DLL reference counting functions.
|
||||
// Although we maintain the count, we never actually
|
||||
|
@ -669,5 +686,6 @@ PyXPCOM_INTERFACE_DECLARE(Py_nsIInterfaceInfo, nsIInterfaceInfo, PyMethods_IInte
|
|||
PyXPCOM_INTERFACE_DECLARE(Py_nsIServiceManager, nsIServiceManager, PyMethods_IServiceManager)
|
||||
PyXPCOM_INTERFACE_DECLARE(Py_nsIInputStream, nsIInputStream, PyMethods_IInputStream)
|
||||
PyXPCOM_ATTR_INTERFACE_DECLARE(Py_nsIClassInfo, nsIClassInfo, PyMethods_IClassInfo)
|
||||
PyXPCOM_ATTR_INTERFACE_DECLARE(Py_nsIVariant, nsIVariant, PyMethods_IVariant)
|
||||
|
||||
#endif // __PYXPCOM_H__
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIVariant.h"
|
||||
|
||||
|
||||
#include "nsXPIDLString.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -131,7 +131,7 @@ PyXPCOM_TypeObject::Py_repr(PyObject *self)
|
|||
// XXX - need some sort of buffer overflow.
|
||||
char buf[512];
|
||||
sprintf(buf, "<XPCOM object (%s) at 0x%p/0x%p>", iid_repr, self, pis->m_obj);
|
||||
nsAllocator::Free(iid_repr);
|
||||
nsMemory::Free(iid_repr);
|
||||
return PyString_FromString(buf);
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ PyXPCOM_TypeObject::Py_str(PyObject *self)
|
|||
ret = Py_repr(self);
|
||||
else
|
||||
ret = PyString_FromString(val);
|
||||
if (val) nsAllocator::Free(val);
|
||||
if (val) nsMemory::Free(val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -86,7 +86,7 @@ PRBool PyXPCOM_ThreadState_Ensure()
|
|||
if (PyXPCOM_InterpreterState==NULL) {
|
||||
Py_FatalError("Can not setup thread state, as have no interpreter state");
|
||||
}
|
||||
pData = (ThreadData *)nsAllocator::Alloc(sizeof(ThreadData));
|
||||
pData = (ThreadData *)nsMemory::Alloc(sizeof(ThreadData));
|
||||
if (!pData)
|
||||
Py_FatalError("Out of memory allocating thread state.");
|
||||
memset(pData, 0, sizeof(*pData));
|
||||
|
@ -128,7 +128,7 @@ void PyXPCOM_ThreadState_Free()
|
|||
PyThreadState *thisThreadState = pData->ts;
|
||||
PyThreadState_Delete(thisThreadState);
|
||||
PR_SetThreadPrivate(tlsIndex, NULL);
|
||||
nsAllocator::Free(pData);
|
||||
nsMemory::Free(pData);
|
||||
}
|
||||
|
||||
void PyXPCOM_ThreadState_Clear()
|
||||
|
@ -141,7 +141,6 @@ void PyXPCOM_ThreadState_Clear()
|
|||
////////////////////////////////////////////////////////////
|
||||
// Lock/exclusion global functions.
|
||||
//
|
||||
|
||||
void PyXPCOM_AcquireGlobalLock(void)
|
||||
{
|
||||
NS_PRECONDITION(g_lockMain != nsnull, "Cant acquire a NULL lock!");
|
||||
|
@ -187,10 +186,6 @@ void PyXPCOM_DLLRelease(void)
|
|||
PR_AtomicDecrement(&g_cLockCount);
|
||||
}
|
||||
|
||||
static void pyxpcom_construct() __attribute__((constructor));
|
||||
static void pyxpcom_destruct() __attribute__((destructor));
|
||||
|
||||
|
||||
void pyxpcom_construct(void)
|
||||
{
|
||||
PRStatus status;
|
||||
|
@ -212,24 +207,12 @@ void pyxpcom_destruct(void)
|
|||
// TlsFree(tlsIndex);
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
|
||||
extern "C" __declspec(dllexport)
|
||||
BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
switch (dwReason) {
|
||||
case DLL_PROCESS_ATTACH: {
|
||||
pyxpcom_construct();
|
||||
break;
|
||||
}
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
pyxpcom_destruct();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
// Yet another attempt at cross-platform library initialization and finalization.
|
||||
struct DllInitializer {
|
||||
DllInitializer() {
|
||||
pyxpcom_construct();
|
||||
}
|
||||
return TRUE; // ok
|
||||
}
|
||||
#endif // XP_WIN
|
||||
~DllInitializer() {
|
||||
pyxpcom_destruct();
|
||||
}
|
||||
} dll_initializer;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# Portions created by ActiveState are Copyright (C) 2000 ActiveState.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Mark Hammond <MarkH@ActiveState.com>
|
||||
# Contributor(s): Mark Hammond <mhammond@skippinet.com.au>
|
||||
#
|
||||
|
||||
DIRS = \
|
||||
|
@ -52,6 +52,7 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\PyIInterfaceInfoManager.obj \
|
||||
.\$(OBJDIR)\PyISimpleEnumerator.obj \
|
||||
.\$(OBJDIR)\PyISupports.obj \
|
||||
.\$(OBJDIR)\PyIVariant.obj \
|
||||
.\$(OBJDIR)\Pyxpt_info.obj \
|
||||
.\$(OBJDIR)\TypeObject.obj \
|
||||
.\$(OBJDIR)\VariantUtils.obj \
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* 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)
|
||||
* Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -63,6 +63,7 @@ PyXPCOM_INTERFACE_DEFINE(Py_nsISimpleEnumerator, nsISimpleEnumerator, PyMethods_
|
|||
PyXPCOM_INTERFACE_DEFINE(Py_nsIInterfaceInfo, nsIInterfaceInfo, PyMethods_IInterfaceInfo)
|
||||
PyXPCOM_INTERFACE_DEFINE(Py_nsIInputStream, nsIInputStream, PyMethods_IInputStream)
|
||||
PyXPCOM_INTERFACE_DEFINE(Py_nsIClassInfo, nsIClassInfo, PyMethods_IClassInfo)
|
||||
PyXPCOM_INTERFACE_DEFINE(Py_nsIVariant, nsIVariant, PyMethods_IVariant)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// This is the main entry point called by the Python component
|
||||
|
@ -502,7 +503,8 @@ PRBool PyXPCOM_Globals_Ensure()
|
|||
if (end > landmark) *end = '\0';
|
||||
|
||||
nsCOMPtr<nsILocalFile> ns_bin_dir;
|
||||
NS_NewLocalFile(landmark, PR_FALSE, getter_AddRefs(ns_bin_dir));
|
||||
nsCAutoString ns_landmark(landmark);
|
||||
NS_NewLocalFile(ns_landmark, PR_FALSE, getter_AddRefs(ns_bin_dir));
|
||||
nsresult rv = NS_InitXPCOM2(nsnull, ns_bin_dir, nsnull);
|
||||
#else
|
||||
// Elsewhere, Mozilla can find it itself (we hope!)
|
||||
|
@ -594,6 +596,7 @@ init_xpcom() {
|
|||
Py_nsIInterfaceInfo::InitType(dict);
|
||||
Py_nsIInputStream::InitType(dict);
|
||||
Py_nsIClassInfo::InitType(dict);
|
||||
Py_nsIVariant::InitType(dict);
|
||||
|
||||
// yet another
|
||||
{ // temp scope nsIComponentManagerObsolete hack :(
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
// We try to get as many data-types etc exposed, meaning this
|
||||
// doesnt really make a good demo of a "simple component"
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIVariant.idl"
|
||||
|
||||
[scriptable, uuid(1ECAED4F-E4D5-4ee7-ABF0-7D72AE1441D7)]
|
||||
interface nsIPythonTestInterface : nsISupports
|
||||
|
@ -121,6 +122,8 @@ interface nsIPythonTestInterfaceExtra : nsIPythonTestInterface
|
|||
void UpString2(in PRUint32 count,
|
||||
[size_is(count)] in string in_str,
|
||||
[size_is(count)]out string out_str);
|
||||
void CopyUTF8String(in AUTF8String in_str, out AUTF8String out_str);
|
||||
void CopyUTF8String2(in AUTF8String in_str, out AUTF8String out_str);
|
||||
// Test we can get an "out" array with an "in" size (and the size is not used anywhere as a size for an in!)
|
||||
void GetFixedString(in PRUint32 count, [size_is(count)]out string out_str);
|
||||
|
||||
|
@ -154,6 +157,10 @@ interface nsIPythonTestInterfaceExtra : nsIPythonTestInterface
|
|||
void CheckInterfaceArray(in PRUint32 count,
|
||||
[array, size_is(count)] in nsISupports data,
|
||||
[retval] out PRBool all_non_null);
|
||||
void CopyInterfaceArray(in PRUint32 count,
|
||||
[array, size_is(count)] in nsISupports data,
|
||||
[array, size_is(out_count)] out nsISupports out_data,
|
||||
out PRUint32 out_count);
|
||||
void GetInterfaceArray(out PRUint32 count,
|
||||
[array, size_is(count)] out nsISupports data);
|
||||
void ExtendInterfaceArray(inout PRUint32 count,
|
||||
|
@ -181,6 +188,8 @@ interface nsIPythonTestInterfaceExtra : nsIPythonTestInterface
|
|||
void CopyAndDoubleArray(inout PRUint32 count, [array, size_is(count)]in PRInt32 array1, [array, size_is(count)]out PRInt32 array2);
|
||||
// Test our "in-out" count param can be shared as one "in", plus one "in-out" param.
|
||||
void AppendArray(inout PRUint32 count, [array, size_is(count)]in PRInt32 array1, [array, size_is(count)]inout PRInt32 array2);
|
||||
void AppendVariant(in nsIVariant variant, inout nsIVariant result);
|
||||
nsIVariant CopyVariant(in nsIVariant variant);
|
||||
};
|
||||
|
||||
// DOM String support is a "recent" (01/2001) addition to XPCOM. These test
|
||||
|
|
|
@ -217,7 +217,10 @@ class PythonTestComponent:
|
|||
def UpWideString(self, val):
|
||||
return val.upper()
|
||||
UpWideString2 = UpWideString
|
||||
|
||||
def CopyUTF8String(self, v):
|
||||
return v
|
||||
def CopyUTF8String2(self, v):
|
||||
return v.encode("utf8")
|
||||
# Test we can get an "out" array with an "in" size (and the size is not used anywhere as a size for an in!)
|
||||
def GetFixedWideString(self, count):
|
||||
# void GetFixedWideString(in PRUint32 count, [size_is(count)out string out_str);
|
||||
|
@ -251,6 +254,8 @@ class PythonTestComponent:
|
|||
ret = 0
|
||||
break
|
||||
return ret
|
||||
def CopyInterfaceArray(self, a):
|
||||
return a
|
||||
def GetInterfaceArray(self):
|
||||
# void GetInterfaceArray(out PRUint32 count,
|
||||
# [array, size_is(count)] out nsISupports data);
|
||||
|
@ -316,6 +321,26 @@ class PythonTestComponent:
|
|||
if array2 is not None:
|
||||
rc.extend(array2)
|
||||
return rc
|
||||
# Test nsIVariant support
|
||||
def AppendVariant(self, invar, inresult):
|
||||
if type(invar)==type([]):
|
||||
invar_use = invar[0]
|
||||
for v in invar[1:]:
|
||||
invar_use += v
|
||||
else:
|
||||
invar_use = invar
|
||||
if type(inresult)==type([]):
|
||||
inresult_use = inresult[0]
|
||||
for v in inresult[1:]:
|
||||
inresult_use += v
|
||||
else:
|
||||
inresult_use = inresult
|
||||
if inresult_use is None and invar_use is None:
|
||||
return None
|
||||
return inresult_use + invar_use
|
||||
|
||||
def CopyVariant(self, invar):
|
||||
return invar
|
||||
|
||||
# Some tests for the "new" (Feb-2001) DOMString type.
|
||||
def GetDOMStringResult( self, length ):
|
||||
|
|
|
@ -151,7 +151,7 @@ def _doTestRepr(progid, interfaces):
|
|||
ob = xpcom.components.classes[progid].createInstance()
|
||||
except xpcom.COMException, details:
|
||||
print "Could not test repr for progid '%s' - %s" % (progid, details)
|
||||
return false
|
||||
return 0
|
||||
|
||||
ok = 1
|
||||
if repr(ob).find(progid) < 0:
|
||||
|
|
|
@ -79,7 +79,7 @@ def test_method(method, args, expected_results):
|
|||
print "Testing %s%s" % (method.__name__, `args`)
|
||||
ret = method(*args)
|
||||
if ret != expected_results:
|
||||
print_error("calling method %s - expected %s, but got %s" % (method.__name__, expected_results, ret))
|
||||
print_error("calling method %s - expected %r, but got %r" % (method.__name__, expected_results, ret))
|
||||
|
||||
def test_int_method(meth):
|
||||
test_method(meth, (0,0), (0,0,0))
|
||||
|
@ -292,6 +292,15 @@ def test_derived_interface(c, test_flat = 0):
|
|||
test_method(c.UpWideString, (val,), val.upper())
|
||||
test_method(c.UpWideString2, (val,), val.upper())
|
||||
test_method(c.GetFixedWideString, (20,), u"A"*20)
|
||||
val = u"The Euro Symbol is '\u20ac'"
|
||||
test_method(c.CopyUTF8String, ("foo",), "foo")
|
||||
test_method(c.CopyUTF8String, (u"foo",), "foo")
|
||||
test_method(c.CopyUTF8String, (val,), val)
|
||||
test_method(c.CopyUTF8String, (val.encode("utf8"),), val)
|
||||
test_method(c.CopyUTF8String2, ("foo",), "foo")
|
||||
test_method(c.CopyUTF8String2, (u"foo",), "foo")
|
||||
test_method(c.CopyUTF8String2, (val,), val)
|
||||
test_method(c.CopyUTF8String2, (val.encode("utf8"),), val)
|
||||
items = [1,2,3,4,5]
|
||||
test_method(c.MultiplyEachItemInIntegerArray, (3, items,), map(lambda i:i*3, items))
|
||||
|
||||
|
@ -322,6 +331,7 @@ def test_derived_interface(c, test_flat = 0):
|
|||
test_method(c.CheckInterfaceArray, ((c, c),), 1)
|
||||
test_method(c.CheckInterfaceArray, ((c, None),), 0)
|
||||
test_method(c.CheckInterfaceArray, ((),), 1)
|
||||
test_method(c.CopyInterfaceArray, ((c, c),), [c,c])
|
||||
|
||||
test_method(c.GetInterfaceArray, (), [c,c,c, None])
|
||||
test_method(c.ExtendInterfaceArray, ((c,c,c, None),), [c,c,c,None,c,c,c,None] )
|
||||
|
@ -339,6 +349,25 @@ def test_derived_interface(c, test_flat = 0):
|
|||
test_method(c.AppendArray, ([1,2,3],), [1,2,3])
|
||||
test_method(c.AppendArray, ([1,2,3],[4,5,6]), [1,2,3,4,5,6])
|
||||
|
||||
test_method(c.CopyVariant, (None,), None)
|
||||
test_method(c.CopyVariant, (1,), 1)
|
||||
test_method(c.CopyVariant, (1.0,), 1.0)
|
||||
test_method(c.CopyVariant, (-1,), -1)
|
||||
test_method(c.CopyVariant, (sys.maxint+1,), sys.maxint+1)
|
||||
test_method(c.CopyVariant, ("foo",), "foo")
|
||||
test_method(c.CopyVariant, (u"foo",), u"foo")
|
||||
test_method(c.CopyVariant, (c,), c)
|
||||
test_method(c.CopyVariant, (component_iid,), component_iid)
|
||||
test_method(c.CopyVariant, ((1,2),), [1,2])
|
||||
test_method(c.CopyVariant, ((1.2,2.1),), [1.2,2.1])
|
||||
test_method(c.CopyVariant, (("foo","bar"),), ["foo", "bar"])
|
||||
test_method(c.CopyVariant, ((component_iid,component_iid),), [component_iid,component_iid])
|
||||
test_method(c.CopyVariant, ((c,c),), [c,c])
|
||||
test_method(c.AppendVariant, (1,2), 3)
|
||||
test_method(c.AppendVariant, ((1,2),(3,4)), 10)
|
||||
test_method(c.AppendVariant, ("bar", "foo"), "foobar")
|
||||
test_method(c.AppendVariant, (None, None), None)
|
||||
|
||||
if not test_flat:
|
||||
c = c.queryInterface(xpcom.components.interfaces.nsIPythonTestInterfaceDOMStrings)
|
||||
# NULL DOM strings don't work yet.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
# 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)
|
||||
# Contributor(s): Mark Hammond <mhammond@skippinet.com.au> (original author)
|
||||
#
|
||||
|
||||
# Could maybe later have a process that extracted these enums should they change.
|
||||
|
@ -143,6 +143,9 @@ TD_INTERFACE_IS_TYPE = 19
|
|||
TD_ARRAY = 20
|
||||
TD_PSTRING_SIZE_IS = 21
|
||||
TD_PWSTRING_SIZE_IS = 22
|
||||
TD_UTF8STRING = 23
|
||||
TD_CSTRING = 24
|
||||
TD_ASTRING = 25
|
||||
|
||||
# From xpt_struct.h
|
||||
XPT_TDP_POINTER = 0x80
|
||||
|
@ -214,3 +217,36 @@ T_INTERFACE_IS = TD_INTERFACE_IS_TYPE
|
|||
T_ARRAY = TD_ARRAY
|
||||
T_PSTRING_SIZE_IS = TD_PSTRING_SIZE_IS
|
||||
T_PWSTRING_SIZE_IS = TD_PWSTRING_SIZE_IS
|
||||
T_UTF8STRING = TD_UTF8STRING
|
||||
T_CSTRING = TD_CSTRING
|
||||
T_ASTRING = TD_ASTRING
|
||||
|
||||
# from nsIVariant
|
||||
VTYPE_INT8 = 0
|
||||
VTYPE_INT16 = 1
|
||||
VTYPE_INT32 = 2
|
||||
VTYPE_INT64 = 3
|
||||
VTYPE_UINT8 = 4
|
||||
VTYPE_UINT16 = 5
|
||||
VTYPE_UINT32 = 6
|
||||
VTYPE_UINT64 = 7
|
||||
VTYPE_FLOAT = 8
|
||||
VTYPE_DOUBLE = 9
|
||||
VTYPE_BOOL = 10
|
||||
VTYPE_CHAR = 11
|
||||
VTYPE_WCHAR = 12
|
||||
VTYPE_VOID = 13
|
||||
VTYPE_ID = 14
|
||||
VTYPE_DOMSTRING = 15
|
||||
VTYPE_CHAR_STR = 16
|
||||
VTYPE_WCHAR_STR = 17
|
||||
VTYPE_INTERFACE = 18
|
||||
VTYPE_INTERFACE_IS = 19
|
||||
VTYPE_ARRAY = 20
|
||||
VTYPE_STRING_SIZE_IS = 21
|
||||
VTYPE_WSTRING_SIZE_IS = 22
|
||||
VTYPE_UTF8STRING = 23
|
||||
VTYPE_CSTRING = 24
|
||||
VTYPE_ASTRING = 25
|
||||
VTYPE_EMPTY_ARRAY = 254
|
||||
VTYPE_EMPTY = 255
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# ActiveState Tool Corp. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): David Ascher <DavidA@ActiveState.com> (original author)
|
||||
# Mark Hammond <MarkH@ActiveState.com>
|
||||
# Mark Hammond <mhammond@skippinet.com.au>
|
||||
#
|
||||
|
||||
"""
|
||||
|
@ -56,10 +56,15 @@ from xpcom_consts import *
|
|||
class Interface:
|
||||
def __init__(self, iid):
|
||||
iim = xpcom._xpcom.XPTI_GetInterfaceInfoManager()
|
||||
if hasattr(iid, "upper"): # Is it a stringy thing.
|
||||
item = iim.GetInfoForName(iid)
|
||||
else:
|
||||
item = iim.GetInfoForIID(iid)
|
||||
try:
|
||||
if hasattr(iid, "upper"): # Is it a stringy thing.
|
||||
item = iim.GetInfoForName(iid)
|
||||
else:
|
||||
item = iim.GetInfoForIID(iid)
|
||||
except xpcom.COMException:
|
||||
name = getattr(iid, "name", str(iid))
|
||||
print "Failed to get info for IID '%s'" % (name,)
|
||||
raise
|
||||
self.interface_info = item
|
||||
self.namespace = "" # where does this come from?
|
||||
self.methods = Methods(item)
|
||||
|
|
Загрузка…
Ссылка в новой задаче