sbkmodule.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (C) 2016 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 SBK_MODULE_H
  4. #define SBK_MODULE_H
  5. #include "sbkpython.h"
  6. #include "shibokenmacros.h"
  7. extern "C"
  8. {
  9. struct SbkConverter;
  10. }
  11. namespace Shiboken::Module {
  12. struct TypeInitStruct
  13. {
  14. PyTypeObject *type;
  15. const char *fullName;
  16. };
  17. /// PYSIDE-2404: Replacing the arguments in cpythonTypeNameExt by a function.
  18. LIBSHIBOKEN_API PyTypeObject *get(TypeInitStruct &typeStruct);
  19. /// PYSIDE-2404: Make sure that mentioned classes really exist.
  20. LIBSHIBOKEN_API void loadLazyClassesWithName(const char *name);
  21. /// PYSIDE-2404: incarnate all classes for star imports.
  22. LIBSHIBOKEN_API void resolveLazyClasses(PyObject *module);
  23. /**
  24. * Imports and returns the module named \p moduleName, or a NULL pointer in case of failure.
  25. * If the module is already imported, it increments its reference count before returning it.
  26. * \returns the module specified in \p moduleName or NULL if an error occurs.
  27. */
  28. LIBSHIBOKEN_API PyObject *import(const char *moduleName);
  29. /**
  30. * Creates a new Python module named \p moduleName using the information passed in \p moduleData
  31. * and calls exec() on it.
  32. * \returns a newly created module.
  33. */
  34. [[deprecated]] LIBSHIBOKEN_API PyObject *create(const char *moduleName, PyModuleDef *moduleData);
  35. /// Creates a new Python module named \p moduleName using the information passed in \p moduleData.
  36. /// exec() is not called (Support for Nuitka).
  37. /// \returns a newly created module.
  38. LIBSHIBOKEN_API PyObject *createOnly(const char *moduleName, PyModuleDef *moduleData);
  39. /// Executes a module (multi-phase initialization helper)
  40. LIBSHIBOKEN_API void exec(PyObject *module);
  41. using TypeCreationFunction = PyTypeObject *(*)(PyObject *module);
  42. /// Adds a type creation function to the module.
  43. LIBSHIBOKEN_API void AddTypeCreationFunction(PyObject *module,
  44. const char *name,
  45. TypeCreationFunction func);
  46. LIBSHIBOKEN_API void AddTypeCreationFunction(PyObject *module,
  47. const char *enclosingName,
  48. TypeCreationFunction func,
  49. const char *subTypeNamePath);
  50. /**
  51. * Registers the list of types created by \p module.
  52. * \param module Module where the types were created.
  53. * \param types Array of PyTypeObject *objects representing the types created on \p module.
  54. */
  55. LIBSHIBOKEN_API void registerTypes(PyObject *module, TypeInitStruct *types);
  56. /**
  57. * Retrieves the array of types.
  58. * \param module Module where the types were created.
  59. * \returns A pointer to the PyTypeObject *array of types.
  60. */
  61. LIBSHIBOKEN_API TypeInitStruct *getTypes(PyObject *module);
  62. /**
  63. * Registers the list of converters created by \p module for non-wrapper types.
  64. * \param module Module where the converters were created.
  65. * \param converters Array of SbkConverter *objects representing the converters created on \p module.
  66. */
  67. LIBSHIBOKEN_API void registerTypeConverters(PyObject *module, SbkConverter **converters);
  68. /**
  69. * Retrieves the array of converters.
  70. * \param module Module where the converters were created.
  71. * \returns A pointer to the SbkConverter *array of converters.
  72. */
  73. LIBSHIBOKEN_API SbkConverter **getTypeConverters(PyObject *module);
  74. /**
  75. * Replace the dictionary of a module. This allows to use `__missing__`.
  76. */
  77. LIBSHIBOKEN_API bool replaceModuleDict(PyObject *module, PyObject *modClass, PyObject *dict);
  78. } // namespace Shiboken::Module
  79. #endif // SBK_MODULE_H