v0.2.2 9100209

gmem.go RawHistoryFolder

1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5	"structs"
6	"unsafe"
7
8	"github.com/ebitengine/purego"
9
10	"github.com/bnema/puregotk/pkg/core"
11)
12
13// A set of functions used to perform memory allocation. The same #GMemVTable must
14// be used for all allocations in the same program; a call to g_mem_set_vtable(),
15// if it exists, should be prior to any use of GLib.
16//
17// This functions related to this has been deprecated in 2.46, and no longer work.
18type MemVTable struct {
19	_ structs.HostLayout
20
21	xMalloc uintptr
22
23	xRealloc uintptr
24
25	xFree uintptr
26
27	xCalloc uintptr
28
29	xTryMalloc uintptr
30
31	xTryRealloc uintptr
32}
33
34func (x *MemVTable) GoPointer() uintptr {
35	return uintptr(unsafe.Pointer(x))
36}
37
38// OverrideMalloc sets the "malloc" callback function.
39// function to use for allocating memory.
40func (x *MemVTable) OverrideMalloc(cb func(uint) uintptr) {
41	if cb == nil {
42		x.xMalloc = 0
43	} else {
44		x.xMalloc = purego.NewCallback(func(NBytesVarp uint) uintptr {
45			return cb(NBytesVarp)
46		})
47	}
48}
49
50// GetMalloc gets the "malloc" callback function.
51// function to use for allocating memory.
52func (x *MemVTable) GetMalloc() func(uint) uintptr {
53	if x.xMalloc == 0 {
54		return nil
55	}
56	var rawCallback func(NBytesVarp uint) uintptr
57	purego.RegisterFunc(&rawCallback, x.xMalloc)
58	return func(NBytesVar uint) uintptr {
59		return rawCallback(NBytesVar)
60	}
61}
62
63// OverrideRealloc sets the "realloc" callback function.
64// function to use for reallocating memory.
65func (x *MemVTable) OverrideRealloc(cb func(uintptr, uint) uintptr) {
66	if cb == nil {
67		x.xRealloc = 0
68	} else {
69		x.xRealloc = purego.NewCallback(func(MemVarp uintptr, NBytesVarp uint) uintptr {
70			return cb(MemVarp, NBytesVarp)
71		})
72	}
73}
74
75// GetRealloc gets the "realloc" callback function.
76// function to use for reallocating memory.
77func (x *MemVTable) GetRealloc() func(uintptr, uint) uintptr {
78	if x.xRealloc == 0 {
79		return nil
80	}
81	var rawCallback func(MemVarp uintptr, NBytesVarp uint) uintptr
82	purego.RegisterFunc(&rawCallback, x.xRealloc)
83	return func(MemVar uintptr, NBytesVar uint) uintptr {
84		return rawCallback(MemVar, NBytesVar)
85	}
86}
87
88// OverrideFree sets the "free" callback function.
89// function to use to free memory.
90func (x *MemVTable) OverrideFree(cb func(uintptr)) {
91	if cb == nil {
92		x.xFree = 0
93	} else {
94		x.xFree = purego.NewCallback(func(MemVarp uintptr) {
95			cb(MemVarp)
96		})
97	}
98}
99
100// GetFree gets the "free" callback function.
101// function to use to free memory.
102func (x *MemVTable) GetFree() func(uintptr) {
103	if x.xFree == 0 {
104		return nil
105	}
106	var rawCallback func(MemVarp uintptr)
107	purego.RegisterFunc(&rawCallback, x.xFree)
108	return func(MemVar uintptr) {
109		rawCallback(MemVar)
110	}
111}
112
113// OverrideCalloc sets the "calloc" callback function.
114// function to use for allocating zero-filled memory.
115func (x *MemVTable) OverrideCalloc(cb func(uint, uint) uintptr) {
116	if cb == nil {
117		x.xCalloc = 0
118	} else {
119		x.xCalloc = purego.NewCallback(func(NBlocksVarp uint, NBlockBytesVarp uint) uintptr {
120			return cb(NBlocksVarp, NBlockBytesVarp)
121		})
122	}
123}
124
125// GetCalloc gets the "calloc" callback function.
126// function to use for allocating zero-filled memory.
127func (x *MemVTable) GetCalloc() func(uint, uint) uintptr {
128	if x.xCalloc == 0 {
129		return nil
130	}
131	var rawCallback func(NBlocksVarp uint, NBlockBytesVarp uint) uintptr
132	purego.RegisterFunc(&rawCallback, x.xCalloc)
133	return func(NBlocksVar uint, NBlockBytesVar uint) uintptr {
134		return rawCallback(NBlocksVar, NBlockBytesVar)
135	}
136}
137
138// OverrideTryMalloc sets the "try_malloc" callback function.
139// function to use for allocating memory without a default error handler.
140func (x *MemVTable) OverrideTryMalloc(cb func(uint) uintptr) {
141	if cb == nil {
142		x.xTryMalloc = 0
143	} else {
144		x.xTryMalloc = purego.NewCallback(func(NBytesVarp uint) uintptr {
145			return cb(NBytesVarp)
146		})
147	}
148}
149
150// GetTryMalloc gets the "try_malloc" callback function.
151// function to use for allocating memory without a default error handler.
152func (x *MemVTable) GetTryMalloc() func(uint) uintptr {
153	if x.xTryMalloc == 0 {
154		return nil
155	}
156	var rawCallback func(NBytesVarp uint) uintptr
157	purego.RegisterFunc(&rawCallback, x.xTryMalloc)
158	return func(NBytesVar uint) uintptr {
159		return rawCallback(NBytesVar)
160	}
161}
162
163// OverrideTryRealloc sets the "try_realloc" callback function.
164// function to use for reallocating memory without a default error handler.
165func (x *MemVTable) OverrideTryRealloc(cb func(uintptr, uint) uintptr) {
166	if cb == nil {
167		x.xTryRealloc = 0
168	} else {
169		x.xTryRealloc = purego.NewCallback(func(MemVarp uintptr, NBytesVarp uint) uintptr {
170			return cb(MemVarp, NBytesVarp)
171		})
172	}
173}
174
175// GetTryRealloc gets the "try_realloc" callback function.
176// function to use for reallocating memory without a default error handler.
177func (x *MemVTable) GetTryRealloc() func(uintptr, uint) uintptr {
178	if x.xTryRealloc == 0 {
179		return nil
180	}
181	var rawCallback func(MemVarp uintptr, NBytesVarp uint) uintptr
182	purego.RegisterFunc(&rawCallback, x.xTryRealloc)
183	return func(MemVar uintptr, NBytesVar uint) uintptr {
184		return rawCallback(MemVar, NBytesVar)
185	}
186}
187
188var xAlignedAlloc func(uint, uint, uint) uintptr
189
190// This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes)
191// bytes, but care is taken to align the allocated memory to with the given
192// alignment value. Additionally, it will detect possible overflow during
193// multiplication.
194//
195// If the allocation fails (because the system is out of memory),
196// the program is terminated.
197//
198// Aligned memory allocations returned by this function can only be
199// freed using g_aligned_free_sized() or g_aligned_free().
200func AlignedAlloc(NBlocksVar uint, NBlockBytesVar uint, AlignmentVar uint) uintptr {
201
202	cret := xAlignedAlloc(NBlocksVar, NBlockBytesVar, AlignmentVar)
203
204	return cret
205}
206
207var xAlignedAlloc0 func(uint, uint, uint) uintptr
208
209// This function is similar to g_aligned_alloc(), but it will
210// also clear the allocated memory before returning it.
211func AlignedAlloc0(NBlocksVar uint, NBlockBytesVar uint, AlignmentVar uint) uintptr {
212
213	cret := xAlignedAlloc0(NBlocksVar, NBlockBytesVar, AlignmentVar)
214
215	return cret
216}
217
218var xAlignedFree func(uintptr)
219
220// Frees the memory allocated by g_aligned_alloc().
221func AlignedFree(MemVar uintptr) {
222
223	xAlignedFree(MemVar)
224
225}
226
227var xAlignedFreeSized func(uintptr, uint, uint)
228
229// Frees the memory pointed to by @mem, assuming it is has the given @size and
230// @alignment.
231//
232// If @mem is %NULL this is a no-op (and @size is ignored).
233//
234// It is an error if @size doesn’t match the size, or @alignment doesn’t match
235// the alignment, passed when @mem was allocated. @size and @alignment are
236// passed to this function to allow optimizations in the allocator. If you
237// don’t know either of them, use g_aligned_free() instead.
238func AlignedFreeSized(MemVar uintptr, AlignmentVar uint, SizeVar uint) {
239
240	xAlignedFreeSized(MemVar, AlignmentVar, SizeVar)
241
242}
243
244var xClearPointer func(*uintptr, uintptr)
245
246// Clears a reference to a variable.
247//
248// @pp must not be %NULL.
249//
250// If the reference is %NULL then this function does nothing.
251// Otherwise, the variable is destroyed using @destroy and the
252// pointer is set to %NULL.
253//
254// A macro is also included that allows this function to be used without
255// pointer casts. This will mask any warnings about incompatible function types
256// or calling conventions, so you must ensure that your @destroy function is
257// compatible with being called as [callback@GLib.DestroyNotify] using the
258// standard calling convention for the platform that GLib was compiled for;
259// otherwise the program will experience undefined behaviour.
260//
261// Examples of this kind of undefined behaviour include using many Windows Win32
262// APIs, as well as many if not all OpenGL and Vulkan calls on 32-bit Windows,
263// which typically use the `__stdcall` calling convention rather than the
264// `__cdecl` calling convention.
265//
266// The affected functions can be used by wrapping them in a
267// [callback@GLib.DestroyNotify] that is declared with the standard calling
268// convention:
269//
270// ```c
271// // Wrapper needed to avoid mismatched calling conventions on Windows
272// static void
273// destroy_sync (void *sync)
274//
275//	{
276//	  glDeleteSync (sync);
277//	}
278//
279// // …
280//
281// g_clear_pointer (&sync, destroy_sync);
282// ```
283func ClearPointer(PpVar *uintptr, DestroyVar *DestroyNotify) {
284
285	var DestroyVarRef uintptr
286	if DestroyVar != nil {
287		DestroyVarPtr := uintptr(unsafe.Pointer(DestroyVar))
288		if cbRefPtr, ok := GetCallback(DestroyVarPtr); ok {
289			DestroyVarRef = cbRefPtr
290		} else {
291			fcb := func(arg0 uintptr) {
292				cbFn := *DestroyVar
293				cbFn(arg0)
294			}
295			DestroyVarRef = purego.NewCallback(fcb)
296			SaveCallbackWithClosure(DestroyVarPtr, DestroyVarRef, DestroyVar)
297		}
298	}
299
300	xClearPointer(PpVar, DestroyVarRef)
301
302}
303
304var xFree func(uintptr)
305
306// Frees the memory pointed to by @mem.
307//
308// If you know the allocated size of @mem, calling g_free_sized() may be faster,
309// depending on the libc implementation in use.
310//
311// Starting from GLib 2.78, this may happen automatically in case a GCC
312// compatible compiler is used with some optimization level and the allocated
313// size is known at compile time (see [documentation of
314// `__builtin_object_size()`](https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html)
315// to understand its caveats).
316//
317// If @mem is %NULL it simply returns, so there is no need to check @mem
318// against %NULL before calling this function.
319func Free(MemVar uintptr) {
320
321	xFree(MemVar)
322
323}
324
325var xFreeSized func(uintptr, uint)
326
327// Frees the memory pointed to by @mem, assuming it is has the given @size.
328//
329// If @mem is %NULL this is a no-op (and @size is ignored).
330//
331// It is an error if @size doesn’t match the size passed when @mem was
332// allocated. @size is passed to this function to allow optimizations in the
333// allocator. If you don’t know the allocation size, use g_free() instead.
334//
335// In case a GCC compatible compiler is used, this function may be used
336// automatically via g_free() if the allocated size is known at compile time,
337// since GLib 2.78.
338func FreeSized(MemVar uintptr, SizeVar uint) {
339
340	xFreeSized(MemVar, SizeVar)
341
342}
343
344var xMalloc func(uint) uintptr
345
346// Allocates @n_bytes bytes of memory.
347// If @n_bytes is 0 it returns %NULL.
348//
349// If the allocation fails (because the system is out of memory),
350// the program is terminated.
351func Malloc(NBytesVar uint) uintptr {
352
353	cret := xMalloc(NBytesVar)
354
355	return cret
356}
357
358var xMalloc0 func(uint) uintptr
359
360// Allocates @n_bytes bytes of memory, initialized to 0's.
361// If @n_bytes is 0 it returns %NULL.
362//
363// If the allocation fails (because the system is out of memory),
364// the program is terminated.
365func Malloc0(NBytesVar uint) uintptr {
366
367	cret := xMalloc0(NBytesVar)
368
369	return cret
370}
371
372var xMalloc0N func(uint, uint) uintptr
373
374// This function is similar to g_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
375// but care is taken to detect possible overflow during multiplication.
376//
377// If the allocation fails (because the system is out of memory),
378// the program is terminated.
379func Malloc0N(NBlocksVar uint, NBlockBytesVar uint) uintptr {
380
381	cret := xMalloc0N(NBlocksVar, NBlockBytesVar)
382
383	return cret
384}
385
386var xMallocN func(uint, uint) uintptr
387
388// This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
389// but care is taken to detect possible overflow during multiplication.
390//
391// If the allocation fails (because the system is out of memory),
392// the program is terminated.
393func MallocN(NBlocksVar uint, NBlockBytesVar uint) uintptr {
394
395	cret := xMallocN(NBlocksVar, NBlockBytesVar)
396
397	return cret
398}
399
400var xMemIsSystemMalloc func() bool
401
402// Checks whether the allocator used by g_malloc() is the system's
403// malloc implementation. If it returns %TRUE memory allocated with
404// malloc() can be used interchangeably with memory allocated using g_malloc().
405// This function is useful for avoiding an extra copy of allocated memory returned
406// by a non-GLib-based API.
407func MemIsSystemMalloc() bool {
408
409	cret := xMemIsSystemMalloc()
410
411	return cret
412}
413
414var xMemProfile func()
415
416// GLib used to support some tools for memory profiling, but this
417// no longer works. There are many other useful tools for memory
418// profiling these days which can be used instead.
419func MemProfile() {
420
421	xMemProfile()
422
423}
424
425var xMemSetVtable func(*MemVTable)
426
427// This function used to let you override the memory allocation function.
428// However, its use was incompatible with the use of global constructors
429// in GLib and GIO, because those use the GLib allocators before main is
430// reached. Therefore this function is now deprecated and is just a stub.
431func MemSetVtable(VtableVar *MemVTable) {
432
433	xMemSetVtable(VtableVar)
434
435}
436
437var xRealloc func(uintptr, uint) uintptr
438
439// Reallocates the memory pointed to by @mem, so that it now has space for
440// @n_bytes bytes of memory. It returns the new address of the memory, which may
441// have been moved. @mem may be %NULL, in which case it's considered to
442// have zero-length. @n_bytes may be 0, in which case %NULL will be returned
443// and @mem will be freed unless it is %NULL.
444//
445// If the allocation fails (because the system is out of memory),
446// the program is terminated.
447func Realloc(MemVar uintptr, NBytesVar uint) uintptr {
448
449	cret := xRealloc(MemVar, NBytesVar)
450
451	return cret
452}
453
454var xReallocN func(uintptr, uint, uint) uintptr
455
456// This function is similar to g_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
457// but care is taken to detect possible overflow during multiplication.
458//
459// If the allocation fails (because the system is out of memory),
460// the program is terminated.
461func ReallocN(MemVar uintptr, NBlocksVar uint, NBlockBytesVar uint) uintptr {
462
463	cret := xReallocN(MemVar, NBlocksVar, NBlockBytesVar)
464
465	return cret
466}
467
468var xTryMalloc func(uint) uintptr
469
470// Attempts to allocate @n_bytes, and returns %NULL on failure.
471// Contrast with g_malloc(), which aborts the program on failure.
472func TryMalloc(NBytesVar uint) uintptr {
473
474	cret := xTryMalloc(NBytesVar)
475
476	return cret
477}
478
479var xTryMalloc0 func(uint) uintptr
480
481// Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on
482// failure. Contrast with g_malloc0(), which aborts the program on failure.
483func TryMalloc0(NBytesVar uint) uintptr {
484
485	cret := xTryMalloc0(NBytesVar)
486
487	return cret
488}
489
490var xTryMalloc0N func(uint, uint) uintptr
491
492// This function is similar to g_try_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
493// but care is taken to detect possible overflow during multiplication.
494func TryMalloc0N(NBlocksVar uint, NBlockBytesVar uint) uintptr {
495
496	cret := xTryMalloc0N(NBlocksVar, NBlockBytesVar)
497
498	return cret
499}
500
501var xTryMallocN func(uint, uint) uintptr
502
503// This function is similar to g_try_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
504// but care is taken to detect possible overflow during multiplication.
505func TryMallocN(NBlocksVar uint, NBlockBytesVar uint) uintptr {
506
507	cret := xTryMallocN(NBlocksVar, NBlockBytesVar)
508
509	return cret
510}
511
512var xTryRealloc func(uintptr, uint) uintptr
513
514// Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL
515// on failure. Contrast with g_realloc(), which aborts the program
516// on failure.
517//
518// If @mem is %NULL, behaves the same as g_try_malloc().
519func TryRealloc(MemVar uintptr, NBytesVar uint) uintptr {
520
521	cret := xTryRealloc(MemVar, NBytesVar)
522
523	return cret
524}
525
526var xTryReallocN func(uintptr, uint, uint) uintptr
527
528// This function is similar to g_try_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
529// but care is taken to detect possible overflow during multiplication.
530func TryReallocN(MemVar uintptr, NBlocksVar uint, NBlockBytesVar uint) uintptr {
531
532	cret := xTryReallocN(MemVar, NBlocksVar, NBlockBytesVar)
533
534	return cret
535}
536
537func init() {
538	core.SetPackageName("GLIB", "glib-2.0")
539	core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
540	var libs []uintptr
541	for _, libPath := range core.GetPaths("GLIB") {
542		lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
543		if err != nil {
544			panic(err)
545		}
546		libs = append(libs, lib)
547	}
548
549	core.PuregoSafeRegister(&xAlignedAlloc, libs, "g_aligned_alloc")
550	core.PuregoSafeRegister(&xAlignedAlloc0, libs, "g_aligned_alloc0")
551	core.PuregoSafeRegister(&xAlignedFree, libs, "g_aligned_free")
552	core.PuregoSafeRegister(&xAlignedFreeSized, libs, "g_aligned_free_sized")
553	core.PuregoSafeRegister(&xClearPointer, libs, "g_clear_pointer")
554	core.PuregoSafeRegister(&xFree, libs, "g_free")
555	core.PuregoSafeRegister(&xFreeSized, libs, "g_free_sized")
556	core.PuregoSafeRegister(&xMalloc, libs, "g_malloc")
557	core.PuregoSafeRegister(&xMalloc0, libs, "g_malloc0")
558	core.PuregoSafeRegister(&xMalloc0N, libs, "g_malloc0_n")
559	core.PuregoSafeRegister(&xMallocN, libs, "g_malloc_n")
560	core.PuregoSafeRegister(&xMemIsSystemMalloc, libs, "g_mem_is_system_malloc")
561	core.PuregoSafeRegister(&xMemProfile, libs, "g_mem_profile")
562	core.PuregoSafeRegister(&xMemSetVtable, libs, "g_mem_set_vtable")
563	core.PuregoSafeRegister(&xRealloc, libs, "g_realloc")
564	core.PuregoSafeRegister(&xReallocN, libs, "g_realloc_n")
565	core.PuregoSafeRegister(&xTryMalloc, libs, "g_try_malloc")
566	core.PuregoSafeRegister(&xTryMalloc0, libs, "g_try_malloc0")
567	core.PuregoSafeRegister(&xTryMalloc0N, libs, "g_try_malloc0_n")
568	core.PuregoSafeRegister(&xTryMallocN, libs, "g_try_malloc_n")
569	core.PuregoSafeRegister(&xTryRealloc, libs, "g_try_realloc")
570	core.PuregoSafeRegister(&xTryReallocN, libs, "g_try_realloc_n")
571
572}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close