1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
5 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
6 | * the License. You may obtain a copy of the License at
|
---|
7 | * http://www.mozilla.org/MPL/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is the Python XPCOM language bindings.
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * ActiveState Tool Corp.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2000
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | * Mark Hammond <MarkH@ActiveState.com> (original author)
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | // Pyxpt_info.cpp - wrappers for the xpt_info objects.
|
---|
39 | //
|
---|
40 | // This code is part of the XPCOM extensions for Python.
|
---|
41 | //
|
---|
42 | // Written May 2000 by Mark Hammond.
|
---|
43 | //
|
---|
44 | // Based heavily on the Python COM support, which is
|
---|
45 | // (c) Mark Hammond and Greg Stein.
|
---|
46 | //
|
---|
47 | // (c) 2000, ActiveState corp.
|
---|
48 | #include "PyXPCOM_std.h"
|
---|
49 |
|
---|
50 | PyObject *PyObject_FromXPTType( const nsXPTType *d)
|
---|
51 | {
|
---|
52 | if (d==nsnull) {
|
---|
53 | Py_INCREF(Py_None);
|
---|
54 | return Py_None;
|
---|
55 | }
|
---|
56 | // build an object using the same format as a TypeDescriptor.
|
---|
57 | return Py_BuildValue("bzzz",
|
---|
58 | d->flags,
|
---|
59 | NULL, NULL, NULL);
|
---|
60 | }
|
---|
61 |
|
---|
62 | PyObject *PyObject_FromXPTTypeDescriptor( const XPTTypeDescriptor *d)
|
---|
63 | {
|
---|
64 | if (d==nsnull) {
|
---|
65 | Py_INCREF(Py_None);
|
---|
66 | return Py_None;
|
---|
67 | }
|
---|
68 | return Py_BuildValue("bbbh",
|
---|
69 | d->prefix.flags,
|
---|
70 | d->argnum,
|
---|
71 | d->argnum2,
|
---|
72 | d->type.iface // this is actually a union!
|
---|
73 | );
|
---|
74 | }
|
---|
75 |
|
---|
76 | PyObject *PyObject_FromXPTParamDescriptor( const XPTParamDescriptor *d)
|
---|
77 | {
|
---|
78 | if (d==nsnull) {
|
---|
79 | Py_INCREF(Py_None);
|
---|
80 | return Py_None;
|
---|
81 | }
|
---|
82 | PyObject *ob = PyObject_FromXPTTypeDescriptor(&d->type);
|
---|
83 | PyObject *ret = Py_BuildValue("bO", d->flags, ob);
|
---|
84 | Py_DECREF(ob);
|
---|
85 | return ret;
|
---|
86 | }
|
---|
87 |
|
---|
88 | PyObject *PyObject_FromXPTMethodDescriptor( const XPTMethodDescriptor *d)
|
---|
89 | {
|
---|
90 | if (d==nsnull) {
|
---|
91 | Py_INCREF(Py_None);
|
---|
92 | return Py_None;
|
---|
93 | }
|
---|
94 | PyObject *ob_params = PyTuple_New(d->num_args);
|
---|
95 | if (ob_params==NULL)
|
---|
96 | return NULL;
|
---|
97 | for (int i=0;i<d->num_args;i++)
|
---|
98 | PyTuple_SET_ITEM(ob_params, i, PyObject_FromXPTParamDescriptor(d->params+i));
|
---|
99 | PyObject *ob_ret = PyObject_FromXPTParamDescriptor(d->result);
|
---|
100 | PyObject *ret = Py_BuildValue("bsOO", d->flags, d->name, ob_params, ob_ret);
|
---|
101 | Py_XDECREF(ob_ret);
|
---|
102 | Py_XDECREF(ob_params);
|
---|
103 | return ret;
|
---|
104 | }
|
---|
105 |
|
---|
106 | PyObject *PyObject_FromXPTConstant( const XPTConstDescriptor *c)
|
---|
107 | {
|
---|
108 | if (c==nsnull) {
|
---|
109 | Py_INCREF(Py_None);
|
---|
110 | return Py_None;
|
---|
111 | }
|
---|
112 | PyObject *ob_type = PyObject_FromXPTTypeDescriptor(&c->type);
|
---|
113 | if (ob_type==NULL)
|
---|
114 | return NULL;
|
---|
115 | PyObject *v = NULL;
|
---|
116 | switch (c->type.prefix.flags) {
|
---|
117 | case TD_INT8:
|
---|
118 | v = PyInt_FromLong( c->value.i8 );
|
---|
119 | break;
|
---|
120 | case TD_INT16:
|
---|
121 | v = PyInt_FromLong( c->value.i16 );
|
---|
122 | break;
|
---|
123 | case TD_INT32:
|
---|
124 | v = PyInt_FromLong( c->value.i32 );
|
---|
125 | break;
|
---|
126 | case TD_INT64:
|
---|
127 | v = PyLong_FromLongLong(c->value.i64);
|
---|
128 | break;
|
---|
129 | case TD_UINT8:
|
---|
130 | v = PyInt_FromLong( c->value.ui8 );
|
---|
131 | break;
|
---|
132 | case TD_UINT16:
|
---|
133 | v = PyInt_FromLong( c->value.ui16 );
|
---|
134 | break;
|
---|
135 | case TD_UINT32:
|
---|
136 | v = PyInt_FromLong( c->value.ui32 );
|
---|
137 | break;
|
---|
138 | case TD_UINT64:
|
---|
139 | v = PyLong_FromUnsignedLongLong(c->value.ui64);
|
---|
140 | break;
|
---|
141 | case TD_FLOAT:
|
---|
142 | v = PyFloat_FromDouble(c->value.flt);
|
---|
143 | break;
|
---|
144 | case TD_DOUBLE:
|
---|
145 | v = PyFloat_FromDouble(c->value.dbl);
|
---|
146 | break;
|
---|
147 | case TD_BOOL:
|
---|
148 | v = c->value.bul ? Py_True : Py_False;
|
---|
149 | Py_INCREF(v);
|
---|
150 | break;
|
---|
151 | case TD_CHAR:
|
---|
152 | #if PY_MAJOR_VERSION <= 2
|
---|
153 | v = PyString_FromStringAndSize(&c->value.ch, 1);
|
---|
154 | #else
|
---|
155 | v = PyUnicode_FromStringAndSize(&c->value.ch, 1);
|
---|
156 | #endif
|
---|
157 | break;
|
---|
158 | case TD_WCHAR:
|
---|
159 | v = PyObject_FromNSString((PRUnichar *)&c->value.wch, 1);
|
---|
160 | break;
|
---|
161 | // TD_VOID = 13,
|
---|
162 | case TD_PNSIID:
|
---|
163 | v = Py_nsIID::PyObjectFromIID(*c->value.iid);
|
---|
164 | break;
|
---|
165 | // TD_DOMSTRING = 15,
|
---|
166 | case TD_PSTRING:
|
---|
167 | #if PY_MAJOR_VERSION <= 2
|
---|
168 | v = PyString_FromString(c->value.str);
|
---|
169 | #else
|
---|
170 | v = PyUnicode_FromString(c->value.str);
|
---|
171 | #endif
|
---|
172 | break;
|
---|
173 | case TD_PWSTRING:
|
---|
174 | v = PyObject_FromNSString((PRUnichar *)c->value.wstr, nsCRT::strlen((PRUnichar *)c->value.wstr));
|
---|
175 | break;
|
---|
176 | // TD_INTERFACE_TYPE = 18,
|
---|
177 | // TD_INTERFACE_IS_TYPE = 19,
|
---|
178 | // TD_ARRAY = 20,
|
---|
179 | // TD_PSTRING_SIZE_IS = 21,
|
---|
180 | // TD_PWSTRING_SIZE_IS = 22
|
---|
181 | // TD_UTF8STRING = 23,
|
---|
182 | // TD_CSTRING = 24,
|
---|
183 | // TD_ASTRING = 25
|
---|
184 | default:
|
---|
185 | #if PY_MAJOR_VERSION <= 2
|
---|
186 | v = PyString_FromString("Unknown type code!!");
|
---|
187 | #else
|
---|
188 | v = PyUnicode_FromString("Unknown type code!!");
|
---|
189 | #endif
|
---|
190 | break;
|
---|
191 |
|
---|
192 | }
|
---|
193 | PyObject *ret = Py_BuildValue("sbO", c->name, ob_type, v);
|
---|
194 | Py_DECREF(ob_type);
|
---|
195 | Py_DECREF(v);
|
---|
196 | return ret;
|
---|
197 | }
|
---|