Line | Count | Source (jump to first uncovered line) |
1 | | /* GLIB - Library of useful routines for C programming |
2 | | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
3 | | * |
4 | | * This library is free software; you can redistribute it and/or |
5 | | * modify it under the terms of the GNU Lesser General Public |
6 | | * License as published by the Free Software Foundation; either |
7 | | * version 2.1 of the License, or (at your option) any later version. |
8 | | * |
9 | | * This library is distributed in the hope that it will be useful, |
10 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | | * Lesser General Public License for more details. |
13 | | * |
14 | | * You should have received a copy of the GNU Lesser General Public |
15 | | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | |
18 | | /* |
19 | | * Modified by the GLib Team and others 1997-2000. See the AUTHORS |
20 | | * file for a list of people on the GLib Team. See the ChangeLog |
21 | | * files for a list of changes. These files are distributed with |
22 | | * GLib at ftp://ftp.gtk.org/pub/gtk/. |
23 | | */ |
24 | | |
25 | | #ifndef __G_MEM_H__ |
26 | | #define __G_MEM_H__ |
27 | | |
28 | | #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) |
29 | | #error "Only <glib.h> can be included directly." |
30 | | #endif |
31 | | |
32 | | #include <glib/gutils.h> |
33 | | |
34 | | #if defined(glib_typeof_2_68) && GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68 |
35 | | /* for glib_typeof */ |
36 | | #include <type_traits> |
37 | | #endif |
38 | | |
39 | | G_BEGIN_DECLS |
40 | | |
41 | | /** |
42 | | * GMemVTable: |
43 | | * @malloc: function to use for allocating memory. |
44 | | * @realloc: function to use for reallocating memory. |
45 | | * @free: function to use to free memory. |
46 | | * @calloc: function to use for allocating zero-filled memory. |
47 | | * @try_malloc: function to use for allocating memory without a default error handler. |
48 | | * @try_realloc: function to use for reallocating memory without a default error handler. |
49 | | * |
50 | | * A set of functions used to perform memory allocation. The same #GMemVTable must |
51 | | * be used for all allocations in the same program; a call to g_mem_set_vtable(), |
52 | | * if it exists, should be prior to any use of GLib. |
53 | | * |
54 | | * This functions related to this has been deprecated in 2.46, and no longer work. |
55 | | */ |
56 | | typedef struct _GMemVTable GMemVTable; |
57 | | |
58 | | |
59 | | #if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG |
60 | | /** |
61 | | * G_MEM_ALIGN: |
62 | | * |
63 | | * Indicates the number of bytes to which memory will be aligned on the |
64 | | * current platform. |
65 | | */ |
66 | | # define G_MEM_ALIGN GLIB_SIZEOF_VOID_P |
67 | | #else /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */ |
68 | | # define G_MEM_ALIGN GLIB_SIZEOF_LONG |
69 | | #endif /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */ |
70 | | |
71 | | |
72 | | /* Memory allocation functions |
73 | | */ |
74 | | |
75 | | GLIB_AVAILABLE_IN_ALL |
76 | | void g_free (gpointer mem); |
77 | | |
78 | | GLIB_AVAILABLE_IN_2_34 |
79 | | void g_clear_pointer (gpointer *pp, |
80 | | GDestroyNotify destroy); |
81 | | |
82 | | GLIB_AVAILABLE_IN_ALL |
83 | | gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); |
84 | | GLIB_AVAILABLE_IN_ALL |
85 | | gpointer g_malloc0 (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); |
86 | | GLIB_AVAILABLE_IN_ALL |
87 | | gpointer g_realloc (gpointer mem, |
88 | | gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT; |
89 | | GLIB_AVAILABLE_IN_ALL |
90 | | gpointer g_try_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); |
91 | | GLIB_AVAILABLE_IN_ALL |
92 | | gpointer g_try_malloc0 (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); |
93 | | GLIB_AVAILABLE_IN_ALL |
94 | | gpointer g_try_realloc (gpointer mem, |
95 | | gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT; |
96 | | |
97 | | GLIB_AVAILABLE_IN_ALL |
98 | | gpointer g_malloc_n (gsize n_blocks, |
99 | | gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2); |
100 | | GLIB_AVAILABLE_IN_ALL |
101 | | gpointer g_malloc0_n (gsize n_blocks, |
102 | | gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2); |
103 | | GLIB_AVAILABLE_IN_ALL |
104 | | gpointer g_realloc_n (gpointer mem, |
105 | | gsize n_blocks, |
106 | | gsize n_block_bytes) G_GNUC_WARN_UNUSED_RESULT; |
107 | | GLIB_AVAILABLE_IN_ALL |
108 | | gpointer g_try_malloc_n (gsize n_blocks, |
109 | | gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2); |
110 | | GLIB_AVAILABLE_IN_ALL |
111 | | gpointer g_try_malloc0_n (gsize n_blocks, |
112 | | gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2); |
113 | | GLIB_AVAILABLE_IN_ALL |
114 | | gpointer g_try_realloc_n (gpointer mem, |
115 | | gsize n_blocks, |
116 | | gsize n_block_bytes) G_GNUC_WARN_UNUSED_RESULT; |
117 | | |
118 | | #if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58 && (!defined(glib_typeof_2_68) || GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68) |
119 | | #define g_clear_pointer(pp, destroy) \ |
120 | 0 | G_STMT_START \ |
121 | 0 | { \ |
122 | 0 | G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \ |
123 | 0 | glib_typeof ((pp)) _pp = (pp); \ |
124 | 0 | glib_typeof (*(pp)) _ptr = *_pp; \ |
125 | 0 | *_pp = NULL; \ |
126 | 0 | if (_ptr) \ |
127 | 0 | (destroy) (_ptr); \ |
128 | 0 | } \ |
129 | 0 | G_STMT_END \ |
130 | 0 | GLIB_AVAILABLE_MACRO_IN_2_34 |
131 | | #else /* __GNUC__ */ |
132 | | #define g_clear_pointer(pp, destroy) \ |
133 | | G_STMT_START { \ |
134 | | G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \ |
135 | | /* Only one access, please; work around type aliasing */ \ |
136 | | union { char *in; gpointer *out; } _pp; \ |
137 | | gpointer _p; \ |
138 | | /* This assignment is needed to avoid a gcc warning */ \ |
139 | | GDestroyNotify _destroy = (GDestroyNotify) (destroy); \ |
140 | | \ |
141 | | _pp.in = (char *) (pp); \ |
142 | | _p = *_pp.out; \ |
143 | | if (_p) \ |
144 | | { \ |
145 | | *_pp.out = NULL; \ |
146 | | _destroy (_p); \ |
147 | | } \ |
148 | | } G_STMT_END \ |
149 | | GLIB_AVAILABLE_MACRO_IN_2_34 |
150 | | #endif /* __GNUC__ */ |
151 | | |
152 | | /** |
153 | | * g_steal_pointer: |
154 | | * @pp: (not nullable): a pointer to a pointer |
155 | | * |
156 | | * Sets @pp to %NULL, returning the value that was there before. |
157 | | * |
158 | | * Conceptually, this transfers the ownership of the pointer from the |
159 | | * referenced variable to the "caller" of the macro (ie: "steals" the |
160 | | * reference). |
161 | | * |
162 | | * The return value will be properly typed, according to the type of |
163 | | * @pp. |
164 | | * |
165 | | * This can be very useful when combined with g_autoptr() to prevent the |
166 | | * return value of a function from being automatically freed. Consider |
167 | | * the following example (which only works on GCC and clang): |
168 | | * |
169 | | * |[ |
170 | | * GObject * |
171 | | * create_object (void) |
172 | | * { |
173 | | * g_autoptr(GObject) obj = g_object_new (G_TYPE_OBJECT, NULL); |
174 | | * |
175 | | * if (early_error_case) |
176 | | * return NULL; |
177 | | * |
178 | | * return g_steal_pointer (&obj); |
179 | | * } |
180 | | * ]| |
181 | | * |
182 | | * It can also be used in similar ways for 'out' parameters and is |
183 | | * particularly useful for dealing with optional out parameters: |
184 | | * |
185 | | * |[ |
186 | | * gboolean |
187 | | * get_object (GObject **obj_out) |
188 | | * { |
189 | | * g_autoptr(GObject) obj = g_object_new (G_TYPE_OBJECT, NULL); |
190 | | * |
191 | | * if (early_error_case) |
192 | | * return FALSE; |
193 | | * |
194 | | * if (obj_out) |
195 | | * *obj_out = g_steal_pointer (&obj); |
196 | | * |
197 | | * return TRUE; |
198 | | * } |
199 | | * ]| |
200 | | * |
201 | | * In the above example, the object will be automatically freed in the |
202 | | * early error case and also in the case that %NULL was given for |
203 | | * @obj_out. |
204 | | * |
205 | | * Since: 2.44 |
206 | | */ |
207 | | GLIB_AVAILABLE_STATIC_INLINE_IN_2_44 |
208 | | static inline gpointer |
209 | | g_steal_pointer (gpointer pp) |
210 | 11.6M | { |
211 | 11.6M | gpointer *ptr = (gpointer *) pp; |
212 | 11.6M | gpointer ref; |
213 | | |
214 | 11.6M | ref = *ptr; |
215 | 11.6M | *ptr = NULL; |
216 | | |
217 | 11.6M | return ref; |
218 | 11.6M | } Unexecuted instantiation: gconverter.c:g_steal_pointer Unexecuted instantiation: gconverterinputstream.c:g_steal_pointer Unexecuted instantiation: gfile.c:g_steal_pointer Unexecuted instantiation: gfileattribute.c:g_steal_pointer Unexecuted instantiation: gfileinfo.c:g_steal_pointer Unexecuted instantiation: gfileinputstream.c:g_steal_pointer Unexecuted instantiation: gfilemonitor.c:g_steal_pointer Unexecuted instantiation: gfileoutputstream.c:g_steal_pointer Unexecuted instantiation: gfilterinputstream.c:g_steal_pointer Unexecuted instantiation: gicon.c:g_steal_pointer Unexecuted instantiation: ginputstream.c:g_steal_pointer Unexecuted instantiation: gioerror.c:g_steal_pointer Unexecuted instantiation: gmarshal-internal.c:g_steal_pointer Unexecuted instantiation: gmemoryinputstream.c:g_steal_pointer Unexecuted instantiation: goutputstream.c:g_steal_pointer Unexecuted instantiation: gpollableinputstream.c:g_steal_pointer Unexecuted instantiation: gpollableoutputstream.c:g_steal_pointer Unexecuted instantiation: gpollableutils.c:g_steal_pointer Unexecuted instantiation: gpollfilemonitor.c:g_steal_pointer Unexecuted instantiation: gresource.c:g_steal_pointer Unexecuted instantiation: gseekable.c:g_steal_pointer Unexecuted instantiation: gtask.c:g_steal_pointer Unexecuted instantiation: gthemedicon.c:g_steal_pointer Unexecuted instantiation: gvfs.c:g_steal_pointer Unexecuted instantiation: gzlibcompressor.c:g_steal_pointer Unexecuted instantiation: gzlibdecompressor.c:g_steal_pointer Unexecuted instantiation: gdesktopappinfo.c:g_steal_pointer Unexecuted instantiation: gcontenttype.c:g_steal_pointer Unexecuted instantiation: gfiledescriptorbased.c:g_steal_pointer Unexecuted instantiation: gvdb-reader.c:g_steal_pointer Unexecuted instantiation: gdbusutils.c:g_steal_pointer Unexecuted instantiation: gdbuserror.c:g_steal_pointer Unexecuted instantiation: gdbusconnection.c:g_steal_pointer Unexecuted instantiation: gdbusmessage.c:g_steal_pointer Unexecuted instantiation: gdbusproxy.c:g_steal_pointer Unexecuted instantiation: gdbusprivate.c:g_steal_pointer Unexecuted instantiation: gdbusintrospection.c:g_steal_pointer Unexecuted instantiation: gdbusmethodinvocation.c:g_steal_pointer Unexecuted instantiation: gdbusinterface.c:g_steal_pointer Unexecuted instantiation: gdbusobject.c:g_steal_pointer Unexecuted instantiation: gdocumentportal.c:g_steal_pointer Unexecuted instantiation: glocalfile.c:g_steal_pointer Unexecuted instantiation: glocalfileenumerator.c:g_steal_pointer Unexecuted instantiation: glocalfileinfo.c:g_steal_pointer Unexecuted instantiation: glocalfileinputstream.c:g_steal_pointer Unexecuted instantiation: glocalfilemonitor.c:g_steal_pointer Unexecuted instantiation: glocalfileoutputstream.c:g_steal_pointer Unexecuted instantiation: glocalfileiostream.c:g_steal_pointer Unexecuted instantiation: glocalvfs.c:g_steal_pointer Unexecuted instantiation: thumbnail-verify.c:g_steal_pointer Unexecuted instantiation: gioenumtypes.c:g_steal_pointer Unexecuted instantiation: xdp-dbus.c:g_steal_pointer Unexecuted instantiation: gappinfo.c:g_steal_pointer Unexecuted instantiation: gasyncinitable.c:g_steal_pointer Unexecuted instantiation: gasyncresult.c:g_steal_pointer Unexecuted instantiation: gbytesicon.c:g_steal_pointer Unexecuted instantiation: gcancellable.c:g_steal_pointer Unexecuted instantiation: gcontextspecificgroup.c:g_steal_pointer Unexecuted instantiation: gdummyfile.c:g_steal_pointer Unexecuted instantiation: gemblem.c:g_steal_pointer Unexecuted instantiation: gemblemedicon.c:g_steal_pointer Unexecuted instantiation: gfileenumerator.c:g_steal_pointer Unexecuted instantiation: gfileicon.c:g_steal_pointer Unexecuted instantiation: gfileiostream.c:g_steal_pointer Unexecuted instantiation: ginitable.c:g_steal_pointer Unexecuted instantiation: giomodule.c:g_steal_pointer Unexecuted instantiation: giomodule-priv.c:g_steal_pointer Unexecuted instantiation: giostream.c:g_steal_pointer Unexecuted instantiation: gloadableicon.c:g_steal_pointer Unexecuted instantiation: gmemorymonitor.c:g_steal_pointer Unexecuted instantiation: gmemorymonitordbus.c:g_steal_pointer Unexecuted instantiation: gnativevolumemonitor.c:g_steal_pointer Unexecuted instantiation: gnetworkmonitor.c:g_steal_pointer Unexecuted instantiation: gnetworkmonitorbase.c:g_steal_pointer Unexecuted instantiation: gproxy.c:g_steal_pointer Unexecuted instantiation: gproxyresolver.c:g_steal_pointer Unexecuted instantiation: gresourcefile.c:g_steal_pointer Unexecuted instantiation: gsimpleasyncresult.c:g_steal_pointer Unexecuted instantiation: gsocket.c:g_steal_pointer Unexecuted instantiation: gsocketaddress.c:g_steal_pointer Unexecuted instantiation: gsocketaddressenumerator.c:g_steal_pointer Unexecuted instantiation: gsocketconnectable.c:g_steal_pointer Unexecuted instantiation: gsocketconnection.c:g_steal_pointer Unexecuted instantiation: gsocketcontrolmessage.c:g_steal_pointer Unexecuted instantiation: gsocketinputstream.c:g_steal_pointer Unexecuted instantiation: gsocketoutputstream.c:g_steal_pointer Unexecuted instantiation: gtcpconnection.c:g_steal_pointer Unexecuted instantiation: gtlsbackend.c:g_steal_pointer Unexecuted instantiation: gtlsdatabase.c:g_steal_pointer Unexecuted instantiation: gtlsinteraction.c:g_steal_pointer Unexecuted instantiation: gtlspassword.c:g_steal_pointer Unexecuted instantiation: gunionvolumemonitor.c:g_steal_pointer Unexecuted instantiation: gvolumemonitor.c:g_steal_pointer Unexecuted instantiation: gunixconnection.c:g_steal_pointer Unexecuted instantiation: gunixcredentialsmessage.c:g_steal_pointer Unexecuted instantiation: gunixfdlist.c:g_steal_pointer Unexecuted instantiation: gunixfdmessage.c:g_steal_pointer Unexecuted instantiation: gunixmounts.c:g_steal_pointer Unexecuted instantiation: gunixsocketaddress.c:g_steal_pointer Unexecuted instantiation: gunixvolumemonitor.c:g_steal_pointer Unexecuted instantiation: gfdonotificationbackend.c:g_steal_pointer Unexecuted instantiation: ggtknotificationbackend.c:g_steal_pointer Unexecuted instantiation: gnetworkmonitornetlink.c:g_steal_pointer Unexecuted instantiation: gnetworkmonitornm.c:g_steal_pointer Unexecuted instantiation: gapplication.c:g_steal_pointer Unexecuted instantiation: gapplicationcommandline.c:g_steal_pointer Unexecuted instantiation: gapplicationimpl-dbus.c:g_steal_pointer Unexecuted instantiation: gactiongroup.c:g_steal_pointer Unexecuted instantiation: gactionmap.c:g_steal_pointer Unexecuted instantiation: gsimpleactiongroup.c:g_steal_pointer Unexecuted instantiation: gremoteactiongroup.c:g_steal_pointer Unexecuted instantiation: gactiongroupexporter.c:g_steal_pointer Unexecuted instantiation: gdbusactiongroup.c:g_steal_pointer Unexecuted instantiation: gaction.c:g_steal_pointer Unexecuted instantiation: gsimpleaction.c:g_steal_pointer Unexecuted instantiation: gnotification.c:g_steal_pointer Unexecuted instantiation: gnotificationbackend.c:g_steal_pointer Unexecuted instantiation: gkeyfilesettingsbackend.c:g_steal_pointer Unexecuted instantiation: gmemorysettingsbackend.c:g_steal_pointer Unexecuted instantiation: gnullsettingsbackend.c:g_steal_pointer Unexecuted instantiation: gsettingsbackend.c:g_steal_pointer Unexecuted instantiation: gsettings.c:g_steal_pointer Unexecuted instantiation: gdbusaddress.c:g_steal_pointer Unexecuted instantiation: gdbusauthobserver.c:g_steal_pointer Unexecuted instantiation: gdbusauth.c:g_steal_pointer Unexecuted instantiation: gdbusauthmechanism.c:g_steal_pointer Unexecuted instantiation: gdbusauthmechanismanon.c:g_steal_pointer Unexecuted instantiation: gdbusauthmechanismexternal.c:g_steal_pointer Unexecuted instantiation: gdbusauthmechanismsha1.c:g_steal_pointer Unexecuted instantiation: gdbusnamewatching.c:g_steal_pointer Unexecuted instantiation: gdbusinterfaceskeleton.c:g_steal_pointer Unexecuted instantiation: gdbusobjectskeleton.c:g_steal_pointer Unexecuted instantiation: gopenuriportal.c:g_steal_pointer Unexecuted instantiation: gmemorymonitorportal.c:g_steal_pointer Unexecuted instantiation: gnetworkmonitorportal.c:g_steal_pointer Unexecuted instantiation: gproxyresolverportal.c:g_steal_pointer Unexecuted instantiation: gtrashportal.c:g_steal_pointer Unexecuted instantiation: gportalsupport.c:g_steal_pointer Unexecuted instantiation: gportalnotificationbackend.c:g_steal_pointer Unexecuted instantiation: ghttpproxy.c:g_steal_pointer Unexecuted instantiation: gsocks4proxy.c:g_steal_pointer Unexecuted instantiation: gsocks4aproxy.c:g_steal_pointer Unexecuted instantiation: gsocks5proxy.c:g_steal_pointer Unexecuted instantiation: ginotifyfilemonitor.c:g_steal_pointer Unexecuted instantiation: gcredentials.c:g_steal_pointer Unexecuted instantiation: gdatagrambased.c:g_steal_pointer Unexecuted instantiation: gdatainputstream.c:g_steal_pointer Unexecuted instantiation: gdataoutputstream.c:g_steal_pointer Unexecuted instantiation: gdrive.c:g_steal_pointer Unexecuted instantiation: gdummyproxyresolver.c:g_steal_pointer Unexecuted instantiation: gdummytlsbackend.c:g_steal_pointer Unexecuted instantiation: gfilteroutputstream.c:g_steal_pointer Unexecuted instantiation: ginetaddress.c:g_steal_pointer Unexecuted instantiation: ginetaddressmask.c:g_steal_pointer Unexecuted instantiation: ginetsocketaddress.c:g_steal_pointer Unexecuted instantiation: gioscheduler.c:g_steal_pointer Unexecuted instantiation: gmount.c:g_steal_pointer Unexecuted instantiation: gnativesocketaddress.c:g_steal_pointer Unexecuted instantiation: gnetworkaddress.c:g_steal_pointer Unexecuted instantiation: gnetworking.c:g_steal_pointer Unexecuted instantiation: gproxyaddress.c:g_steal_pointer Unexecuted instantiation: gproxyaddressenumerator.c:g_steal_pointer Unexecuted instantiation: gresolver.c:g_steal_pointer Unexecuted instantiation: gsimplepermission.c:g_steal_pointer Unexecuted instantiation: gsocketclient.c:g_steal_pointer Unexecuted instantiation: gsrvtarget.c:g_steal_pointer Unexecuted instantiation: gtcpwrapperconnection.c:g_steal_pointer Unexecuted instantiation: gthreadedresolver.c:g_steal_pointer Unexecuted instantiation: gtlscertificate.c:g_steal_pointer Unexecuted instantiation: gtlsclientconnection.c:g_steal_pointer Unexecuted instantiation: gtlsconnection.c:g_steal_pointer Unexecuted instantiation: gtlsfiledatabase.c:g_steal_pointer Unexecuted instantiation: gtlsserverconnection.c:g_steal_pointer Unexecuted instantiation: gdtlsconnection.c:g_steal_pointer Unexecuted instantiation: gdtlsclientconnection.c:g_steal_pointer Unexecuted instantiation: gdtlsserverconnection.c:g_steal_pointer Unexecuted instantiation: gvolume.c:g_steal_pointer Unexecuted instantiation: gunixmount.c:g_steal_pointer Unexecuted instantiation: gunixvolume.c:g_steal_pointer Unexecuted instantiation: gunixinputstream.c:g_steal_pointer Unexecuted instantiation: gdelayedsettingsbackend.c:g_steal_pointer Unexecuted instantiation: gsettingsschema.c:g_steal_pointer Unexecuted instantiation: gsettings-mapping.c:g_steal_pointer Unexecuted instantiation: inotify-sub.c:g_steal_pointer Unexecuted instantiation: inotify-helper.c:g_steal_pointer Unexecuted instantiation: gbufferedinputstream.c:g_steal_pointer Unexecuted instantiation: gnetworkservice.c:g_steal_pointer Unexecuted instantiation: gpermission.c:g_steal_pointer Unexecuted instantiation: gsubprocess.c:g_steal_pointer Unexecuted instantiation: giounix-private.c:g_steal_pointer Unexecuted instantiation: gunixoutputstream.c:g_steal_pointer Unexecuted instantiation: inotify-path.c:g_steal_pointer Unexecuted instantiation: inotify-missing.c:g_steal_pointer Unexecuted instantiation: gmemoryoutputstream.c:g_steal_pointer Unexecuted instantiation: inotify-kernel.c:g_steal_pointer Unexecuted instantiation: gmodule.c:g_steal_pointer Unexecuted instantiation: gboxed.c:g_steal_pointer Unexecuted instantiation: gclosure.c:g_steal_pointer Unexecuted instantiation: genums.c:g_steal_pointer Unexecuted instantiation: gmarshal.c:g_steal_pointer Unexecuted instantiation: gobject.c:g_steal_pointer Unexecuted instantiation: gparam.c:g_steal_pointer Unexecuted instantiation: gparamspecs.c:g_steal_pointer Unexecuted instantiation: gsignal.c:g_steal_pointer Unexecuted instantiation: gsourceclosure.c:g_steal_pointer Unexecuted instantiation: gtype.c:g_steal_pointer Unexecuted instantiation: gtypemodule.c:g_steal_pointer Unexecuted instantiation: gtypeplugin.c:g_steal_pointer Unexecuted instantiation: gvalue.c:g_steal_pointer Unexecuted instantiation: gvaluearray.c:g_steal_pointer Unexecuted instantiation: gvaluetransform.c:g_steal_pointer Unexecuted instantiation: gvaluetypes.c:g_steal_pointer Unexecuted instantiation: gatomicarray.c:g_steal_pointer Line | Count | Source | 210 | 11.5M | { | 211 | 11.5M | gpointer *ptr = (gpointer *) pp; | 212 | 11.5M | gpointer ref; | 213 | | | 214 | 11.5M | ref = *ptr; | 215 | 11.5M | *ptr = NULL; | 216 | | | 217 | 11.5M | return ref; | 218 | 11.5M | } |
Unexecuted instantiation: gbase64.c:g_steal_pointer Unexecuted instantiation: gbytes.c:g_steal_pointer Unexecuted instantiation: gcharset.c:g_steal_pointer Unexecuted instantiation: gchecksum.c:g_steal_pointer Unexecuted instantiation: gconvert.c:g_steal_pointer Unexecuted instantiation: gdataset.c:g_steal_pointer Unexecuted instantiation: gdate.c:g_steal_pointer Unexecuted instantiation: gdatetime.c:g_steal_pointer Unexecuted instantiation: gdir.c:g_steal_pointer Unexecuted instantiation: genviron.c:g_steal_pointer Unexecuted instantiation: gerror.c:g_steal_pointer Unexecuted instantiation: gfileutils.c:g_steal_pointer Unexecuted instantiation: ggettext.c:g_steal_pointer Line | Count | Source | 210 | 41.2k | { | 211 | 41.2k | gpointer *ptr = (gpointer *) pp; | 212 | 41.2k | gpointer ref; | 213 | | | 214 | 41.2k | ref = *ptr; | 215 | 41.2k | *ptr = NULL; | 216 | | | 217 | 41.2k | return ref; | 218 | 41.2k | } |
Unexecuted instantiation: ghook.c:g_steal_pointer Unexecuted instantiation: ghostutils.c:g_steal_pointer Unexecuted instantiation: giochannel.c:g_steal_pointer Unexecuted instantiation: gkeyfile.c:g_steal_pointer Unexecuted instantiation: glib-init.c:g_steal_pointer Unexecuted instantiation: glib-private.c:g_steal_pointer Unexecuted instantiation: glist.c:g_steal_pointer Unexecuted instantiation: gmain.c:g_steal_pointer Unexecuted instantiation: gmappedfile.c:g_steal_pointer Unexecuted instantiation: gmarkup.c:g_steal_pointer Unexecuted instantiation: gmem.c:g_steal_pointer Unexecuted instantiation: gmessages.c:g_steal_pointer Unexecuted instantiation: goption.c:g_steal_pointer Unexecuted instantiation: gpattern.c:g_steal_pointer Unexecuted instantiation: gpoll.c:g_steal_pointer Unexecuted instantiation: gqsort.c:g_steal_pointer Unexecuted instantiation: gquark.c:g_steal_pointer Unexecuted instantiation: gqueue.c:g_steal_pointer Unexecuted instantiation: grand.c:g_steal_pointer Unexecuted instantiation: grefstring.c:g_steal_pointer Unexecuted instantiation: gregex.c:g_steal_pointer Unexecuted instantiation: gscanner.c:g_steal_pointer Unexecuted instantiation: gsequence.c:g_steal_pointer Unexecuted instantiation: gshell.c:g_steal_pointer Unexecuted instantiation: gslice.c:g_steal_pointer Unexecuted instantiation: gslist.c:g_steal_pointer Unexecuted instantiation: gstdio.c:g_steal_pointer Unexecuted instantiation: gstrfuncs.c:g_steal_pointer Unexecuted instantiation: gstring.c:g_steal_pointer Unexecuted instantiation: gstrvbuilder.c:g_steal_pointer Unexecuted instantiation: gtestutils.c:g_steal_pointer gthread.c:g_steal_pointer Line | Count | Source | 210 | 87 | { | 211 | 87 | gpointer *ptr = (gpointer *) pp; | 212 | 87 | gpointer ref; | 213 | | | 214 | 87 | ref = *ptr; | 215 | 87 | *ptr = NULL; | 216 | | | 217 | 87 | return ref; | 218 | 87 | } |
Unexecuted instantiation: gthreadpool.c:g_steal_pointer Unexecuted instantiation: gtimer.c:g_steal_pointer Unexecuted instantiation: gtimezone.c:g_steal_pointer Unexecuted instantiation: gtranslit.c:g_steal_pointer Unexecuted instantiation: gtree.c:g_steal_pointer Unexecuted instantiation: guniprop.c:g_steal_pointer Unexecuted instantiation: gutf8.c:g_steal_pointer Unexecuted instantiation: gunicollate.c:g_steal_pointer Unexecuted instantiation: gunidecomp.c:g_steal_pointer Unexecuted instantiation: guri.c:g_steal_pointer Unexecuted instantiation: gutils.c:g_steal_pointer Unexecuted instantiation: gvariant.c:g_steal_pointer Unexecuted instantiation: gvariant-core.c:g_steal_pointer Unexecuted instantiation: gvariant-parser.c:g_steal_pointer Unexecuted instantiation: gvariant-serialiser.c:g_steal_pointer Unexecuted instantiation: gvarianttypeinfo.c:g_steal_pointer Unexecuted instantiation: gvarianttype.c:g_steal_pointer Unexecuted instantiation: gwakeup.c:g_steal_pointer Unexecuted instantiation: gprintf.c:g_steal_pointer Unexecuted instantiation: glib-unix.c:g_steal_pointer Unexecuted instantiation: gspawn.c:g_steal_pointer Unexecuted instantiation: giounix.c:g_steal_pointer Unexecuted instantiation: gthread-posix.c:g_steal_pointer Unexecuted instantiation: printf.c:g_steal_pointer Unexecuted instantiation: vasnprintf.c:g_steal_pointer Unexecuted instantiation: pcre_globals.c:g_steal_pointer Unexecuted instantiation: garcbox.c:g_steal_pointer Unexecuted instantiation: gasyncqueue.c:g_steal_pointer Unexecuted instantiation: gbitlock.c:g_steal_pointer Unexecuted instantiation: grcbox.c:g_steal_pointer Unexecuted instantiation: printf-args.c:g_steal_pointer Unexecuted instantiation: printf-parse.c:g_steal_pointer |
219 | | |
220 | | /* type safety */ |
221 | | #if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58 && (!defined(glib_typeof_2_68) || GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68) |
222 | 11.6M | #define g_steal_pointer(pp) ((glib_typeof (*pp)) (g_steal_pointer) (pp)) |
223 | | #else /* __GNUC__ */ |
224 | | /* This version does not depend on gcc extensions, but gcc does not warn |
225 | | * about incompatible-pointer-types: */ |
226 | | #define g_steal_pointer(pp) \ |
227 | | (0 ? (*(pp)) : (g_steal_pointer) (pp)) |
228 | | #endif /* __GNUC__ */ |
229 | | |
230 | | /* Optimise: avoid the call to the (slower) _n function if we can |
231 | | * determine at compile-time that no overflow happens. |
232 | | */ |
233 | | #if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__) |
234 | | # define _G_NEW(struct_type, n_structs, func) \ |
235 | 22.1M | (struct_type *) (G_GNUC_EXTENSION ({ \ |
236 | 22.1M | gsize __n = (gsize) (n_structs); \ |
237 | 22.1M | gsize __s = sizeof (struct_type); \ |
238 | 22.1M | gpointer __p; \ |
239 | 22.1M | if (__s == 1) \ |
240 | 22.1M | __p = g_##func (__n); \ |
241 | 22.1M | else if (__builtin_constant_p (__n) && \ |
242 | 393k | (__s == 0 || __n <= G_MAXSIZE / __s)) \ |
243 | 393k | __p = g_##func (__n * __s); \ |
244 | 393k | else \ |
245 | 393k | __p = g_##func##_n (__n, __s); \ |
246 | 22.1M | __p; \ |
247 | 22.1M | })) |
248 | | # define _G_RENEW(struct_type, mem, n_structs, func) \ |
249 | 94.4k | (struct_type *) (G_GNUC_EXTENSION ({ \ |
250 | 94.4k | gsize __n = (gsize) (n_structs); \ |
251 | 94.4k | gsize __s = sizeof (struct_type); \ |
252 | 94.4k | gpointer __p = (gpointer) (mem); \ |
253 | 94.4k | if (__s == 1) \ |
254 | 94.4k | __p = g_##func (__p, __n); \ |
255 | 94.4k | else if (__builtin_constant_p (__n) && \ |
256 | 94.4k | (__s == 0 || __n <= G_MAXSIZE / __s)) \ |
257 | 94.4k | __p = g_##func (__p, __n * __s); \ |
258 | 94.4k | else \ |
259 | 94.4k | __p = g_##func##_n (__p, __n, __s); \ |
260 | 94.4k | __p; \ |
261 | 94.4k | })) |
262 | | |
263 | | #else |
264 | | |
265 | | /* Unoptimised version: always call the _n() function. */ |
266 | | |
267 | | #define _G_NEW(struct_type, n_structs, func) \ |
268 | | ((struct_type *) g_##func##_n ((n_structs), sizeof (struct_type))) |
269 | | #define _G_RENEW(struct_type, mem, n_structs, func) \ |
270 | | ((struct_type *) g_##func##_n (mem, (n_structs), sizeof (struct_type))) |
271 | | |
272 | | #endif |
273 | | |
274 | | /** |
275 | | * g_new: |
276 | | * @struct_type: the type of the elements to allocate |
277 | | * @n_structs: the number of elements to allocate |
278 | | * |
279 | | * Allocates @n_structs elements of type @struct_type. |
280 | | * The returned pointer is cast to a pointer to the given type. |
281 | | * If @n_structs is 0 it returns %NULL. |
282 | | * Care is taken to avoid overflow when calculating the size of the allocated block. |
283 | | * |
284 | | * Since the returned pointer is already casted to the right type, |
285 | | * it is normally unnecessary to cast it explicitly, and doing |
286 | | * so might hide memory allocation errors. |
287 | | * |
288 | | * Returns: a pointer to the allocated memory, cast to a pointer to @struct_type |
289 | | */ |
290 | 21.7M | #define g_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc) |
291 | | /** |
292 | | * g_new0: |
293 | | * @struct_type: the type of the elements to allocate. |
294 | | * @n_structs: the number of elements to allocate. |
295 | | * |
296 | | * Allocates @n_structs elements of type @struct_type, initialized to 0's. |
297 | | * The returned pointer is cast to a pointer to the given type. |
298 | | * If @n_structs is 0 it returns %NULL. |
299 | | * Care is taken to avoid overflow when calculating the size of the allocated block. |
300 | | * |
301 | | * Since the returned pointer is already casted to the right type, |
302 | | * it is normally unnecessary to cast it explicitly, and doing |
303 | | * so might hide memory allocation errors. |
304 | | * |
305 | | * Returns: a pointer to the allocated memory, cast to a pointer to @struct_type. |
306 | | */ |
307 | 354k | #define g_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc0) |
308 | | /** |
309 | | * g_renew: |
310 | | * @struct_type: the type of the elements to allocate |
311 | | * @mem: the currently allocated memory |
312 | | * @n_structs: the number of elements to allocate |
313 | | * |
314 | | * Reallocates the memory pointed to by @mem, so that it now has space for |
315 | | * @n_structs elements of type @struct_type. It returns the new address of |
316 | | * the memory, which may have been moved. |
317 | | * Care is taken to avoid overflow when calculating the size of the allocated block. |
318 | | * |
319 | | * Returns: a pointer to the new allocated memory, cast to a pointer to @struct_type |
320 | | */ |
321 | 94.4k | #define g_renew(struct_type, mem, n_structs) _G_RENEW (struct_type, mem, n_structs, realloc) |
322 | | /** |
323 | | * g_try_new: |
324 | | * @struct_type: the type of the elements to allocate |
325 | | * @n_structs: the number of elements to allocate |
326 | | * |
327 | | * Attempts to allocate @n_structs elements of type @struct_type, and returns |
328 | | * %NULL on failure. Contrast with g_new(), which aborts the program on failure. |
329 | | * The returned pointer is cast to a pointer to the given type. |
330 | | * The function returns %NULL when @n_structs is 0 of if an overflow occurs. |
331 | | * |
332 | | * Since: 2.8 |
333 | | * Returns: a pointer to the allocated memory, cast to a pointer to @struct_type |
334 | | */ |
335 | | #define g_try_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc) |
336 | | /** |
337 | | * g_try_new0: |
338 | | * @struct_type: the type of the elements to allocate |
339 | | * @n_structs: the number of elements to allocate |
340 | | * |
341 | | * Attempts to allocate @n_structs elements of type @struct_type, initialized |
342 | | * to 0's, and returns %NULL on failure. Contrast with g_new0(), which aborts |
343 | | * the program on failure. |
344 | | * The returned pointer is cast to a pointer to the given type. |
345 | | * The function returns %NULL when @n_structs is 0 or if an overflow occurs. |
346 | | * |
347 | | * Since: 2.8 |
348 | | * Returns: a pointer to the allocated memory, cast to a pointer to @struct_type |
349 | | */ |
350 | | #define g_try_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc0) |
351 | | /** |
352 | | * g_try_renew: |
353 | | * @struct_type: the type of the elements to allocate |
354 | | * @mem: the currently allocated memory |
355 | | * @n_structs: the number of elements to allocate |
356 | | * |
357 | | * Attempts to reallocate the memory pointed to by @mem, so that it now has |
358 | | * space for @n_structs elements of type @struct_type, and returns %NULL on |
359 | | * failure. Contrast with g_renew(), which aborts the program on failure. |
360 | | * It returns the new address of the memory, which may have been moved. |
361 | | * The function returns %NULL if an overflow occurs. |
362 | | * |
363 | | * Since: 2.8 |
364 | | * Returns: a pointer to the new allocated memory, cast to a pointer to @struct_type |
365 | | */ |
366 | | #define g_try_renew(struct_type, mem, n_structs) _G_RENEW (struct_type, mem, n_structs, try_realloc) |
367 | | |
368 | | |
369 | | /* Memory allocation virtualization for debugging purposes |
370 | | * g_mem_set_vtable() has to be the very first GLib function called |
371 | | * if being used |
372 | | */ |
373 | | struct _GMemVTable { |
374 | | gpointer (*malloc) (gsize n_bytes); |
375 | | gpointer (*realloc) (gpointer mem, |
376 | | gsize n_bytes); |
377 | | void (*free) (gpointer mem); |
378 | | /* optional; set to NULL if not used ! */ |
379 | | gpointer (*calloc) (gsize n_blocks, |
380 | | gsize n_block_bytes); |
381 | | gpointer (*try_malloc) (gsize n_bytes); |
382 | | gpointer (*try_realloc) (gpointer mem, |
383 | | gsize n_bytes); |
384 | | }; |
385 | | GLIB_DEPRECATED_IN_2_46 |
386 | | void g_mem_set_vtable (GMemVTable *vtable); |
387 | | GLIB_DEPRECATED_IN_2_46 |
388 | | gboolean g_mem_is_system_malloc (void); |
389 | | |
390 | | GLIB_VAR gboolean g_mem_gc_friendly; |
391 | | |
392 | | /* Memory profiler and checker, has to be enabled via g_mem_set_vtable() |
393 | | */ |
394 | | GLIB_VAR GMemVTable *glib_mem_profiler_table; |
395 | | GLIB_DEPRECATED_IN_2_46 |
396 | | void g_mem_profile (void); |
397 | | |
398 | | G_END_DECLS |
399 | | |
400 | | #endif /* __G_MEM_H__ */ |