File: gmem.h

package info (click to toggle)
wine-gecko-2.24 2.24%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 740,092 kB
  • ctags: 688,789
  • sloc: cpp: 3,160,639; ansic: 1,619,153; python: 164,084; java: 128,022; asm: 114,527; xml: 69,863; sh: 55,281; makefile: 49,648; perl: 20,454; objc: 2,344; yacc: 2,066; pascal: 995; lex: 982; exp: 449; php: 244; lisp: 228; awk: 211; sed: 61; csh: 21; ada: 16; ruby: 3
file content (56 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (19)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GMEM_WRAPPER_H
#define GMEM_WRAPPER_H

#define g_malloc_n g_malloc_n_
#define g_malloc0_n g_malloc0_n_
#define g_realloc_n g_realloc_n_
#include_next <glib/gmem.h>
#undef g_malloc_n
#undef g_malloc0_n
#undef g_realloc_n

#include <glib/gmessages.h>

#undef g_new
#define g_new(type, num) \
    ((type *) g_malloc_n((num), sizeof(type)))

#undef g_new0
#define g_new0(type, num) \
    ((type *) g_malloc0_n((num), sizeof(type)))

#undef g_renew
#define g_renew(type, ptr, num) \
    ((type *) g_realloc_n(ptr, (num), sizeof(type)))

#define _CHECK_OVERFLOW(num, type_size) \
    if (G_UNLIKELY(type_size > 0 && num > G_MAXSIZE / type_size)) { \
      g_error("%s: overflow allocating %" G_GSIZE_FORMAT "*%" G_GSIZE_FORMAT " bytes", \
              G_STRLOC, num, type_size); \
    }

static inline gpointer
g_malloc_n(gsize num, gsize type_size)
{
  _CHECK_OVERFLOW(num, type_size)
  return g_malloc(num * type_size);
}

static inline gpointer
g_malloc0_n(gsize num, gsize type_size)
{
  _CHECK_OVERFLOW(num, type_size)
  return g_malloc0(num * type_size);
}

static inline gpointer
g_realloc_n(gpointer ptr, gsize num, gsize type_size)
{
  _CHECK_OVERFLOW(num, type_size)
  return g_realloc(ptr, num * type_size);
}
#endif /* GMEM_WRAPPER_H */