interfaceMakerPython.cxx 3.1 KB

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