Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / share / swig / 1.3.26 / python / pyptrtypes.swg
CommitLineData
920dae64
AT
1/*
2 Value typemaps (Type, const Type&) for "Ptr" types, such as swig
3 wrapped classes, that define the AsPtr/From methods
4*/
5
6/* in */
7
8%define PYPTR_IN_TYPEMAP(asptr_meth,pyfrag,Type...)
9 %typemap(in,fragment=pyfrag) Type {
10 Type *ptr = (Type *)0;
11 int res = asptr_meth($input, &ptr);
12 if (!res) {
13 if (!PyErr_Occurred())
14 SWIG_type_error("$basetype", $input);
15 } else if (!ptr) {
16 SWIG_null_ref("$basetype");
17 }
18 if (SWIG_arg_fail($argnum)) SWIG_fail;
19 $1 = *ptr;
20 if (res == SWIG_NEWOBJ) delete ptr;
21 }
22 %typemap(in,fragment=pyfrag) const Type & (int res = 0) {
23 Type *ptr = (Type *)0;
24 res = asptr_meth($input, &ptr);
25 if (!res) {
26 if (!PyErr_Occurred())
27 SWIG_type_error("$basetype", $input);
28 } else if (!ptr) {
29 SWIG_null_ref("$basetype");
30 }
31 if (SWIG_arg_fail($argnum)) SWIG_fail;
32 $1 = ptr;
33 }
34
35 %typemap(freearg) const Type &
36 "if (res$argnum == SWIG_NEWOBJ) delete $1;";
37%enddef
38
39/* varin */
40
41%define PYPTR_VARIN_TYPEMAP(asptr_meth,pyfrag,Type...)
42 %typemap(varin,fragment=pyfrag) Type {
43 Type *ptr = (Type *)0;
44 int res = asptr_meth($input, &ptr);
45 if (!res) {
46 if (!PyErr_Occurred()) {
47 SWIG_type_error("$basetype", $input);
48 }
49 SWIG_append_errmsg(" C/C++ variable '$name'");
50 return 1;
51 } else if (!ptr) {
52 SWIG_null_ref("$basetype");
53 SWIG_append_errmsg(" C/C++ variable '$name'");
54 return 1;
55 }
56 $1 = *ptr;
57 if (res == SWIG_NEWOBJ) delete ptr;
58 }
59%enddef
60
61/* directorout */
62
63%define PYPTR_DIRECTOROUT_TYPEMAP(asptr_meth,pyfrag,Type...)
64 %typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT ($*1_ltype temp) {
65 Type *ptr = 0;
66 int res = $input ? asptr_meth($input, &ptr) : 0;
67 if (!res || !ptr)
68 Swig::DirectorTypeMismatchException::raise("Error converting Python object when using asptr_meth.");
69 temp = *ptr;
70 $result = &temp;
71 if (res == SWIG_NEWOBJ) delete ptr;
72 }
73
74 %typemap(directorout,fragment=pyfrag) Type {
75 Type *ptr = 0;
76 int res = $input ? asptr_meth($input, &ptr) : 0;
77 if (!res || !ptr)
78 Swig::DirectorTypeMismatchException::raise("Error converting Python object when using asptr_meth.");
79 $result = *ptr;
80 if (res == SWIG_NEWOBJ) delete ptr;
81 }
82
83 %typemap(directorout,fragment=pyfrag,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const Type& {
84 Type *ptr = 0;
85 int res = $input ? asptr_meth($input, &ptr) : 0;
86 if (!res || !ptr)
87 Swig::DirectorTypeMismatchException::raise("Error converting Python object when using asptr_meth.");
88 $result = ptr;
89 if (res == SWIG_NEWOBJ) {
90 /* Possible thread/reentrant problem here! */
91 static $*ltype temp = *ptr;
92 $result = &temp;
93 delete ptr;
94 } else {
95 $result = ptr;
96 }
97 }
98
99 %typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
100
101%enddef
102
103/* typecheck */
104
105%define PYPTR_TYPECHECK_TYPEMAP(check,asptr_meth,pyfrag,Type...)
106%typemap(typecheck,precedence=check,fragment=pyfrag)
107 Type, const Type&
108 "$1 = asptr_meth($input, (Type**)(0));";
109%enddef
110
111/*
112 typemap definition for types with AsPtr/From methods
113 */
114
115%define %typemap_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type...)
116 %fragment(SWIG_AsVal_frag(Type),"header",
117 fragment=SWIG_AsPtr_frag(Type)) %{
118 SWIGINTERNINLINE int
119 SWIG_AsVal(Type)(PyObject* obj, Type *val)
120 {
121 Type *v = (Type *)0;
122 int res = SWIG_AsPtr(Type)(obj, &v);
123 if (!res || !v) return 0;
124 if (val) {
125 *val = *v;
126 if (res == SWIG_NEWOBJ) delete v;
127 }
128 return 1;
129 }
130 %}
131 %fragment(SWIG_As_frag(Type),"header",
132 fragment=SWIG_AsVal_frag(Type)) %{
133 SWIGINTERNINLINE Type
134 SWIG_As(Type)(PyObject* obj)
135 {
136 Type v;
137 SWIG_AsVal(Type)(obj, &v);
138 return v;
139 }
140 %}
141 PYPTR_IN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
142 PYPTR_VARIN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
143 PYPTR_DIRECTOROUT_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
144 PYPTR_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsPtrMeth),
145 SWIG_arg(AsPtrFrag), Type);
146 %typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
147
148 PYPTR_INPUT_TYPEMAP(SWIG_arg(CheckCode),SWIG_arg(AsPtrMeth),
149 SWIG_arg(AsPtrFrag),Type);
150 PYVAL_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
151 PYPTR_INOUT_TYPEMAP(Type);
152%enddef
153
154/*
155 typemap for simple swig types with only AsPtr/From methods
156*/
157
158%define %typemap_asptrfromn(CheckCode, Type...)
159%typemap_asptrfrom(SWIG_arg(CheckCode),
160 SWIG_arg(SWIG_AsPtr(Type)),
161 SWIG_arg(SWIG_From(Type)),
162 SWIG_arg(SWIG_AsPtr_frag(Type)),
163 SWIG_arg(SWIG_From_frag(Type)),
164 Type);
165%enddef