Subversion Repositories Kolibri OS

Rev

Rev 1892 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1892 Rev 3959
Line 36... Line 36...
36
 
36
 
37
#ifndef CAIRO_MALLOC_PRIVATE_H
37
#ifndef CAIRO_MALLOC_PRIVATE_H
Line 38... Line 38...
38
#define CAIRO_MALLOC_PRIVATE_H
38
#define CAIRO_MALLOC_PRIVATE_H
-
 
39
 
Line 39... Line 40...
39
 
40
#include "cairo-wideint-private.h"
40
#include "cairo-wideint-private.h"
41
#include 
41
 
42
 
42
#if HAVE_MEMFAULT
43
#if HAVE_MEMFAULT
Line 54... Line 55...
54
 * The memory should be freed using free().
55
 * The memory should be freed using free().
55
 * malloc is skipped, if 0 bytes are requested, and %NULL will be returned.
56
 * malloc is skipped, if 0 bytes are requested, and %NULL will be returned.
56
 *
57
 *
57
 * Return value: A pointer to the newly allocated memory, or %NULL in
58
 * Return value: A pointer to the newly allocated memory, or %NULL in
58
 * case of malloc() failure or size is 0.
59
 * case of malloc() failure or size is 0.
59
 */
60
 **/
Line 60... Line 61...
60
 
61
 
61
#define _cairo_malloc(size) \
62
#define _cairo_malloc(size) \
Line 62... Line 63...
62
   ((size) ? malloc((unsigned) (size)) : NULL)
63
   ((size) ? malloc((unsigned) (size)) : NULL)
63
 
64
 
64
/**
65
/**
65
 * _cairo_malloc_ab:
66
 * _cairo_malloc_ab:
66
 * @n: number of elements to allocate
67
 * @a: number of elements to allocate
67
 * @size: size of each element
68
 * @size: size of each element
68
 *
69
 *
69
 * Allocates @n*@size memory using _cairo_malloc(), taking care to not
70
 * Allocates @a*@size memory using _cairo_malloc(), taking care to not
70
 * overflow when doing the multiplication.  Behaves much like
71
 * overflow when doing the multiplication.  Behaves much like
71
 * calloc(), except that the returned memory is not set to zero.
72
 * calloc(), except that the returned memory is not set to zero.
72
 * The memory should be freed using free().
73
 * The memory should be freed using free().
73
 *
74
 *
74
 * @size should be a constant so that the compiler can optimize
75
 * @size should be a constant so that the compiler can optimize
75
 * out a constant division.
76
 * out a constant division.
76
 *
77
 *
77
 * Return value: A pointer to the newly allocated memory, or %NULL in
78
 * Return value: A pointer to the newly allocated memory, or %NULL in
Line 78... Line 79...
78
 * case of malloc() failure or overflow.
79
 * case of malloc() failure or overflow.
79
 */
80
 **/
80
 
81
 
Line 81... Line 82...
81
#define _cairo_malloc_ab(a, size) \
82
#define _cairo_malloc_ab(a, size) \
82
  ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \
83
  ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \
83
   _cairo_malloc((unsigned) (a) * (unsigned) (size)))
84
   _cairo_malloc((unsigned) (a) * (unsigned) (size)))
84
 
85
 
85
/**
86
/**
86
 * _cairo_realloc_ab:
87
 * _cairo_realloc_ab:
87
 * @ptr: original pointer to block of memory to be resized
88
 * @ptr: original pointer to block of memory to be resized
88
 * @n: number of elements to allocate
89
 * @a: number of elements to allocate
89
 * @size: size of each element
90
 * @size: size of each element
90
 *
91
 *
91
 * Reallocates @ptr a block of @n*@size memory using realloc(), taking
92
 * Reallocates @ptr a block of @a*@size memory using realloc(), taking
92
 * care to not overflow when doing the multiplication.  The memory
93
 * care to not overflow when doing the multiplication.  The memory
93
 * should be freed using free().
94
 * should be freed using free().
94
 *
95
 *
95
 * @size should be a constant so that the compiler can optimize
96
 * @size should be a constant so that the compiler can optimize
96
 * out a constant division.
97
 * out a constant division.
97
 *
98
 *
Line 98... Line 99...
98
 * Return value: A pointer to the newly allocated memory, or %NULL in
99
 * Return value: A pointer to the newly allocated memory, or %NULL in
99
 * case of realloc() failure or overflow (whereupon the original block
100
 * case of realloc() failure or overflow (whereupon the original block
100
 * of memory * is left untouched).
101
 * of memory * is left untouched).
Line 101... Line 102...
101
 */
