kiwisolver.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*-----------------------------------------------------------------------------
  2. | Copyright (c) 2013-2017, Nucleic Development Team.
  3. |
  4. | Distributed under the terms of the Modified BSD License.
  5. |
  6. | The full license is in the file COPYING.txt, distributed with this software.
  7. |----------------------------------------------------------------------------*/
  8. #include <Python.h>
  9. #include <kiwi/kiwi.h>
  10. #include "pythonhelpers.h"
  11. #include "types.h"
  12. #define PY_KIWI_VERSION "1.1.0"
  13. using namespace PythonHelpers;
  14. static PyMethodDef
  15. kiwisolver_methods[] = {
  16. { 0 } // Sentinel
  17. };
  18. #if PY_MAJOR_VERSION >= 3
  19. static struct PyModuleDef kiwisolver_moduledef = {
  20. PyModuleDef_HEAD_INIT,
  21. "kiwisolver",
  22. NULL,
  23. sizeof( struct module_state ),
  24. kiwisolver_methods,
  25. NULL
  26. };
  27. PyMODINIT_FUNC
  28. PyInit_kiwisolver( void )
  29. #else
  30. PyMODINIT_FUNC
  31. initkiwisolver( void )
  32. #endif
  33. {
  34. #if PY_MAJOR_VERSION >= 3
  35. PyObject *mod = PyModule_Create( &kiwisolver_moduledef );
  36. #else
  37. PyObject* mod = Py_InitModule( "kiwisolver", kiwisolver_methods );
  38. #endif
  39. if( !mod )
  40. INITERROR;
  41. if( import_variable() < 0 )
  42. INITERROR;
  43. if( import_term() < 0 )
  44. INITERROR;
  45. if( import_expression() < 0 )
  46. INITERROR;
  47. if( import_constraint() < 0 )
  48. INITERROR;
  49. if( import_solver() < 0 )
  50. INITERROR;
  51. if( import_strength() < 0 )
  52. INITERROR;
  53. PyObject* kiwiversion = FROM_STRING( KIWI_VERSION );
  54. if( !kiwiversion )
  55. INITERROR;
  56. PyObject* pyversion = FROM_STRING( PY_KIWI_VERSION );
  57. if( !pyversion )
  58. INITERROR;
  59. PyObject* pystrength = PyType_GenericNew( &strength_Type, 0, 0 );
  60. if( !pystrength )
  61. INITERROR;
  62. PyModule_AddObject( mod, "__version__", pyversion );
  63. PyModule_AddObject( mod, "__kiwi_version__", kiwiversion );
  64. PyModule_AddObject( mod, "strength", pystrength );
  65. PyModule_AddObject( mod, "Variable", newref( pyobject_cast( &Variable_Type ) ) );
  66. PyModule_AddObject( mod, "Term", newref( pyobject_cast( &Term_Type ) ) );
  67. PyModule_AddObject( mod, "Expression", newref( pyobject_cast( &Expression_Type ) ) );
  68. PyModule_AddObject( mod, "Constraint", newref( pyobject_cast( &Constraint_Type ) ) );
  69. PyModule_AddObject( mod, "Solver", newref( pyobject_cast( &Solver_Type ) ) );
  70. PyModule_AddObject( mod, "DuplicateConstraint", newref( DuplicateConstraint ) );
  71. PyModule_AddObject( mod, "UnsatisfiableConstraint", newref( UnsatisfiableConstraint ) );
  72. PyModule_AddObject( mod, "UnknownConstraint", newref( UnknownConstraint ) );
  73. PyModule_AddObject( mod, "DuplicateEditVariable", newref( DuplicateEditVariable ) );
  74. PyModule_AddObject( mod, "UnknownEditVariable", newref( UnknownEditVariable ) );
  75. PyModule_AddObject( mod, "BadRequiredStrength", newref( BadRequiredStrength ) );
  76. #if PY_MAJOR_VERSION >= 3
  77. return mod;
  78. #endif
  79. }