]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/pyfragments.swg
applied patch 1378261
[wxWidgets.git] / wxPython / src / pyfragments.swg
CommitLineData
1b8c7ba6
RD
1
2
214c4fbe
RD
3//----------------------------------------------------------------------
4
5// The standard t_output_helper has been changed to return a list rather than
6// a tuple, we'll replace it with the old implementation here. In SWIG 1.3.27
8f146d6b
RD
7// and earlier it is implemented as a $fragment, so it is only inserted into
8// the modules that need it. For SWIG 1.3.28+ we just need to add a -D on the
9// compile command line to turn on the tuple version of the AppendOuput
10// function.
214c4fbe
RD
11#if SWIG_VERSION < 0x010328
12%fragment("t_output_helper","header")
13%{
14 static PyObject* t_output_helper(PyObject* result, PyObject* obj)
15 {
16 PyObject* o2;
17 PyObject* o3;
18 if (!result) {
19 result = obj;
20 } else if (result == Py_None) {
21 Py_DECREF(result);
22 result = obj;
23 } else {
24 if (!PyTuple_Check(result)) {
25 o2 = result;
26 result = PyTuple_New(1);
27 PyTuple_SET_ITEM(result, 0, o2);
28 }
29 o3 = PyTuple_New(1);
30 PyTuple_SetItem(o3, 0, obj);
31 o2 = result;
32 result = PySequence_Concat(o2, o3);
33 Py_DECREF(o2);
34 Py_DECREF(o3);
35 }
36 return result;
80739955 37 }
80739955
RD
38%}
39
214c4fbe
RD
40#endif
41
42
80739955
RD
43
44
214c4fbe 45//----------------------------------------------------------------------
0190c472
RD
46// These fragments are inserted in modules that need to convert PyObjects to
47// integer values, my versions allow any numeric type to be used, as long as
48// it can be converted to a PyInt. (Specifically, I allow floats where the
49// default SWIG_AsVal_long would just raise an exception.
50//
0190c472 51
214c4fbe 52#if SWIG_VERSION < 0x010328
0190c472
RD
53
54%fragment(SWIG_AsVal_frag(long), "header") {
1b8c7ba6 55SWIGINTERN int
0190c472
RD
56SWIG_AsVal(long)(PyObject* obj, long* val)
57{
58 if (PyNumber_Check(obj)) {
59 if (val) *val = PyInt_AsLong(obj);
60 return 1;
61 }
62 else {
214c4fbe 63 SWIG_Python_TypeError("number", obj);
0190c472
RD
64 }
65 return 0;
66}
67}
68
69
70%fragment(SWIG_AsVal_frag(unsigned long), "header",
71 fragment=SWIG_AsVal_frag(long)) {
1b8c7ba6 72SWIGINTERN int
0190c472
RD
73SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
74{
75 long v = 0;
76 if (SWIG_AsVal_long(obj, &v) && v < 0) {
214c4fbe 77 SWIG_Python_TypeError("unsigned number", obj);
0190c472
RD
78 }
79 else if (val)
80 *val = (unsigned long)v;
81 return 1;
82}
83}
84
85
86%fragment(SWIG_AsVal_frag(double), "header") {
1b8c7ba6 87SWIGINTERN int
0190c472
RD
88SWIG_AsVal(double)(PyObject *obj, double* val)
89{
90 if (PyNumber_Check(obj)) {
91 if (val) *val = PyFloat_AsDouble(obj);
92 return 1;
93 }
94 else {
214c4fbe 95 SWIG_Python_TypeError("number", obj);
0190c472
RD
96 }
97 return 0;
98}
99}
214c4fbe
RD
100
101
102#else // SWIG_VERSION >= 1.3.28
103
104%fragment(SWIG_AsVal_frag(long), "header") {
105SWIGINTERN int
106SWIG_AsVal(long)(PyObject* obj, long* val)
107{
108 if (PyNumber_Check(obj)) {
109 if (val) *val = PyInt_AsLong(obj);
110 return SWIG_OK;
111 }
112 return SWIG_TypeError;
113}
114}
115
116
117%fragment(SWIG_AsVal_frag(unsigned long), "header",
118 fragment=SWIG_AsVal_frag(long)) {
119SWIGINTERN int
120SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
121{
122 long v = 0;
123 if (SWIG_AsVal_long(obj, &v) && v < 0) {
124 return SWIG_TypeError;
125 }
126 else if (val)
127 *val = (unsigned long)v;
128 return SWIG_OK;
129}
130}
131
132
133%fragment(SWIG_AsVal_frag(double), "header") {
134SWIGINTERN int
135SWIG_AsVal(double)(PyObject *obj, double* val)
136{
137 if (PyNumber_Check(obj)) {
138 if (val) *val = PyFloat_AsDouble(obj);
139 return SWIG_OK;
140 }
141 return SWIG_TypeError;
142}
143}
144
145
146#endif // SWIG_VERSION