102
 **/
102
 
103
 
103
#define _cairo_realloc_ab(ptr, a, size) \
104
#define _cairo_realloc_ab(ptr, a, size) \
104
  ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \
105
  ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \
105
   realloc(ptr, (unsigned) (a) * (unsigned) (size)))
106
   realloc(ptr, (unsigned) (a) * (unsigned) (size)))
106
 
107
 
107
/**
108
/**
108
 * _cairo_malloc_abc:
109
 * _cairo_malloc_abc:
109
 * @n: first factor of number of elements to allocate
110
 * @a: first factor of number of elements to allocate
110
 * @b: second factor of number of elements to allocate
111
 * @b: second factor of number of elements to allocate
111
 * @size: size of each element
112
 * @size: size of each element
112
 *
113
 *
113
 * Allocates @n*@b*@size memory using _cairo_malloc(), taking care to not
114
 * Allocates @a*@b*@size memory using _cairo_malloc(), taking care to not
114
 * overflow when doing the multiplication.  Behaves like
115
 * overflow when doing the multiplication.  Behaves like
115
 * _cairo_malloc_ab().  The memory should be freed using free().
116
 * _cairo_malloc_ab().  The memory should be freed using free().
116
 *
117
 *
Line 117... Line 118...
117
 * @size should be a constant so that the compiler can optimize
118
 * @size should be a constant so that the compiler can optimize
118
 * out a constant division.
119
 * out a constant division.
119
 *
120
 *
120
 * Return value: A pointer to the newly allocated memory, or %NULL in
121
 * Return value: A pointer to the newly allocated memory, or %NULL in
Line 121... Line 122...
121
 * case of malloc() failure or overflow.
122
 * case of malloc() failure or overflow.
122
 */
123
 **/
123
 
124
 
124
#define _cairo_malloc_abc(a, b, size) \
125
#define _cairo_malloc_abc(a, b, size) \
125
  ((b) && (unsigned) (a) >= INT32_MAX / (unsigned) (b) ? NULL : \
126
  ((b) && (unsigned) (a) >= INT32_MAX / (unsigned) (b) ? NULL : \
126
   (size) && (unsigned) ((a)*(b)) >= INT32_MAX / (unsigned) (size) ? NULL : \
127
   (size) && (unsigned) ((a)*(b)) >= INT32_MAX / (unsigned) (size) ? NULL : \
127
   _cairo_malloc((unsigned) (a) * (unsigned) (b) * (unsigned) (size)))
128
   _cairo_malloc((unsigned) (a) * (unsigned) (b) * (unsigned) (size)))
128
 
129
 
129
/**
130
/**
130
 * _cairo_malloc_ab_plus_c:
131
 * _cairo_malloc_ab_plus_c:
131
 * @n: number of elements to allocate
132
 * @a: number of elements to allocate
132
 * @size: size of each element
133
 * @size: size of each element
133
 * @k: additional size to allocate
134
 * @c: additional size to allocate
Line 134... Line 135...
134
 *
135
 *
135
 * Allocates @n*@ksize+@k memory using _cairo_malloc(), taking care to not
136
 * Allocates @a*@size+@c memory using _cairo_malloc(), taking care to not
136
 * overflow when doing the arithmetic.  Behaves like
137
 * overflow when doing the arithmetic.  Behaves similar to
137
 * _cairo_malloc_ab().  The memory should be freed using free().
138
 * _cairo_malloc_ab().  The memory should be freed using free().
Line 138... Line 139...
138
 *
139
 *