PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/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
32#ifndef SDL_PERL_DEFINES_H
33#define SDL_PERL_DEFINES_H
34
35#ifdef _WIN32
36#include <windows.h>
37typedef void* (*malloc_t)(int size);
38malloc_t _msvcrt_malloc = NULL;
39extern malloc_t _msvcrt_malloc;
40
41void *msvcrt_malloc(int size) {
42	if (!_msvcrt_malloc)
43		_msvcrt_malloc = (malloc_t)GetProcAddress(GetModuleHandle("msvcrt"), "malloc");
44    return _msvcrt_malloc(size);
45}
46#endif
47
48#ifdef USE_THREADS
49PerlInterpreter *parent_perl = NULL;
50extern PerlInterpreter *parent_perl;
51PerlInterpreter *current_perl = NULL;
52#define GET_TLS_CONTEXT eval_pv("require DynaLoader;", TRUE); \
53        if(!current_perl) { \
54            parent_perl = PERL_GET_CONTEXT; \
55            current_perl = perl_clone(parent_perl, CLONEf_KEEP_PTR_TABLE); \
56            PERL_SET_CONTEXT(parent_perl); \
57        }
58#define ENTER_TLS_CONTEXT { \
59            if(!PERL_GET_CONTEXT) { \
60                PERL_SET_CONTEXT(current_perl); \
61            }
62#define LEAVE_TLS_CONTEXT }
63#else
64PerlInterpreter *parent_perl = NULL;
65extern PerlInterpreter *parent_perl;
66#define GET_TLS_CONTEXT         /* TLS context not enabled */
67#define ENTER_TLS_CONTEXT       /* TLS context not enabled */
68#define LEAVE_TLS_CONTEXT       /* TLS context not enabled */
69#endif
70
71/* VERSION_ATLEAST(have_triplet, need_triplet) */
72#define VERSION_ATLEAST(a, b, c, d, e, f) (a > d || (a == d && b > e) \
73                                           || (a == d && b == e && c >= f))
74
75#endif