Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / share / swig / 1.3.26 / python / pyinit.swg
CommitLineData
920dae64
AT
1/* ------------------------------------------------------------
2 * The start of the Python initialization function
3 * ------------------------------------------------------------ */
4
5%insert(init) "swiginit.swg"
6
7%init %{
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13/* Python-specific SWIG API */
14#define SWIG_newvarlink() SWIG_Python_newvarlink()
15#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr)
16#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants)
17
18/* -----------------------------------------------------------------------------
19 * global variable support code.
20 * ----------------------------------------------------------------------------- */
21
22typedef struct swig_globalvar {
23 char *name; /* Name of global variable */
24 PyObject *(*get_attr)(void); /* Return the current value */
25 int (*set_attr)(PyObject *); /* Set the value */
26 struct swig_globalvar *next;
27} swig_globalvar;
28
29typedef struct swig_varlinkobject {
30 PyObject_HEAD
31 swig_globalvar *vars;
32} swig_varlinkobject;
33
34SWIGINTERN PyObject *
35swig_varlink_repr(swig_varlinkobject *v) {
36 v = v;
37 return PyString_FromString("<Swig global variables>");
38}
39
40SWIGINTERN int
41swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags) {
42 swig_globalvar *var;
43 flags = flags;
44 fprintf(fp,"Swig global variables { ");
45 for (var = v->vars; var; var=var->next) {
46 fprintf(fp,"%s", var->name);
47 if (var->next) fprintf(fp,", ");
48 }
49 fprintf(fp," }\n");
50 return 0;
51}
52
53SWIGINTERN PyObject *
54swig_varlink_getattr(swig_varlinkobject *v, char *n) {
55 swig_globalvar *var = v->vars;
56 while (var) {
57 if (strcmp(var->name,n) == 0) {
58 return (*var->get_attr)();
59 }
60 var = var->next;
61 }
62 PyErr_SetString(PyExc_NameError,"Unknown C global variable");
63 return NULL;
64}
65
66SWIGINTERN int
67swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
68 swig_globalvar *var = v->vars;
69 while (var) {
70 if (strcmp(var->name,n) == 0) {
71 return (*var->set_attr)(p);
72 }
73 var = var->next;
74 }
75 PyErr_SetString(PyExc_NameError,"Unknown C global variable");
76 return 1;
77}
78
79SWIGINTERN PyTypeObject*
80swig_varlink_type(void) {
81 static char varlink__doc__[] = "Swig var link object";
82 static PyTypeObject varlink_type
83#if !defined(__cplusplus)
84 ;
85 static int type_init = 0;
86 if (!type_init) {
87 PyTypeObject tmp
88#endif
89 = {
90 PyObject_HEAD_INIT(&PyType_Type)
91 0, /* Number of items in variable part (ob_size) */
92 (char *)"swigvarlink", /* Type name (tp_name) */
93 sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */
94 0, /* Itemsize (tp_itemsize) */
95 0, /* Deallocator (tp_dealloc) */
96 (printfunc) swig_varlink_print, /* Print (tp_print) */
97 (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */
98 (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */
99 0, /* tp_compare */
100 (reprfunc) swig_varlink_repr, /* tp_repr */
101 0, /* tp_as_number */
102 0, /* tp_as_sequence */
103 0, /* tp_as_mapping */
104 0, /* tp_hash */
105 0, /* tp_call */
106 0, /* tp_str */
107 0, /* tp_getattro */
108 0, /* tp_setattro */
109 0, /* tp_as_buffer */
110 0, /* tp_flags */
111 varlink__doc__, /* tp_doc */
112#if PY_VERSION_HEX >= 0x02000000
113 0, /* tp_traverse */
114 0, /* tp_clear */
115#endif
116#if PY_VERSION_HEX >= 0x02010000
117 0, /* tp_richcompare */
118 0, /* tp_weaklistoffset */
119#endif
120#if PY_VERSION_HEX >= 0x02020000
121 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
122#endif
123#if PY_VERSION_HEX >= 0x02030000
124 0, /* tp_del */
125#endif
126#ifdef COUNT_ALLOCS
127 0,0,0,0 /* tp_alloc -> tp_next */
128#endif
129 };
130#if !defined(__cplusplus)
131 varlink_type = tmp;
132 type_init = 1;
133 }
134#endif
135 return &varlink_type;
136}
137
138/* Create a variable linking object for use later */
139SWIGINTERN PyObject *
140SWIG_Python_newvarlink(void) {
141 swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type());
142 if (result) {
143 result->vars = 0;
144 }
145 return ((PyObject*) result);
146}
147
148SWIGINTERN void
149SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
150 swig_varlinkobject *v = (swig_varlinkobject *) p;
151 swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
152 if (gv) {
153 size_t size = strlen(name)+1;
154 gv->name = (char *)malloc(size);
155 if (gv->name) {
156 strncpy(gv->name,name,size);
157 gv->get_attr = get_attr;
158 gv->set_attr = set_attr;
159 gv->next = v->vars;
160 }
161 }
162 v->vars = gv;
163}
164
165/* -----------------------------------------------------------------------------
166 * constants/methods manipulation
167 * ----------------------------------------------------------------------------- */
168
169/* Install Constants */
170SWIGINTERN void
171SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
172 PyObject *obj = 0;
173 size_t i;
174 for (i = 0; constants[i].type; ++i) {
175 switch(constants[i].type) {
176 case SWIG_PY_INT:
177 obj = PyInt_FromLong(constants[i].lvalue);
178 break;
179 case SWIG_PY_FLOAT:
180 obj = PyFloat_FromDouble(constants[i].dvalue);
181 break;
182 case SWIG_PY_STRING:
183 if (constants[i].pvalue) {
184 obj = PyString_FromString((char *) constants[i].pvalue);
185 } else {
186 Py_INCREF(Py_None);
187 obj = Py_None;
188 }
189 break;
190 case SWIG_PY_POINTER:
191 obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
192 break;
193 case SWIG_PY_BINARY:
194 obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
195 break;
196 default:
197 obj = 0;
198 break;
199 }
200 if (obj) {
201 PyDict_SetItemString(d,constants[i].name,obj);
202 Py_DECREF(obj);
203 }
204 }
205}
206
207/* -----------------------------------------------------------------------------*/
208/* Fix SwigMethods to carry the callback ptrs when needed */
209/* -----------------------------------------------------------------------------*/
210
211SWIGINTERN void
212SWIG_Python_FixMethods(PyMethodDef *methods,
213 swig_const_info *const_table,
214 swig_type_info **types,
215 swig_type_info **types_initial) {
216 size_t i;
217 for (i = 0; methods[i].ml_name; ++i) {
218 char *c = methods[i].ml_doc;
219 if (c && (c = strstr(c, "swig_ptr: "))) {
220 int j;
221 swig_const_info *ci = 0;
222 char *name = c + 10;
223 for (j = 0; const_table[j].type; ++j) {
224 if (strncmp(const_table[j].name, name,
225 strlen(const_table[j].name)) == 0) {
226 ci = &(const_table[j]);
227 break;
228 }
229 }
230 if (ci) {
231 size_t shift = (ci->ptype) - types;
232 swig_type_info *ty = types_initial[shift];
233 size_t ldoc = (c - methods[i].ml_doc);
234 size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
235 char *ndoc = (char*)malloc(ldoc + lptr + 10);
236 if (ndoc) {
237 char *buff = ndoc;
238 void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
239 if (ptr) {
240 strncpy(buff, methods[i].ml_doc, ldoc);
241 buff += ldoc;
242 strncpy(buff, "swig_ptr: ", 10);
243 buff += 10;
244 SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
245 methods[i].ml_doc = ndoc;
246 }
247 }
248 }
249 }
250 }
251}
252
253/* -----------------------------------------------------------------------------*
254 * Initialize type list
255 * -----------------------------------------------------------------------------*/
256
257#ifdef __cplusplus
258}
259#endif
260
261/* -----------------------------------------------------------------------------*
262 * Partial Init method
263 * -----------------------------------------------------------------------------*/
264
265#ifdef __cplusplus
266extern "C"
267#endif
268SWIGEXPORT void SWIG_init(void) {
269 static PyObject *SWIG_globals = 0;
270 PyObject *m, *d;
271 if (!SWIG_globals) SWIG_globals = SWIG_newvarlink();
272
273 /* Fix SwigMethods to carry the callback ptrs when needed */
274 SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
275
276 m = Py_InitModule((char *) SWIG_name, SwigMethods);
277 d = PyModule_GetDict(m);
278
279 SWIG_InitializeModule(0);
280 SWIG_InstallConstants(d,swig_const_table);
281%}
282