Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
PythonIncludes.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 /**
21  *
22  * This file is part of Tulip (www.tulip-software.org)
23  *
24  * Authors: David Auber and the Tulip development Team
25  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
26  *
27  * Tulip is free software; you can redistribute it and/or modify
28  * it under the terms of the GNU Lesser General Public License
29  * as published by the Free Software Foundation, either version 3
30  * of the License, or (at your option) any later version.
31  *
32  * Tulip is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35  * See the GNU General Public License for more details.
36  *
37  */
38 
39 #ifndef PYTHONINCLUDES_H_
40 #define PYTHONINCLUDES_H_
41 
42 // thanks to the VTK project for this patch for Visual Studio in debug mode
43 #if defined(_MSC_VER) && defined(_DEBUG)
44 // Include these low level headers before undefing _DEBUG. Otherwise when doing
45 // a debug build against a release build of python the compiler will end up
46 // including these low level headers without DEBUG enabled, causing it to try
47 // and link release versions of this low level C api.
48 # include <basetsd.h>
49 # include <assert.h>
50 # include <ctype.h>
51 # include <errno.h>
52 # include <io.h>
53 # include <math.h>
54 # include <sal.h>
55 # include <stdarg.h>
56 # include <stddef.h>
57 # include <stdio.h>
58 # include <stdlib.h>
59 # include <string.h>
60 # include <sys/stat.h>
61 # include <time.h>
62 # include <wchar.h>
63 # undef _DEBUG
64 # if _MSC_VER >= 1400
65 # define _CRT_NOFORCE_MANIFEST 1
66 # endif
67 # include <Python.h>
68 # include <frameobject.h>
69 # include <structmember.h>
70 # include <import.h>
71 # include <sip.h>
72 # define _DEBUG
73 # else
74 # include <Python.h>
75 # include <frameobject.h>
76 # include <structmember.h>
77 # include <import.h>
78 # pragma GCC diagnostic push
79 # pragma GCC diagnostic ignored "-pedantic"
80 # include <sip.h>
81 # pragma GCC diagnostic pop
82 # endif
83 
84 static const sipAPIDef *getSipAPI() {
85 #if defined(SIP_USE_PYCAPSULE)
86  return (const sipAPIDef *)PyCapsule_Import("sip._C_API", 0);
87 #else
88  PyObject *sip_module;
89  PyObject *sip_module_dict;
90  PyObject *c_api;
91 
92  /* Import the SIP module. */
93  sip_module = PyImport_ImportModule("sip");
94 
95  if (sip_module == NULL)
96  return NULL;
97 
98  /* Get the module's dictionary. */
99  sip_module_dict = PyModule_GetDict(sip_module);
100 
101  /* Get the "_C_API" attribute. */
102  c_api = PyDict_GetItemString(sip_module_dict, "_C_API");
103 
104  if (c_api == NULL)
105  return NULL;
106 
107  /* Sanity check that it is the right type. */
108  if (!PyCObject_Check(c_api))
109  return NULL;
110 
111  /* Get the actual pointer from the object. */
112  return (const sipAPIDef *)PyCObject_AsVoidPtr(c_api);
113 #endif
114 }
115 
116 static const sipAPIDef *sipAPI = NULL;
117 
118 static void initSipAPI() {
119  if (!sipAPI) {
120  sipAPI = getSipAPI();
121  }
122 }
123 
124 #define sipMalloc sipAPI->api_malloc
125 #define sipFree sipAPI->api_free
126 #define sipBuildResult sipAPI->api_build_result
127 #define sipCallMethod sipAPI->api_call_method
128 #define sipParseResult sipAPI->api_parse_result
129 #define sipParseArgs sipAPI->api_parse_args
130 #define sipParseKwdArgs sipAPI->api_parse_kwd_args
131 #define sipParsePair sipAPI->api_parse_pair
132 #define sipCommonDtor sipAPI->api_common_dtor
133 #define sipConvertFromSequenceIndex sipAPI->api_convert_from_sequence_index
134 #define sipConvertFromVoidPtr sipAPI->api_convert_from_void_ptr
135 #define sipConvertToVoidPtr sipAPI->api_convert_to_void_ptr
136 #define sipAddException sipAPI->api_add_exception
137 #define sipNoFunction sipAPI->api_no_function
138 #define sipNoMethod sipAPI->api_no_method
139 #define sipAbstractMethod sipAPI->api_abstract_method
140 #define sipBadClass sipAPI->api_bad_class
141 #define sipBadCatcherResult sipAPI->api_bad_catcher_result
142 #define sipBadCallableArg sipAPI->api_bad_callable_arg
143 #define sipBadOperatorArg sipAPI->api_bad_operator_arg
144 #define sipTrace sipAPI->api_trace
145 #define sipTransferBack sipAPI->api_transfer_back
146 #define sipTransferTo sipAPI->api_transfer_to
147 #define sipTransferBreak sipAPI->api_transfer_break
148 #define sipSimpleWrapper_Type sipAPI->api_simplewrapper_type
149 #define sipWrapper_Type sipAPI->api_wrapper_type
150 #define sipWrapperType_Type sipAPI->api_wrappertype_type
151 #define sipVoidPtr_Type sipAPI->api_voidptr_type
152 #define sipGetPyObject sipAPI->api_get_pyobject
153 #define sipGetAddress sipAPI->api_get_address
154 #define sipGetCppPtr sipAPI->api_get_cpp_ptr
155 #define sipGetComplexCppPtr sipAPI->api_get_complex_cpp_ptr
156 #define sipIsPyMethod sipAPI->api_is_py_method
157 #define sipCallHook sipAPI->api_call_hook
158 #define sipStartThread sipAPI->api_start_thread
159 #define sipEndThread sipAPI->api_end_thread
160 #define sipConnectRx sipAPI->api_connect_rx
161 #define sipDisconnectRx sipAPI->api_disconnect_rx
162 #define sipRaiseUnknownException sipAPI->api_raise_unknown_exception
163 #define sipRaiseTypeException sipAPI->api_raise_type_exception
164 #define sipBadLengthForSlice sipAPI->api_bad_length_for_slice
165 #define sipAddTypeInstance sipAPI->api_add_type_instance
166 #define sipFreeSipslot sipAPI->api_free_sipslot
167 #define sipSameSlot sipAPI->api_same_slot
168 #define sipPySlotExtend sipAPI->api_pyslot_extend
169 #define sipConvertRx sipAPI->api_convert_rx
170 #define sipAddDelayedDtor sipAPI->api_add_delayed_dtor
171 #define sipCanConvertToType sipAPI->api_can_convert_to_type
172 #define sipConvertToType sipAPI->api_convert_to_type
173 #define sipForceConvertToType sipAPI->api_force_convert_to_type
174 #define sipCanConvertToEnum sipAPI->api_can_convert_to_enum
175 #define sipReleaseType sipAPI->api_release_type
176 #define sipConvertFromType sipAPI->api_convert_from_type
177 #define sipConvertFromNewType sipAPI->api_convert_from_new_type
178 #define sipConvertFromEnum sipAPI->api_convert_from_enum
179 #define sipGetState sipAPI->api_get_state
180 #define sipLong_AsUnsignedLong sipAPI->api_long_as_unsigned_long
181 #define sipExportSymbol sipAPI->api_export_symbol
182 #define sipImportSymbol sipAPI->api_import_symbol
183 #define sipFindType sipAPI->api_find_type
184 #define sipFindNamedEnum sipAPI->api_find_named_enum
185 #define sipBytes_AsChar sipAPI->api_bytes_as_char
186 #define sipBytes_AsString sipAPI->api_bytes_as_string
187 #define sipString_AsASCIIChar sipAPI->api_string_as_ascii_char
188 #define sipString_AsASCIIString sipAPI->api_string_as_ascii_string
189 #define sipString_AsLatin1Char sipAPI->api_string_as_latin1_char
190 #define sipString_AsLatin1String sipAPI->api_string_as_latin1_string
191 #define sipString_AsUTF8Char sipAPI->api_string_as_utf8_char
192 #define sipString_AsUTF8String sipAPI->api_string_as_utf8_string
193 #define sipUnicode_AsWChar sipAPI->api_unicode_as_wchar
194 #define sipUnicode_AsWString sipAPI->api_unicode_as_wstring
195 #define sipConvertFromConstVoidPtr sipAPI->api_convert_from_const_void_ptr
196 #define sipConvertFromVoidPtrAndSize sipAPI->api_convert_from_void_ptr_and_size
197 #define sipConvertFromConstVoidPtrAndSize sipAPI->api_convert_from_const_void_ptr_and_size
198 #define sipInvokeSlot sipAPI->api_invoke_slot
199 #define sipSaveSlot sipAPI->api_save_slot
200 #define sipClearAnySlotReference sipAPI->api_clear_any_slot_reference
201 #define sipVisitSlot sipAPI->api_visit_slot
202 #define sipWrappedTypeName(wt) ((wt)->type->td_cname)
203 #define sipDeprecated sipAPI->api_deprecated
204 #define sipKeepReference sipAPI->api_keep_reference
205 #define sipRegisterPyType sipAPI->api_register_py_type
206 #define sipTypeFromPyTypeObject sipAPI->api_type_from_py_type_object
207 #define sipTypeScope sipAPI->api_type_scope
208 #define sipResolveTypedef sipAPI->api_resolve_typedef
209 #define sipRegisterAttributeGetter sipAPI->api_register_attribute_getter
210 #define sipIsAPIEnabled sipAPI->api_is_api_enabled
211 #define sipExportModule sipAPI->api_export_module
212 #define sipInitModule sipAPI->api_init_module
213 
214 #endif /* PYTHONINCLUDES_H_ */