interfaceMakerPython.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Filename: interfaceMakerPython.cxx
  2. // Created by: drose (21Sep01)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #include "interfaceMakerPython.h"
  15. #include "interrogate.h"
  16. ////////////////////////////////////////////////////////////////////
  17. // Function: InterfaceMakerPython::Constructor
  18. // Access: Public
  19. // Description:
  20. ////////////////////////////////////////////////////////////////////
  21. InterfaceMakerPython::
  22. InterfaceMakerPython(InterrogateModuleDef *def) :
  23. InterfaceMaker(def)
  24. {
  25. }
  26. ////////////////////////////////////////////////////////////////////
  27. // Function: InterfaceMakerPython::write_includes
  28. // Access: Public, Virtual
  29. // Description: Generates the list of #include ... whatever that's
  30. // required by this particular interface to the
  31. // indicated output stream.
  32. ////////////////////////////////////////////////////////////////////
  33. void InterfaceMakerPython::
  34. write_includes(ostream &out) {
  35. InterfaceMaker::write_includes(out);
  36. out << "#undef _POSIX_C_SOURCE\n\n"
  37. << "#if PYTHON_FRAMEWORK\n"
  38. << " #include \"Python/Python.h\"\n"
  39. << "#else\n"
  40. << " #include \"Python.h\"\n"
  41. << "#endif\n";
  42. }
  43. ////////////////////////////////////////////////////////////////////
  44. // Function: InterfaceMakerPython::test_assert
  45. // Access: Protected
  46. // Description: Outputs code to check to see if an assertion has
  47. // failed while the C++ code was executing, and report
  48. // this failure back to Python.
  49. ////////////////////////////////////////////////////////////////////
  50. void InterfaceMakerPython::
  51. test_assert(ostream &out, int indent_level) const {
  52. if (watch_asserts) {
  53. out << "#ifndef NDEBUG\n";
  54. indent(out, indent_level)
  55. << "Notify *notify = Notify::ptr();\n";
  56. indent(out, indent_level)
  57. << "if (notify->has_assert_failed()) {\n";
  58. indent(out, indent_level + 2)
  59. << "PyErr_SetString(PyExc_AssertionError, notify->get_assert_error_message().c_str());\n";
  60. indent(out, indent_level + 2)
  61. << "notify->clear_assert_failed();\n";
  62. indent(out, indent_level + 2)
  63. << "return (PyObject *)NULL;\n";
  64. indent(out, indent_level)
  65. << "}\n";
  66. indent(out, indent_level)
  67. << "if (PyErr_Occurred()) {\n";
  68. indent(out, indent_level + 2)
  69. << "return (PyObject *)NULL;\n";
  70. indent(out, indent_level)
  71. << "}\n";
  72. out << "#endif\n";
  73. }
  74. }