/src/defines.h

http://github.com/PerlGameDev/SDL · C Header · 75 lines · 40 code · 6 blank · 29 comment · 11 complexity · 6df1b6e88241b166d78bbd6c62e97880 MD5 · raw file

  1. #include <SDL.h>
  2. #include "SDL_thread.h"
  3. /* */
  4. /* defines.h */
  5. /* */
  6. /* Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org> */
  7. /* */
  8. /* ------------------------------------------------------------------------------ */
  9. /* */
  10. /* This library is free software; you can redistribute it and/or */
  11. /* modify it under the terms of the GNU Lesser General Public */
  12. /* License as published by the Free Software Foundation; either */
  13. /* version 2.1 of the License, or (at your option) any later version. */
  14. /* */
  15. /* This library is distributed in the hope that it will be useful, */
  16. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  17. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
  18. /* Lesser General Public License for more details. */
  19. /* */
  20. /* You should have received a copy of the GNU Lesser General Public */
  21. /* License along with this library; if not, write to the Free Software */
  22. /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
  23. /* */
  24. /* ------------------------------------------------------------------------------ */
  25. /* */
  26. /* Please feel free to send questions, suggestions or improvements to: */
  27. /* */
  28. /* David J. Goehrig */
  29. /* dgoehrig@cpan.org */
  30. /* */
  31. #ifndef SDL_PERL_DEFINES_H
  32. #define SDL_PERL_DEFINES_H
  33. #ifdef _WIN32
  34. #include <windows.h>
  35. typedef void* (*malloc_t)(int size);
  36. malloc_t _msvcrt_malloc = NULL;
  37. extern malloc_t _msvcrt_malloc;
  38. void *msvcrt_malloc(int size) {
  39. if (!_msvcrt_malloc)
  40. _msvcrt_malloc = (malloc_t)GetProcAddress(GetModuleHandle("msvcrt"), "malloc");
  41. return _msvcrt_malloc(size);
  42. }
  43. #endif
  44. #ifdef USE_THREADS
  45. PerlInterpreter *parent_perl = NULL;
  46. extern PerlInterpreter *parent_perl;
  47. PerlInterpreter *current_perl = NULL;
  48. #define GET_TLS_CONTEXT eval_pv("require DynaLoader;", TRUE); \
  49. if(!current_perl) { \
  50. parent_perl = PERL_GET_CONTEXT; \
  51. current_perl = perl_clone(parent_perl, CLONEf_KEEP_PTR_TABLE); \
  52. PERL_SET_CONTEXT(parent_perl); \
  53. }
  54. #define ENTER_TLS_CONTEXT { \
  55. if(!PERL_GET_CONTEXT) { \
  56. PERL_SET_CONTEXT(current_perl); \
  57. }
  58. #define LEAVE_TLS_CONTEXT }
  59. #else
  60. PerlInterpreter *parent_perl = NULL;
  61. extern PerlInterpreter *parent_perl;
  62. #define GET_TLS_CONTEXT /* TLS context not enabled */
  63. #define ENTER_TLS_CONTEXT /* TLS context not enabled */
  64. #define LEAVE_TLS_CONTEXT /* TLS context not enabled */
  65. #endif
  66. /* VERSION_ATLEAST(have_triplet, need_triplet) */
  67. #define VERSION_ATLEAST(a, b, c, d, e, f) (a > d || (a == d && b > e) \
  68. || (a == d && b == e && c >= f))
  69. #endif