Tulip  4.4.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 # if defined(__GNUC__) && !defined(__clang__)
79 # pragma GCC diagnostic push
80 # pragma GCC diagnostic ignored "-pedantic"
81 # endif
82 # include <sip.h>
83 # if defined(__GNUC__) && !defined(__clang__)
84 # pragma GCC diagnostic pop
85 # endif
86 # endif
87 
88 static const sipAPIDef *getSipAPI() {
89 #if defined(SIP_USE_PYCAPSULE)
90  return (const sipAPIDef *)PyCapsule_Import("sip._C_API", 0);
91 #else
92  PyObject *sip_module;
93  PyObject *sip_module_dict;
94  PyObject *c_api;
95 
96  /* Import the SIP module. */
97  sip_module = PyImport_ImportModule("sip");
98 
99  if (sip_module == NULL)
100  return NULL;
101 
102  /* Get the module's dictionary. */
103  sip_module_dict = PyModule_GetDict(sip_module);
104 
105  /* Get the "_C_API" attribute. */
106  c_api = PyDict_GetItemString(sip_module_dict, "_C_API");
107 
108  if (c_api == NULL)
109  return NULL;
110 
111  /* Sanity check that it is the right type. */
112  if (!PyCObject_Check(c_api))
113  return NULL;
114 
115  /* Get the actual pointer from the object. */
116  return (const sipAPIDef *)PyCObject_AsVoidPtr(c_api);
117 #endif
118 }
119 
120 static const sipAPIDef *sipAPIPtr = NULL;
121 
122 inline const sipAPIDef * sipAPI() {
123  if (!sipAPIPtr) {
124  sipAPIPtr = getSipAPI();
125  }
126 
127  return sipAPIPtr;
128 }
129 
130 #define sipMalloc sipAPI()->api_malloc
131 #define sipFree sipAPI()->api_free
132 #define sipBuildResult sipAPI()->api_build_result
133 #define sipCallMethod sipAPI()->api_call_method
134 #define sipParseResult sipAPI()->api_parse_result
135 #define sipParseArgs sipAPI()->api_parse_args
136 #define sipParseKwdArgs sipAPI()->api_parse_kwd_args
137 #define sipParsePair sipAPI()->api_parse_pair
138 #define sipCommonDtor sipAPI()->api_common_dtor
139 #define sipConvertFromSequenceIndex sipAPI()->api_convert_from_sequence_index
140 #define sipConvertFromVoidPtr sipAPI()->api_convert_from_void_ptr
141 #define sipConvertToVoidPtr sipAPI()->api_convert_to_void_ptr
142 #define sipAddException sipAPI()->api_add_exception
143 #define sipNoFunction sipAPI()->api_no_function
144 #define sipNoMethod sipAPI()->api_no_method
145 #define sipAbstractMethod sipAPI()->api_abstract_method
146 #define sipBadClass sipAPI()->api_bad_class
147 #define sipBadCatcherResult sipAPI()->api_bad_catcher_result
148 #define sipBadCallableArg sipAPI()->api_bad_callable_arg
149 #define sipBadOperatorArg sipAPI()->api_bad_operator_arg
150 #define sipTrace sipAPI()->api_trace
151 #define sipTransferBack sipAPI()->api_transfer_back
152 #define sipTransferTo sipAPI()->api_transfer_to
153 #define sipTransferBreak sipAPI()->api_transfer_break
154 #define sipSimpleWrapper_Type sipAPI()->api_simplewrapper_type
155 #define sipWrapper_Type sipAPI()->api_wrapper_type
156 #define sipWrapperType_Type sipAPI()->api_wrappertype_type
157 #define sipVoidPtr_Type sipAPI()->api_voidptr_type
158 #define sipGetPyObject sipAPI()->api_get_pyobject
159 #define sipGetAddress sipAPI()->api_get_address
160 #define sipGetCppPtr sipAPI()->api_get_cpp_ptr
161 #define sipGetComplexCppPtr sipAPI()->api_get_complex_cpp_ptr
162 #define sipIsPyMethod sipAPI()->api_is_py_method
163 #define sipCallHook sipAPI()->api_call_hook
164 #define sipStartThread sipAPI()->api_start_thread
165 #define sipEndThread sipAPI()->api_end_thread
166 #define sipConnectRx sipAPI()->api_connect_rx
167 #define sipDisconnectRx sipAPI()->api_disconnect_rx
168 #define sipRaiseUnknownException sipAPI()->api_raise_unknown_exception
169 #define sipRaiseTypeException sipAPI()->api_raise_type_exception
170 #define sipBadLengthForSlice sipAPI()->api_bad_length_for_slice
171 #define sipAddTypeInstance sipAPI()->api_add_type_instance
172 #define sipFreeSipslot sipAPI()->api_free_sipslot
173 #define sipSameSlot sipAPI()->api_same_slot
174 #define sipPySlotExtend sipAPI()->api_pyslot_extend
175 #define sipConvertRx sipAPI()->api_convert_rx
176 #define sipAddDelayedDtor sipAPI()->api_add_delayed_dtor
177 #define sipCanConvertToType sipAPI()->api_can_convert_to_type
178 #define sipConvertToType sipAPI()->api_convert_to_type
179 #define sipForceConvertToType sipAPI()->api_force_convert_to_type
180 #define sipCanConvertToEnum sipAPI()->api_can_convert_to_enum
181 #define sipReleaseType sipAPI()->api_release_type
182 #define sipConvertFromType sipAPI()->api_convert_from_type
183 #define sipConvertFromNewType sipAPI()->api_convert_from_new_type
184 #define sipConvertFromEnum sipAPI()->api_convert_from_enum
185 #define sipGetState sipAPI()->api_get_state
186 #define sipLong_AsUnsignedLong sipAPI()->api_long_as_unsigned_long
187 #define sipExportSymbol sipAPI()->api_export_symbol
188 #define sipImportSymbol sipAPI()->api_import_symbol
189 #define sipFindType sipAPI()->api_find_type
190 #define sipFindNamedEnum sipAPI()->api_find_named_enum
191 #define sipBytes_AsChar sipAPI()->api_bytes_as_char
192 #define sipBytes_AsString sipAPI()->api_bytes_as_string
193 #define sipString_AsASCIIChar sipAPI()->api_string_as_ascii_char
194 #define sipString_AsASCIIString sipAPI()->api_string_as_ascii_string
195 #define sipString_AsLatin1Char sipAPI()->api_string_as_latin1_char
196 #define sipString_AsLatin1String sipAPI()->api_string_as_latin1_string
197 #define sipString_AsUTF8Char sipAPI()->api_string_as_utf8_char
198 #define sipString_AsUTF8String sipAPI()->api_string_as_utf8_string
199 #define sipUnicode_AsWChar sipAPI()->api_unicode_as_wchar
200 #define sipUnicode_AsWString sipAPI()->api_unicode_as_wstring
201 #define sipConvertFromConstVoidPtr sipAPI()->api_convert_from_const_void_ptr
202 #define sipConvertFromVoidPtrAndSize sipAPI()->api_convert_from_void_ptr_and_size
203 #define sipConvertFromConstVoidPtrAndSize sipAPI()->api_convert_from_const_void_ptr_and_size
204 #define sipInvokeSlot sipAPI()->api_invoke_slot
205 #define sipSaveSlot sipAPI()->api_save_slot
206 #define sipClearAnySlotReference sipAPI()->api_clear_any_slot_reference
207 #define sipVisitSlot sipAPI()->api_visit_slot
208 #define sipWrappedTypeName(wt) ((wt)->type->td_cname)
209 #define sipDeprecated sipAPI()->api_deprecated
210 #define sipKeepReference sipAPI()->api_keep_reference
211 #define sipRegisterPyType sipAPI()->api_register_py_type
212 #define sipTypeFromPyTypeObject sipAPI()->api_type_from_py_type_object
213 #define sipTypeScope sipAPI()->api_type_scope
214 #define sipResolveTypedef sipAPI()->api_resolve_typedef
215 #define sipRegisterAttributeGetter sipAPI()->api_register_attribute_getter
216 #define sipIsAPIEnabled sipAPI()->api_is_api_enabled
217 #define sipExportModule sipAPI()->api_export_module
218 #define sipInitModule sipAPI()->api_init_module
219 
220 #endif /* PYTHONINCLUDES_H_ */