1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/* This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdbool.h>
#include <gpython/gpython.h>
#include <gpython/objects.h>
#include <gpython/vectors.h>
#include <gpython/garbage.h>
#ifndef HAVE_STRDUP
char * gpy_strdup( const char * str )
{
register size_t len= (gpy_strlen( str )+1);
register char *ret= gpy_malloc( len );
memcpy(ret, str, len);
return ret;
}
#endif
inline
void gpy_assertion_failed( const char * expr, unsigned line,
const char * file, const char * func )
{
fprintf( stderr, "assertion of <%s> failed at <%s:%s:%u>!\n",
expr, file, func, line );
/* Call cleanups .... */
exit( EXIT_FAILURE );
}
#ifdef DEBUG
inline
void __gpy_debug__( const char * file, unsigned line,
const char * functor, const char * fmt, ... )
{
fprintf( stderr, "debug: <%s:%s:%u> -> ",
file, functor, line );
va_list args;
va_start( args, fmt );
vfprintf( stderr, fmt, args );
va_end( args );
}
#endif
inline
void __gpy_error__( const char * file, unsigned line,
const char * functor, const char * fmt, ... )
{
fprintf( stderr, "error: <%s:%s:%u> -> ",
file, functor, line );
va_list args;
va_start( args, fmt );
vfprintf( stderr, fmt, args );
va_end( args );
}
inline
void __gpy_fatal__( const char * file, unsigned line,
const char * functor, const char * fmt, ... )
{
fprintf( stderr, "fatal: <%s:%s:%u> -> ",
file, functor, line );
va_list args;
va_start( args, fmt );
vfprintf( stderr, fmt, args );
va_end( args );
/* Call cleanups .... */
exit( EXIT_FAILURE );
}
/* --- memory allocators --- */
inline
void * gpy_malloc( size_t s )
{
register void * retval = malloc( s );
if( !retval )
fatal("virtual memory exhausted!\n");
return retval;
}
inline
void * gpy_realloc( void * p, size_t s )
{
register void * retval = realloc( p, s );
if( !retval )
fatal("virtual memory exhausted!\n");
return retval;
}
inline
void * gpy_calloc( size_t n, size_t s )
{
register void * retval = calloc( n , s );
if( !retval )
fatal("virtual memory exhausted!\n");
return retval;
}
|