basewrapper.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. // Copyright (C) 2019 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. #ifndef BASEWRAPPER_H
  4. #define BASEWRAPPER_H
  5. #include "sbkpython.h"
  6. #include "shibokenmacros.h"
  7. #include "sbkmodule.h"
  8. #include "gilstate.h"
  9. #include <vector>
  10. #include <string>
  11. extern "C"
  12. {
  13. struct SbkConverter;
  14. struct SbkObjectPrivate;
  15. /// Base Python object for all the wrapped C++ classes.
  16. struct LIBSHIBOKEN_API SbkObject
  17. {
  18. PyObject_HEAD
  19. /// Instance dictionary.
  20. PyObject *ob_dict;
  21. /// List of weak references
  22. PyObject *weakreflist;
  23. SbkObjectPrivate *d;
  24. };
  25. /// PYSIDE-939: A general replacement for object_dealloc.
  26. LIBSHIBOKEN_API void Sbk_object_dealloc(PyObject *self);
  27. /// Dealloc the python object \p pyObj and the C++ object represented by it.
  28. LIBSHIBOKEN_API void SbkDeallocWrapper(PyObject *pyObj);
  29. LIBSHIBOKEN_API void SbkDeallocQAppWrapper(PyObject *pyObj);
  30. LIBSHIBOKEN_API void SbkDeallocWrapperWithPrivateDtor(PyObject *self);
  31. /// Function signature for the multiple inheritance information initializers that should be provided by classes with multiple inheritance.
  32. using MultipleInheritanceInitFunction = int *(*)(const void *);
  33. /**
  34. * Special cast function is used to correctly cast an object when it's
  35. * part of a multiple inheritance hierarchy.
  36. * The implementation of this function is auto generated by the generator and you don't need to care about it.
  37. */
  38. using SpecialCastFunction = void *(*)(void *, PyTypeObject *);
  39. using TypeDiscoveryFunc = PyTypeObject *(*)(void *, PyTypeObject *);
  40. using TypeDiscoveryFuncV2 = void *(*)(void *, PyTypeObject *);
  41. // Used in userdata dealloc function
  42. using DeleteUserDataFunc = void (*)(void *);
  43. using ObjectDestructor = void (*)(void *);
  44. using SubTypeInitHook = void (*)(PyTypeObject *, PyObject *, PyObject *);
  45. /// PYSIDE-1019: Set the function to select the current feature.
  46. /// Return value is the previous content.
  47. using SelectableFeatureHook = void (*)(PyTypeObject *);
  48. using SelectableFeatureCallback = void (*)(bool);
  49. LIBSHIBOKEN_API SelectableFeatureHook initSelectableFeature(SelectableFeatureHook func);
  50. LIBSHIBOKEN_API void setSelectableFeatureCallback(SelectableFeatureCallback func);
  51. /// PYSIDE-1626: Enforcing a context switch without further action.
  52. LIBSHIBOKEN_API void SbkObjectType_UpdateFeature(PyTypeObject *type);
  53. /// PYSIDE-1019: Get access to PySide property strings.
  54. LIBSHIBOKEN_API const char **SbkObjectType_GetPropertyStrings(PyTypeObject *type);
  55. LIBSHIBOKEN_API void SbkObjectType_SetPropertyStrings(PyTypeObject *type, const char **strings);
  56. /// PYSIDE-1735: Store the enumFlagInfo.
  57. LIBSHIBOKEN_API void SbkObjectType_SetEnumFlagInfo(PyTypeObject *type, const char **strings);
  58. /// PYSIDE-1470: Set the function to kill a Q*Application.
  59. using DestroyQAppHook = void(*)();
  60. LIBSHIBOKEN_API void setDestroyQApplication(DestroyQAppHook func);
  61. /// PYSIDE-535: Use the C API in PyPy instead of `op->ob_dict`, directly (borrowed ref)
  62. LIBSHIBOKEN_API PyObject *SbkObject_GetDict_NoRef(PyObject *op);
  63. extern LIBSHIBOKEN_API PyTypeObject *SbkObjectType_TypeF(void);
  64. extern LIBSHIBOKEN_API PyTypeObject *SbkObject_TypeF(void);
  65. struct SbkObjectTypePrivate;
  66. /// PyTypeObject extended with C++ multiple inheritance information.
  67. LIBSHIBOKEN_API PyObject *SbkObject_tp_new(PyTypeObject *subtype, PyObject *, PyObject *);
  68. /// The special case of a switchable singleton Q*Application.
  69. LIBSHIBOKEN_API PyObject *SbkQApp_tp_new(PyTypeObject *subtype, PyObject *, PyObject *);
  70. /// Create a new Q*Application wrapper and monitor it.
  71. LIBSHIBOKEN_API PyObject *MakeQAppWrapper(PyTypeObject *type);
  72. /**
  73. * PYSIDE-832: Use object_dealloc instead of nullptr.
  74. *
  75. * When moving to heaptypes, we were struck by a special default behavior of
  76. * PyType_FromSpec that inserts subtype_dealloc when tp_dealloc is
  77. * nullptr. But the default before conversion to heaptypes was to assign
  78. * object_dealloc. This seems to be a bug in the Limited API.
  79. */
  80. /// PYSIDE-939: Replaced by Sbk_object_dealloc.
  81. LIBSHIBOKEN_API PyObject *SbkDummyNew(PyTypeObject *type, PyObject *, PyObject *);
  82. /// PYSIDE-74: Fallback used in all types now.
  83. LIBSHIBOKEN_API PyObject *FallbackRichCompare(PyObject *self, PyObject *other, int op);
  84. /// PYSIDE-1970: Be easily able to see what is happening in the running code.
  85. LIBSHIBOKEN_API void disassembleFrame(const char *marker);
  86. /// PYSIDE-2230: Check if an object is an SbkObject.
  87. LIBSHIBOKEN_API bool SbkObjectType_Check(PyTypeObject *type);
  88. /// PYSIDE-2701: Some improvements from folding optimizations.
  89. LIBSHIBOKEN_API PyObject *Sbk_ReturnFromPython_None();
  90. LIBSHIBOKEN_API PyObject *Sbk_ReturnFromPython_Result(PyObject *pyResult);
  91. LIBSHIBOKEN_API PyObject *Sbk_ReturnFromPython_Self(PyObject *self);
  92. } // extern "C"
  93. LIBSHIBOKEN_API PyObject *Sbk_GetPyOverride(const void *voidThis, PyTypeObject *typeObject,
  94. Shiboken::GilState &gil, const char *funcName,
  95. PyObject *&resultCache, PyObject **nameCache);
  96. namespace Shiboken
  97. {
  98. /**
  99. * Init shiboken library.
  100. */
  101. LIBSHIBOKEN_API void init();
  102. /// PYSIDE-1415: Publish Shiboken objects.
  103. LIBSHIBOKEN_API void initShibokenSupport(PyObject *module);
  104. /// Delete the class T allocated on \p cptr.
  105. template<typename T>
  106. void callCppDestructor(void *cptr)
  107. {
  108. delete reinterpret_cast<T *>(cptr);
  109. }
  110. /// setErrorAboutWrongArguments now gets overload information from the signature module.
  111. /// The extra info argument can contain additional data about the error.
  112. LIBSHIBOKEN_API void setErrorAboutWrongArguments(PyObject *args, const char *funcName,
  113. PyObject *info, const char *className = nullptr);
  114. /// Return values for the different return variants.
  115. /// This is used instead of goto.
  116. /// Either funcname should contain the full function name, or the module and class
  117. /// are taken from the TypeInitStruct.
  118. LIBSHIBOKEN_API PyObject *returnWrongArguments(PyObject *args, const char *funcName, PyObject *info,
  119. Module::TypeInitStruct initStruct = {nullptr, nullptr});
  120. LIBSHIBOKEN_API int returnWrongArguments_Zero(PyObject *args, const char *funcName, PyObject *info,
  121. Module::TypeInitStruct initStruct = {nullptr, nullptr});
  122. LIBSHIBOKEN_API int returnWrongArguments_MinusOne(PyObject *args, const char *funcName, PyObject *info,
  123. Module::TypeInitStruct initStruct = {nullptr, nullptr});
  124. /// A simple special version for the end of rich comparison.
  125. LIBSHIBOKEN_API PyObject *returnFromRichCompare(PyObject *result);
  126. // Return error information object if the argument count is wrong
  127. LIBSHIBOKEN_API PyObject *checkInvalidArgumentCount(Py_ssize_t numArgs,
  128. Py_ssize_t minArgs,
  129. Py_ssize_t maxArgs);
  130. namespace ObjectType {
  131. /**
  132. * Returns true if the object is an instance of a type created by the Shiboken generator.
  133. */
  134. LIBSHIBOKEN_API bool checkType(PyTypeObject *pyObj);
  135. /**
  136. * Returns true if this object is an instance of an user defined type derived from an Shiboken type.
  137. */
  138. LIBSHIBOKEN_API bool isUserType(PyTypeObject *pyObj);
  139. /**
  140. * Returns true if the constructor of \p ctorType can be called for a instance of type \p myType.
  141. * \note This function set a python error when returning false.
  142. */
  143. LIBSHIBOKEN_API bool canCallConstructor(PyTypeObject *myType, PyTypeObject *ctorType);
  144. /**
  145. * Tells if the \p type represents an object of a class with multiple inheritance in C++.
  146. * When this occurs, the C++ pointer held by the Python wrapper will need to be cast when
  147. * passed as a parameter that expects a type of its ancestry.
  148. * \returns true if a call to ObjectType::cast() is needed to obtain the correct
  149. * C++ pointer for Python objects of type \p type.
  150. */
  151. LIBSHIBOKEN_API bool hasCast(PyTypeObject *type);
  152. /**
  153. * Cast the C++ pointer held by a Python object \p obj of type \p sourceType,
  154. * to a C++ pointer of a C++ class indicated by type \p targetType.
  155. * \returns The cast C++ pointer.
  156. */
  157. LIBSHIBOKEN_API void *cast(PyTypeObject *sourceType, SbkObject *obj, PyTypeObject *targetType);
  158. /// Set the C++ cast function for \p type.
  159. LIBSHIBOKEN_API void setCastFunction(PyTypeObject *type, SpecialCastFunction func);
  160. LIBSHIBOKEN_API void setOriginalName(PyTypeObject *self, const char *name);
  161. LIBSHIBOKEN_API const char *getOriginalName(PyTypeObject *self);
  162. LIBSHIBOKEN_API void setTypeDiscoveryFunctionV2(PyTypeObject *self, TypeDiscoveryFuncV2 func);
  163. LIBSHIBOKEN_API void copyMultipleInheritance(PyTypeObject *self, PyTypeObject *other);
  164. LIBSHIBOKEN_API void setMultipleInheritanceFunction(PyTypeObject *self, MultipleInheritanceInitFunction func);
  165. LIBSHIBOKEN_API MultipleInheritanceInitFunction getMultipleInheritanceFunction(PyTypeObject *type);
  166. LIBSHIBOKEN_API void setDestructorFunction(PyTypeObject *self, ObjectDestructor func);
  167. enum WrapperFlags
  168. {
  169. InnerClass = 0x1,
  170. DeleteInMainThread = 0x2,
  171. Value = 0x4,
  172. InternalWrapper = 0x8
  173. };
  174. /**
  175. * Initializes a Shiboken wrapper type and adds it to the module,
  176. * or to the enclosing class if the type is an inner class.
  177. * This function also calls setDestructorFunction.
  178. * \param enclosingObject The module or enclosing class to where the new \p type will be added.
  179. * \param typeName Name by which the type will be known in Python.
  180. * \param originalName Original C++ name of the type.
  181. * \param type The new type to be initialized and added to the module.
  182. * \param cppObjDtor Memory deallocation function for the C++ object held by \p type.
  183. * Should not be used if the underlying C++ class has a private destructor.
  184. * \param baseType Base type from whom the new \p type inherits.
  185. * \param baseTypes Other base types from whom the new \p type inherits.
  186. * \param isInnerClass Tells if the new \p type is an inner class (the default is that it isn't).
  187. * If false then the \p enclosingObject is a module, otherwise it is another
  188. * wrapper type.
  189. * \returns true if the initialization went fine, false otherwise.
  190. */
  191. LIBSHIBOKEN_API PyTypeObject *introduceWrapperType(PyObject *enclosingObject,
  192. const char *typeName,
  193. const char *originalName,
  194. PyType_Spec *typeSpec,
  195. ObjectDestructor cppObjDtor,
  196. PyObject *bases,
  197. unsigned wrapperFlags = 0);
  198. /**
  199. * Set the subtype init hook for a type.
  200. *
  201. * This hook will be invoked every time the user creates a sub-type inherited from a Shiboken based type.
  202. * The hook gets 3 params, they are: The new type being created, args and kwds. The last two are the very
  203. * same got from tp_new.
  204. */
  205. LIBSHIBOKEN_API void setSubTypeInitHook(PyTypeObject *self, SubTypeInitHook func);
  206. /**
  207. * Get the user data previously set by Shiboken::Object::setTypeUserData
  208. */
  209. LIBSHIBOKEN_API void *getTypeUserData(PyTypeObject *self);
  210. LIBSHIBOKEN_API void setTypeUserData(PyTypeObject *self, void *userData, DeleteUserDataFunc d_func);
  211. /**
  212. * Return an instance of PyTypeObject for a C++ type name as determined by
  213. * typeinfo().name().
  214. * \param typeName Type name
  215. * \since 5.12
  216. */
  217. LIBSHIBOKEN_API PyTypeObject *typeForTypeName(const char *typeName);
  218. /**
  219. * Returns whether PyTypeObject has a special cast function (multiple inheritance)
  220. * \param sbkType Sbk type
  221. * \since 5.12
  222. */
  223. LIBSHIBOKEN_API bool hasSpecialCastFunction(PyTypeObject *sbkType);
  224. /// Returns whether a C++ pointer of \p baseType can be safely downcast
  225. /// to \p targetType (base is a direct, single line base class of targetType).
  226. /// (is a direct, single-line inheritance)
  227. /// \param baseType Python type of base class
  228. /// \param targetType Python type of derived class
  229. /// \since 6.8
  230. LIBSHIBOKEN_API bool canDowncastTo(PyTypeObject *baseType, PyTypeObject *targetType);
  231. }
  232. namespace Object {
  233. /**
  234. * Returns a string with information about the internal state of the instance object, useful for debug purposes.
  235. */
  236. LIBSHIBOKEN_API std::string info(SbkObject *self);
  237. /**
  238. * Returns true if the object is an instance of a type created by the Shiboken generator.
  239. */
  240. LIBSHIBOKEN_API bool checkType(PyObject *pyObj);
  241. /**
  242. * Returns true if this object type is an instance of an user defined type derived from an Shiboken type.
  243. * \see Shiboken::ObjectType::isUserType
  244. */
  245. LIBSHIBOKEN_API bool isUserType(PyObject *pyObj);
  246. /**
  247. * Generic function used to make ObjectType hashable, the C++ pointer is used as hash value.
  248. */
  249. LIBSHIBOKEN_API Py_hash_t hash(PyObject *pyObj);
  250. /**
  251. * Find a child of given wrapper having same address having the specified type.
  252. */
  253. LIBSHIBOKEN_API SbkObject *findColocatedChild(SbkObject *wrapper,
  254. const PyTypeObject *instanceType);
  255. /**
  256. * Bind a C++ object to Python. Forwards to
  257. * newObjectWithHeuristics(), newObjectForType() depending on \p isExactType.
  258. * \param instanceType equivalent Python type for the C++ object.
  259. * \param hasOwnership if true, Python will try to delete the underlying C++ object when there's no more refs.
  260. * \param isExactType if false, Shiboken will use some heuristics to detect the correct Python type of this C++
  261. * object, in any case you must provide \p instanceType, it'll be used as search starting point
  262. * and as fallback.
  263. * \param typeName If non-null, this will be used as helper to find the correct Python type for this object.
  264. */
  265. LIBSHIBOKEN_API PyObject *newObject(PyTypeObject *instanceType,
  266. void *cptr,
  267. bool hasOwnership = true,
  268. bool isExactType = false,
  269. const char *typeName = nullptr);
  270. /// Bind a C++ object to Python for polymorphic pointers. Calls
  271. /// newObjectWithHeuristics() with an additional check for multiple
  272. /// inheritance, in which case it will fall back to instanceType.
  273. /// \param instanceType Equivalent Python type for the C++ object.
  274. /// \param hasOwnership if true, Python will try to delete the underlying C++ object
  275. /// when there's no more refs.
  276. /// \param typeName If non-null, this will be used as helper to find the correct
  277. /// Python type for this object (obtained by typeid().name().
  278. LIBSHIBOKEN_API PyObject *newObjectForPointer(PyTypeObject *instanceType,
  279. void *cptr,
  280. bool hasOwnership = true,
  281. const char *typeName = nullptr);
  282. /// Bind a C++ object to Python using some heuristics to detect the correct
  283. /// Python type of this C++ object. In any case \p instanceType must be provided;
  284. /// it'll be used as search starting point and as fallback.
  285. /// \param instanceType Equivalent Python type for the C++ object.
  286. /// \param hasOwnership if true, Python will try to delete the underlying C++ object
  287. /// C++ object when there are no more references.
  288. /// when there's no more refs.
  289. /// \param typeName If non-null, this will be used as helper to find the correct
  290. /// Python type for this object (obtained by typeid().name().
  291. LIBSHIBOKEN_API PyObject *newObjectWithHeuristics(PyTypeObject *instanceType,
  292. void *cptr,
  293. bool hasOwnership = true,
  294. const char *typeName = nullptr);
  295. /// Bind a C++ object to Python using the given type.
  296. /// \param instanceType Equivalent Python type for the C++ object.
  297. /// \param hasOwnership if true, Python will try to delete the underlying
  298. /// C++ object when there are no more references.
  299. LIBSHIBOKEN_API PyObject *newObjectForType(PyTypeObject *instanceType,
  300. void *cptr, bool hasOwnership = true);
  301. /**
  302. * Changes the valid flag of a PyObject, invalid objects will raise an exception when someone tries to access it.
  303. */
  304. LIBSHIBOKEN_API void setValidCpp(SbkObject *pyObj, bool value);
  305. /**
  306. * Tells shiboken the Python object \p pyObj has a C++ wrapper used to intercept virtual method calls.
  307. */
  308. LIBSHIBOKEN_API void setHasCppWrapper(SbkObject *pyObj, bool value);
  309. /**
  310. * Return true if the Python object \p pyObj has a C++ wrapper used to intercept virtual method calls.
  311. */
  312. LIBSHIBOKEN_API bool hasCppWrapper(SbkObject *pyObj);
  313. /**
  314. * Return true if the Python object was created by Python, false otherwise.
  315. * \note This function was added to libshiboken only to be used by shiboken.wasCreatedByPython()
  316. */
  317. LIBSHIBOKEN_API bool wasCreatedByPython(SbkObject *pyObj);
  318. /**
  319. * Call the C++ object destructor and invalidates the Python object.
  320. * \note This function was added to libshiboken only to be used by shiboken.delete()
  321. */
  322. LIBSHIBOKEN_API void callCppDestructors(SbkObject *pyObj);
  323. /**
  324. * Return true if the Python is responsible for deleting the underlying C++ object.
  325. */
  326. LIBSHIBOKEN_API bool hasOwnership(SbkObject *pyObj);
  327. /**
  328. * Sets python as responsible to delete the underlying C++ object.
  329. * \note You this overload only when the PyObject can be a sequence and you want to
  330. * call this function for every item in the sequence.
  331. * \see getOwnership(SbkObject *)
  332. */
  333. LIBSHIBOKEN_API void getOwnership(PyObject *pyObj);
  334. /**
  335. * Sets python as responsible to delete the underlying C++ object.
  336. */
  337. LIBSHIBOKEN_API void getOwnership(SbkObject *pyObj);
  338. /**
  339. * Release the ownership, so Python will not delete the underlying C++ object.
  340. * \note You this overload only when the PyObject can be a sequence and you want to
  341. * call this function for every item in the sequence.
  342. * \see releaseOwnership(SbkObject *)
  343. */
  344. LIBSHIBOKEN_API void releaseOwnership(PyObject *pyObj);
  345. /**
  346. * Release the ownership, so Python will not delete the underlying C++ object.
  347. */
  348. LIBSHIBOKEN_API void releaseOwnership(SbkObject *pyObj);
  349. /**
  350. * Get the C++ pointer of type \p desiredType from a Python object.
  351. */
  352. LIBSHIBOKEN_API void *cppPointer(SbkObject *pyObj, PyTypeObject *desiredType);
  353. /**
  354. * Return a list with all C++ pointers held from a Python object.
  355. * \note This function was added to libshiboken only to be used by shiboken.getCppPointer()
  356. */
  357. LIBSHIBOKEN_API std::vector<void *>cppPointers(SbkObject *pyObj);
  358. /**
  359. * Set the C++ pointer of type \p desiredType of a Python object.
  360. */
  361. LIBSHIBOKEN_API bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr);
  362. /**
  363. * Returns false and sets a Python RuntimeError if the Python wrapper is not marked as valid.
  364. */
  365. LIBSHIBOKEN_API bool isValid(PyObject *pyObj);
  366. /**
  367. * Returns false if the Python wrapper is not marked as valid.
  368. * \param pyObj the object.
  369. * \param throwPyError sets a Python RuntimeError when the object isn't valid.
  370. */
  371. LIBSHIBOKEN_API bool isValid(SbkObject *pyObj, bool throwPyError = true);
  372. /**
  373. * Returns false if the Python wrapper is not marked as valid.
  374. * \param pyObj the object.
  375. * \param throwPyError sets a Python RuntimeError when the object isn't valid.
  376. */
  377. LIBSHIBOKEN_API bool isValid(PyObject *pyObj, bool throwPyError);
  378. /**
  379. * Set the parent of \p child to \p parent.
  380. * When an object dies, all their children, grandchildren, etc, are tagged as invalid.
  381. * \param parent the parent object, if null, the child will have no parents.
  382. * \param child the child.
  383. */
  384. LIBSHIBOKEN_API void setParent(PyObject *parent, PyObject *child);
  385. /**
  386. * Remove this child from their parent, if any.
  387. * \param child the child.
  388. */
  389. LIBSHIBOKEN_API void removeParent(SbkObject *child, bool giveOwnershipBack = true, bool keepReferenc = false);
  390. /**
  391. * Mark the object as invalid
  392. */
  393. LIBSHIBOKEN_API void invalidate(SbkObject *self);
  394. /**
  395. * Help function can be used to invalidate a sequence of object
  396. **/
  397. LIBSHIBOKEN_API void invalidate(PyObject *pyobj);
  398. /**
  399. * Make the object valid again
  400. */
  401. LIBSHIBOKEN_API void makeValid(SbkObject *self);
  402. /**
  403. * Destroy any data in Shiboken structure and c++ pointer if the pyboject has the ownership
  404. */
  405. LIBSHIBOKEN_API void destroy(SbkObject *self, void *cppData);
  406. /**
  407. * Set user data on type of \p wrapper.
  408. * \param wrapper instance object, the user data will be set on his type
  409. * \param userData the user data
  410. * \param d_func a function used to delete the user data
  411. */
  412. LIBSHIBOKEN_API void setTypeUserData(SbkObject *wrapper, void *userData, DeleteUserDataFunc d_func);
  413. /**
  414. * Get the user data previously set by Shiboken::Object::setTypeUserData
  415. */
  416. LIBSHIBOKEN_API void *getTypeUserData(SbkObject *wrapper);
  417. /**
  418. * Increments the reference count of the referred Python object.
  419. * A previous Python object in the same position identified by the 'key' parameter
  420. * will have its reference counter decremented automatically when replaced.
  421. * All the kept references should be decremented when the Python wrapper indicated by
  422. * 'self' dies.
  423. * No checking is done for any of the passed arguments, since it is meant to be used
  424. * by generated code it is supposed that the generator is correct.
  425. * \param self the wrapper instance that keeps references to other objects.
  426. * \param key a key that identifies the C++ method signature and argument where the referred Object came from.
  427. * \param referredObject the object whose reference is used by the self object.
  428. */
  429. LIBSHIBOKEN_API void keepReference(SbkObject *self, const char *key, PyObject *referredObject, bool append = false);
  430. /**
  431. * Removes any reference previously added by keepReference function
  432. * \param self the wrapper instance that keeps references to other objects.
  433. * \param key a key that identifies the C++ method signature and argument from where the referred Object came.
  434. * \param referredObject the object whose reference is used by the self object.
  435. */
  436. LIBSHIBOKEN_API void removeReference(SbkObject *self, const char *key, PyObject *referredObject);
  437. } // namespace Object
  438. } // namespace Shiboken
  439. #endif // BASEWRAPPER_H