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 "github.com/bnema/puregotk/v4/gobject/types"
12)
13
14// Contains the public fields of a `GArray`.
15type Array struct {
16 _ structs.HostLayout
17
18 Data uintptr
19
20 Len uint
21}
22
23var xArrayGLibType func() types.GType
24
25func ArrayGLibType() types.GType {
26 return xArrayGLibType()
27}
28
29func (x *Array) GoPointer() uintptr {
30 return uintptr(unsafe.Pointer(x))
31}
32
33// Contains the public fields of a `GByteArray`.
34type ByteArray struct {
35 _ structs.HostLayout
36
37 Data byte
38
39 Len uint
40}
41
42var xByteArrayGLibType func() types.GType
43
44func ByteArrayGLibType() types.GType {
45 return xByteArrayGLibType()
46}
47
48func (x *ByteArray) GoPointer() uintptr {
49 return uintptr(unsafe.Pointer(x))
50}
51
52// A simple reference counted data type representing an immutable sequence of
53// zero or more bytes from an unspecified origin.
54//
55// The purpose of a `GBytes` is to keep the memory region that it holds
56// alive for as long as anyone holds a reference to the bytes. When
57// the last reference count is dropped, the memory is released. Multiple
58// unrelated callers can use byte data in the `GBytes` without coordinating
59// their activities, resting assured that the byte data will not change or
60// move while they hold a reference.
61//
62// A `GBytes` can come from many different origins that may have
63// different procedures for freeing the memory region. Examples are
64// memory from [func@GLib.malloc], from memory slices, from a
65// [struct@GLib.MappedFile] or memory from other allocators.
66//
67// `GBytes` work well as keys in [struct@GLib.HashTable]. Use
68// [method@GLib.Bytes.equal] and [method@GLib.Bytes.hash] as parameters to
69// [func@GLib.HashTable.new] or [func@GLib.HashTable.new_full].
70// `GBytes` can also be used as keys in a [struct@GLib.Tree] by passing the
71// [method@GLib.Bytes.compare] function to [ctor@GLib.Tree.new].
72//
73// The data pointed to by this bytes must not be modified. For a mutable
74// array of bytes see [struct@GLib.ByteArray]. Use
75// [method@GLib.Bytes.unref_to_array] to create a mutable array for a `GBytes`
76// sequence. To create an immutable `GBytes` from a mutable
77// [struct@GLib.ByteArray], use the [func@GLib.ByteArray.free_to_bytes]
78// function.
79type Bytes struct {
80 _ structs.HostLayout
81}
82
83var xBytesGLibType func() types.GType
84
85func BytesGLibType() types.GType {
86 return xBytesGLibType()
87}
88
89func (x *Bytes) GoPointer() uintptr {
90 return uintptr(unsafe.Pointer(x))
91}
92
93var xNewBytes func([]byte, uint) *Bytes
94
95// Creates a new [struct@GLib.Bytes] from @data.
96//
97// @data is copied. If @size is 0, @data may be `NULL`.
98//
99// As an optimization, [ctor@GLib.Bytes.new] may avoid an extra allocation by
100// copying the data within the resulting bytes structure if sufficiently small
101// (since GLib 2.84).
102func NewBytes(DataVar []byte, SizeVar uint) *Bytes {
103
104 cret := xNewBytes(DataVar, SizeVar)
105 return cret
106}
107
108var xNewBytesStatic func([]byte, uint) *Bytes
109
110// Creates a new [struct@GLib.Bytes] from static data.
111//
112// @data must be static (ie: never modified or freed). It may be `NULL` if @size
113// is 0.
114func NewBytesStatic(DataVar []byte, SizeVar uint) *Bytes {
115
116 cret := xNewBytesStatic(DataVar, SizeVar)
117 return cret
118}
119
120var xNewBytesTake func(uintptr, uint) *Bytes
121
122// Creates a new [struct@GLib.Bytes] from @data.
123//
124// After this call, @data belongs to the `GBytes` and may no longer be
125// modified by the caller. The memory of @data has to be dynamically
126// allocated and will eventually be freed with [func@GLib.free].
127//
128// For creating `GBytes` with memory from other allocators, see
129// [ctor@GLib.Bytes.new_with_free_func].
130//
131// @data may be `NULL` if @size is 0.
132func NewBytesTake(DataVar uintptr, SizeVar uint) *Bytes {
133
134 cret := xNewBytesTake(DataVar, SizeVar)
135 return cret
136}
137
138var xNewBytesWithFreeFunc func([]byte, uint, uintptr, uintptr) *Bytes
139
140// Creates a [struct@GLib.Bytes] from @data.
141//
142// When the last reference is dropped, @free_func will be called with the
143// @user_data argument.
144//
145// @data must not be modified after this call is made until @free_func has
146// been called to indicate that the bytes is no longer in use.
147//
148// @data may be `NULL` if @size is 0.
149func NewBytesWithFreeFunc(DataVar []byte, SizeVar uint, FreeFuncVar *DestroyNotify, UserDataVar uintptr) *Bytes {
150
151 var FreeFuncVarRef uintptr
152 if FreeFuncVar != nil {
153 FreeFuncVarPtr := uintptr(unsafe.Pointer(FreeFuncVar))
154 if cbRefPtr, ok := GetCallback(FreeFuncVarPtr); ok {
155 FreeFuncVarRef = cbRefPtr
156 } else {
157 fcb := func(arg0 uintptr) {
158 cbFn := *FreeFuncVar
159 cbFn(arg0)
160 }
161 FreeFuncVarRef = purego.NewCallback(fcb)
162 SaveCallbackWithClosure(FreeFuncVarPtr, FreeFuncVarRef, FreeFuncVar)
163 }
164 }
165
166 cret := xNewBytesWithFreeFunc(DataVar, SizeVar, FreeFuncVarRef, UserDataVar)
167 return cret
168}
169
170var xBytesCompare func(uintptr, uintptr) int
171
172// Compares the two [struct@GLib.Bytes] values.
173//
174// This function can be used to sort `GBytes` instances in lexicographical
175// order.
176//
177// If @bytes1 and @bytes2 have different length but the shorter one is a
178// prefix of the longer one then the shorter one is considered to be less than
179// the longer one. Otherwise the first byte where both differ is used for
180// comparison. If @bytes1 has a smaller value at that position it is
181// considered less, otherwise greater than @bytes2.
182func (x *Bytes) Compare(Bytes2Var uintptr) int {
183
184 cret := xBytesCompare(x.GoPointer(), Bytes2Var)
185 return cret
186}
187
188var xBytesEqual func(uintptr, uintptr) bool
189
190// Compares the two [struct@GLib.Bytes] values being pointed to and returns
191// `TRUE` if they are equal.
192//
193// This function can be passed to [func@GLib.HashTable.new] as the
194// @key_equal_func parameter, when using non-`NULL` `GBytes` pointers as keys in
195// a [struct@GLib.HashTable].
196func (x *Bytes) Equal(Bytes2Var uintptr) bool {
197
198 cret := xBytesEqual(x.GoPointer(), Bytes2Var)
199 return cret
200}
201
202var xBytesGetData func(uintptr, *uint) uintptr
203
204// Get the byte data in the [struct@GLib.Bytes].
205//
206// This data should not be modified.
207//
208// This function will always return the same pointer for a given `GBytes`.
209//
210// `NULL` may be returned if @size is 0. This is not guaranteed, as the `GBytes`
211// may represent an empty string with @data non-`NULL` and @size as 0. `NULL`
212// will not be returned if @size is non-zero.
213func (x *Bytes) GetData(SizeVar *uint) uintptr {
214
215 cret := xBytesGetData(x.GoPointer(), SizeVar)
216 return cret
217}
218
219var xBytesGetRegion func(uintptr, uint, uint, uint) uintptr
220
221// Gets a pointer to a region in @bytes.
222//
223// The region starts at @offset many bytes from the start of the data
224// and contains @n_elements many elements of @element_size size.
225//
226// @n_elements may be zero, but @element_size must always be non-zero.
227// Ideally, @element_size is a static constant (eg: `sizeof` a struct).
228//
229// This function does careful bounds checking (including checking for
230// arithmetic overflows) and returns a non-`NULL` pointer if the
231// specified region lies entirely within the @bytes. If the region is
232// in some way out of range, or if an overflow has occurred, then `NULL`
233// is returned.
234//
235// Note: it is possible to have a valid zero-size region. In this case,
236// the returned pointer will be equal to the base pointer of the data of
237// @bytes, plus @offset. This will be non-`NULL` except for the case
238// where @bytes itself was a zero-sized region. Since it is unlikely
239// that you will be using this function to check for a zero-sized region
240// in a zero-sized @bytes, `NULL` effectively always means ‘error’.
241func (x *Bytes) GetRegion(ElementSizeVar uint, OffsetVar uint, NElementsVar uint) uintptr {
242
243 cret := xBytesGetRegion(x.GoPointer(), ElementSizeVar, OffsetVar, NElementsVar)
244 return cret
245}
246
247var xBytesGetSize func(uintptr) uint
248
249// Get the size of the byte data in the [struct@GLib.Bytes].
250//
251// This function will always return the same value for a given `GBytes`.
252func (x *Bytes) GetSize() uint {
253
254 cret := xBytesGetSize(x.GoPointer())
255 return cret
256}
257
258var xBytesHash func(uintptr) uint
259
260// Creates an integer hash code for the byte data in the [struct@GLib.Bytes].
261//
262// This function can be passed to [func@GLib.HashTable.new] as the
263// @key_hash_func parameter, when using non-`NULL` `GBytes` pointers as keys in
264// a [struct@GLib.HashTable].
265func (x *Bytes) Hash() uint {
266
267 cret := xBytesHash(x.GoPointer())
268 return cret
269}
270
271var xBytesNewFromBytes func(uintptr, uint, uint) *Bytes
272
273// Creates a [struct@GLib.Bytes] which is a subsection of another `GBytes`.
274//
275// The @offset + @length may not be longer than the size of @bytes.
276//
277// A reference to @bytes will be held by the newly created `GBytes` until
278// the byte data is no longer needed.
279//
280// Since 2.56, if @offset is 0 and @length matches the size of @bytes, then
281// @bytes will be returned with the reference count incremented by 1. If @bytes
282// is a slice of another `GBytes`, then the resulting `GBytes` will reference
283// the same `GBytes` instead of @bytes. This allows consumers to simplify the
284// usage of `GBytes` when asynchronously writing to streams.
285func (x *Bytes) NewFromBytes(OffsetVar uint, LengthVar uint) *Bytes {
286
287 cret := xBytesNewFromBytes(x.GoPointer(), OffsetVar, LengthVar)
288 return cret
289}
290
291var xBytesRef func(uintptr) *Bytes
292
293// Increase the reference count on @bytes.
294func (x *Bytes) Ref() *Bytes {
295
296 cret := xBytesRef(x.GoPointer())
297 return cret
298}
299
300var xBytesUnref func(uintptr)
301
302// Releases a reference on @bytes.
303//
304// This may result in the bytes being freed. If @bytes is `NULL`, it will
305// return immediately.
306func (x *Bytes) Unref() {
307
308 xBytesUnref(x.GoPointer())
309
310}
311
312var xBytesUnrefToArray func(uintptr) uintptr
313
314// Unreferences the bytes, and returns a new mutable [struct@GLib.ByteArray]
315// containing the same byte data.
316//
317// As an optimization, the byte data is transferred to the array without copying
318// if this was the last reference to @bytes and @bytes was created with
319// [ctor@GLib.Bytes.new], [ctor@GLib.Bytes.new_take] or
320// [func@GLib.ByteArray.free_to_bytes] and the buffer was larger than the size
321// [struct@GLib.Bytes] may internalize within its allocation. In all other cases
322// the data is copied.
323//
324// Do not use it if @bytes contains more than %G_MAXUINT
325// bytes. [struct@GLib.ByteArray] stores the length of its data in `guint`,
326// which may be shorter than `gsize`, that @bytes is using.
327func (x *Bytes) UnrefToArray() uintptr {
328
329 cret := xBytesUnrefToArray(x.GoPointer())
330 return cret
331}
332
333var xBytesUnrefToData func(uintptr, *uint) uintptr
334
335// Unreferences the bytes, and returns a pointer the same byte data
336// contents.
337//
338// As an optimization, the byte data is returned without copying if this was
339// the last reference to @bytes and @bytes was created with
340// [ctor@GLib.Bytes.new], [ctor@GLib.Bytes.new_take] or
341// [func@GLib.ByteArray.free_to_bytes] and the buffer was larger than the size
342// [struct@GLib.Bytes] may internalize within its allocation. In all other cases
343// the data is copied.
344func (x *Bytes) UnrefToData(SizeVar *uint) uintptr {
345
346 cret := xBytesUnrefToData(x.GoPointer(), SizeVar)
347 return cret
348}
349
350// Contains the public fields of a `GPtrArray`.
351type PtrArray struct {
352 _ structs.HostLayout
353
354 Pdata uintptr
355
356 Len uint
357}
358
359var xPtrArrayGLibType func() types.GType
360
361func PtrArrayGLibType() types.GType {
362 return xPtrArrayGLibType()
363}
364
365func (x *PtrArray) GoPointer() uintptr {
366 return uintptr(unsafe.Pointer(x))
367}
368
369var xArrayNewTake func(uintptr, uint, bool, uint) uintptr
370
371// Creates a new `GArray` with @data as array data, @len as length and a
372// reference count of 1.
373//
374// This avoids having to copy the data manually, when it can just be
375// inherited.
376// After this call, @data belongs to the `GArray` and may no longer be
377// modified by the caller. The memory of @data has to be dynamically
378// allocated and will eventually be freed with [func@GLib.free].
379//
380// In case the elements need to be cleared when the array is freed, use
381// [func@GLib.Array.set_clear_func] to set a [callback@GLib.DestroyNotify]
382// function to perform such task.
383//
384// Do not use it if @len or @element_size are greater than
385//
386// [`G_MAXUINT`](types.html#guint). `GArray` stores the length of its data in
387// `guint`, which may be shorter than `gsize`.
388func ArrayNewTake(DataVar uintptr, LenVar uint, ClearVar bool, ElementSizeVar uint) uintptr {
389
390 cret := xArrayNewTake(DataVar, LenVar, ClearVar, ElementSizeVar)
391
392 return cret
393}
394
395var xArrayNewTakeZeroTerminated func(uintptr, bool, uint) uintptr
396
397// Creates a new `GArray` with @data as array data, computing the length of it
398// and setting the reference count to 1.
399//
400// This avoids having to copy the data manually, when it can just be
401// inherited.
402// After this call, @data belongs to the `GArray` and may no longer be
403// modified by the caller. The memory of @data has to be dynamically
404// allocated and will eventually be freed with [func@GLib.free].
405//
406// The length is calculated by iterating through @data until the first `NULL`
407// element is found.
408//
409// In case the elements need to be cleared when the array is freed, use
410// [func@GLib.Array.set_clear_func] to set a [callback@GLib.DestroyNotify]
411// function to perform such task.
412//
413// Do not use it if @data length or @element_size are greater than
414// [`G_MAXUINT`](types.html#guint). `GArray` stores the length of its data in
415// `guint`, which may be shorter than `gsize`.
416func ArrayNewTakeZeroTerminated(DataVar uintptr, ClearVar bool, ElementSizeVar uint) uintptr {
417
418 cret := xArrayNewTakeZeroTerminated(DataVar, ClearVar, ElementSizeVar)
419
420 return cret
421}
422
423var xByteArrayAppend func([]byte, []byte, uint) uintptr
424
425// Adds the given bytes to the end of the `GByteArray`.
426// The array will grow in size automatically if necessary.
427func ByteArrayAppend(ArrayVar []byte, DataVar []byte, LenVar uint) uintptr {
428
429 cret := xByteArrayAppend(ArrayVar, DataVar, LenVar)
430
431 return cret
432}
433
434var xByteArrayFree func([]byte, bool) uintptr
435
436// Frees the memory allocated by the `GByteArray`. If @free_segment is
437// true it frees the actual byte data. If the reference count of
438// @array is greater than one, the `GByteArray` wrapper is preserved but
439// the size of @array will be set to zero.
440func ByteArrayFree(ArrayVar []byte, FreeSegmentVar bool) uintptr {
441
442 cret := xByteArrayFree(ArrayVar, FreeSegmentVar)
443
444 return cret
445}
446
447var xByteArrayFreeToBytes func([]byte) *Bytes
448
449// Transfers the data from the `GByteArray` into a new immutable
450// [struct@GLib.Bytes].
451//
452// The `GByteArray` is freed unless the reference count of @array is greater
453// than one, in which the `GByteArray` wrapper is preserved but the size of
454// @array will be set to zero.
455//
456// This is identical to using [ctor@GLib.Bytes.new_take] and
457// [func@GLib.ByteArray.free] together.
458func ByteArrayFreeToBytes(ArrayVar []byte) *Bytes {
459
460 cret := xByteArrayFreeToBytes(ArrayVar)
461
462 return cret
463}
464
465var xByteArrayNew func() uintptr
466
467// Creates a new `GByteArray` with a reference count of 1.
468func ByteArrayNew() uintptr {
469
470 cret := xByteArrayNew()
471
472 return cret
473}
474
475var xByteArrayNewTake func([]byte, uint) uintptr
476
477// Creates a byte array containing the @data.
478// After this call, @data belongs to the `GByteArray` and may no longer be
479// modified by the caller. The memory of @data has to be dynamically
480// allocated and will eventually be freed with [func@GLib.free].
481//
482// Do not use it if @len is greater than [`G_MAXUINT`](types.html#guint).
483// `GByteArray` stores the length of its data in `guint`, which may be shorter
484// than `gsize`.
485func ByteArrayNewTake(DataVar []byte, LenVar uint) uintptr {
486
487 cret := xByteArrayNewTake(DataVar, LenVar)
488
489 return cret
490}
491
492var xByteArrayPrepend func([]byte, []byte, uint) uintptr
493
494// Adds the given data to the start of the `GByteArray`.
495// The array will grow in size automatically if necessary.
496func ByteArrayPrepend(ArrayVar []byte, DataVar []byte, LenVar uint) uintptr {
497
498 cret := xByteArrayPrepend(ArrayVar, DataVar, LenVar)
499
500 return cret
501}
502
503var xByteArrayRef func([]byte) uintptr
504
505// Atomically increments the reference count of @array by one.
506// This function is thread-safe and may be called from any thread.
507func ByteArrayRef(ArrayVar []byte) uintptr {
508
509 cret := xByteArrayRef(ArrayVar)
510
511 return cret
512}
513
514var xByteArrayRemoveIndex func([]byte, uint) uintptr
515
516// Removes the byte at the given index from a `GByteArray`.
517// The following bytes are moved down one place.
518func ByteArrayRemoveIndex(ArrayVar []byte, IndexVar uint) uintptr {
519
520 cret := xByteArrayRemoveIndex(ArrayVar, IndexVar)
521
522 return cret
523}
524
525var xByteArrayRemoveIndexFast func([]byte, uint) uintptr
526
527// Removes the byte at the given index from a `GByteArray`. The last
528// element in the array is used to fill in the space, so this function
529// does not preserve the order of the `GByteArray`. But it is faster
530// than [func@GLib.ByteArray.remove_index].
531func ByteArrayRemoveIndexFast(ArrayVar []byte, IndexVar uint) uintptr {
532
533 cret := xByteArrayRemoveIndexFast(ArrayVar, IndexVar)
534
535 return cret
536}
537
538var xByteArrayRemoveRange func([]byte, uint, uint) uintptr
539
540// Removes the given number of bytes starting at the given index from a
541// `GByteArray`. The following elements are moved to close the gap.
542func ByteArrayRemoveRange(ArrayVar []byte, IndexVar uint, LengthVar uint) uintptr {
543
544 cret := xByteArrayRemoveRange(ArrayVar, IndexVar, LengthVar)
545
546 return cret
547}
548
549var xByteArraySetSize func([]byte, uint) uintptr
550
551// Sets the size of the `GByteArray`, expanding it if necessary.
552func ByteArraySetSize(ArrayVar []byte, LengthVar uint) uintptr {
553
554 cret := xByteArraySetSize(ArrayVar, LengthVar)
555
556 return cret
557}
558
559var xByteArraySizedNew func(uint) uintptr
560
561// Creates a new `GByteArray` with @reserved_size bytes preallocated.
562// This avoids frequent reallocation, if you are going to add many
563// bytes to the array. Note however that the size of the array is still
564// 0.
565func ByteArraySizedNew(ReservedSizeVar uint) uintptr {
566
567 cret := xByteArraySizedNew(ReservedSizeVar)
568
569 return cret
570}
571
572var xByteArraySort func([]byte, uintptr)
573
574// Sorts a byte array, using @compare_func which should be a
575// `qsort()`-style comparison function (returns less than zero for first
576// arg is less than second arg, zero for equal, greater than zero if
577// first arg is greater than second arg).
578//
579// If two array elements compare equal, their order in the sorted array
580// is undefined. If you want equal elements to keep their order (i.e.
581// you want a stable sort) you can write a comparison function that,
582// if two elements would otherwise compare equal, compares them by
583// their addresses.
584func ByteArraySort(ArrayVar []byte, CompareFuncVar *CompareFunc) {
585
586 var CompareFuncVarRef uintptr
587 if CompareFuncVar != nil {
588 CompareFuncVarPtr := uintptr(unsafe.Pointer(CompareFuncVar))
589 if cbRefPtr, ok := GetCallback(CompareFuncVarPtr); ok {
590 CompareFuncVarRef = cbRefPtr
591 } else {
592 fcb := func(arg0 uintptr, arg1 uintptr) int {
593 cbFn := *CompareFuncVar
594 return cbFn(arg0, arg1)
595 }
596 CompareFuncVarRef = purego.NewCallback(fcb)
597 SaveCallbackWithClosure(CompareFuncVarPtr, CompareFuncVarRef, CompareFuncVar)
598 }
599 }
600
601 xByteArraySort(ArrayVar, CompareFuncVarRef)
602
603}
604
605var xByteArraySortWithData func([]byte, uintptr, uintptr)
606
607// Like [func@GLib.ByteArray.sort], but the comparison function takes an extra
608// user data argument.
609func ByteArraySortWithData(ArrayVar []byte, CompareFuncVar *CompareDataFunc, UserDataVar uintptr) {
610
611 var CompareFuncVarRef uintptr
612 if CompareFuncVar != nil {
613 CompareFuncVarPtr := uintptr(unsafe.Pointer(CompareFuncVar))
614 if cbRefPtr, ok := GetCallback(CompareFuncVarPtr); ok {
615 CompareFuncVarRef = cbRefPtr
616 } else {
617 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) int {
618 cbFn := *CompareFuncVar
619 return cbFn(arg0, arg1, arg2)
620 }
621 CompareFuncVarRef = purego.NewCallback(fcb)
622 SaveCallbackWithClosure(CompareFuncVarPtr, CompareFuncVarRef, CompareFuncVar)
623 }
624 }
625
626 xByteArraySortWithData(ArrayVar, CompareFuncVarRef, UserDataVar)
627
628}
629
630var xByteArraySteal func([]byte, *uint) uintptr
631
632// Frees the data in the array and resets the size to zero, while
633// the underlying array is preserved for use elsewhere and returned
634// to the caller.
635func ByteArraySteal(ArrayVar []byte, LenVar *uint) uintptr {
636
637 cret := xByteArraySteal(ArrayVar, LenVar)
638
639 return cret
640}
641
642var xByteArrayUnref func([]byte)
643
644// Atomically decrements the reference count of @array by one. If the
645// reference count drops to 0, all memory allocated by the array is
646// released. This function is thread-safe and may be called from any
647// thread.
648func ByteArrayUnref(ArrayVar []byte) {
649
650 xByteArrayUnref(ArrayVar)
651
652}
653
654var xPtrArrayFind func([]uintptr, uintptr, *uint) bool
655
656// Checks whether @needle exists in @haystack. If the element is found, true
657// is returned and the element’s index is returned in @index_ (if non-`NULL`).
658// Otherwise, false is returned and @index_ is undefined. If @needle exists
659// multiple times in @haystack, the index of the first instance is returned.
660//
661// This does pointer comparisons only. If you want to use more complex equality
662// checks, such as string comparisons, use
663// [func@GLib.PtrArray.find_with_equal_func].
664func PtrArrayFind(HaystackVar []uintptr, NeedleVar uintptr, IndexVar *uint) bool {
665
666 cret := xPtrArrayFind(HaystackVar, NeedleVar, IndexVar)
667
668 return cret
669}
670
671var xPtrArrayFindWithEqualFunc func([]uintptr, uintptr, uintptr, *uint) bool
672
673// Checks whether @needle exists in @haystack, using the given @equal_func.
674// If the element is found, true is returned and the element’s index is
675// returned in @index_ (if non-`NULL`). Otherwise, false is returned and @index_
676// is undefined. If @needle exists multiple times in @haystack, the index of
677// the first instance is returned.
678//
679// @equal_func is called with the element from the array as its first parameter,
680// and @needle as its second parameter. If @equal_func is `NULL`, pointer
681// equality is used.
682func PtrArrayFindWithEqualFunc(HaystackVar []uintptr, NeedleVar uintptr, EqualFuncVar *EqualFunc, IndexVar *uint) bool {
683
684 var EqualFuncVarRef uintptr
685 if EqualFuncVar != nil {
686 EqualFuncVarPtr := uintptr(unsafe.Pointer(EqualFuncVar))
687 if cbRefPtr, ok := GetCallback(EqualFuncVarPtr); ok {
688 EqualFuncVarRef = cbRefPtr
689 } else {
690 fcb := func(arg0 uintptr, arg1 uintptr) bool {
691 cbFn := *EqualFuncVar
692 return cbFn(arg0, arg1)
693 }
694 EqualFuncVarRef = purego.NewCallback(fcb)
695 SaveCallbackWithClosure(EqualFuncVarPtr, EqualFuncVarRef, EqualFuncVar)
696 }
697 }
698
699 cret := xPtrArrayFindWithEqualFunc(HaystackVar, NeedleVar, EqualFuncVarRef, IndexVar)
700
701 return cret
702}
703
704var xPtrArrayNewFromArray func([]uintptr, uint, uintptr, uintptr, uintptr) uintptr
705
706// Creates a new `GPtrArray`, copying @len pointers from @data, and setting
707// the array’s reference count to 1.
708//
709// This avoids having to manually add each element one by one.
710//
711// If @copy_func is provided, then it is used to copy each element before
712// adding them to the new array. If it is `NULL` then the pointers are copied
713// directly.
714//
715// It also sets @element_free_func for freeing each element when the array is
716// destroyed either via [func@GLib.PtrArray.unref], when
717// [func@GLib.PtrArray.free] is called with @free_segment set to true or when
718// removing elements.
719//
720// Do not use it if @len is greater than [`G_MAXUINT`](types.html#guint).
721// `GPtrArray` stores the length of its data in `guint`, which may be shorter
722// than `gsize`.
723func PtrArrayNewFromArray(DataVar []uintptr, LenVar uint, CopyFuncVar *CopyFunc, CopyFuncUserDataVar uintptr, ElementFreeFuncVar *DestroyNotify) uintptr {
724
725 var CopyFuncVarRef uintptr
726 if CopyFuncVar != nil {
727 CopyFuncVarPtr := uintptr(unsafe.Pointer(CopyFuncVar))
728 if cbRefPtr, ok := GetCallback(CopyFuncVarPtr); ok {
729 CopyFuncVarRef = cbRefPtr
730 } else {
731 fcb := func(arg0 uintptr, arg1 uintptr) uintptr {
732 cbFn := *CopyFuncVar
733 return cbFn(arg0, arg1)
734 }
735 CopyFuncVarRef = purego.NewCallback(fcb)
736 SaveCallbackWithClosure(CopyFuncVarPtr, CopyFuncVarRef, CopyFuncVar)
737 }
738 }
739
740 var ElementFreeFuncVarRef uintptr
741 if ElementFreeFuncVar != nil {
742 ElementFreeFuncVarPtr := uintptr(unsafe.Pointer(ElementFreeFuncVar))
743 if cbRefPtr, ok := GetCallback(ElementFreeFuncVarPtr); ok {
744 ElementFreeFuncVarRef = cbRefPtr
745 } else {
746 fcb := func(arg0 uintptr) {
747 cbFn := *ElementFreeFuncVar
748 cbFn(arg0)
749 }
750 ElementFreeFuncVarRef = purego.NewCallback(fcb)
751 SaveCallbackWithClosure(ElementFreeFuncVarPtr, ElementFreeFuncVarRef, ElementFreeFuncVar)
752 }
753 }
754
755 cret := xPtrArrayNewFromArray(DataVar, LenVar, CopyFuncVarRef, CopyFuncUserDataVar, ElementFreeFuncVarRef)
756
757 return cret
758}
759
760var xPtrArrayNewFromNullTerminatedArray func([]uintptr, uintptr, uintptr, uintptr) uintptr
761
762// Creates a new `GPtrArray` copying the pointers from @data after having
763// computed the length of it and with a reference count of 1.
764// This avoids having to manually add each element one by one.
765// If @copy_func is provided, then it is used to copy the data in the new
766// array.
767// It also sets @element_free_func for freeing each element when the array is
768// destroyed either via [func@GLib.PtrArray.unref], when
769// [func@GLib.PtrArray.free] is called with @free_segment set to true or when
770// removing elements.
771//
772// Do not use it if the @data has more than [`G_MAXUINT`](types.html#guint)
773// elements. `GPtrArray` stores the length of its data in `guint`, which may be
774// shorter than `gsize`.
775func PtrArrayNewFromNullTerminatedArray(DataVar []uintptr, CopyFuncVar *CopyFunc, CopyFuncUserDataVar uintptr, ElementFreeFuncVar *DestroyNotify) uintptr {
776
777 var CopyFuncVarRef uintptr
778 if CopyFuncVar != nil {
779 CopyFuncVarPtr := uintptr(unsafe.Pointer(CopyFuncVar))
780 if cbRefPtr, ok := GetCallback(CopyFuncVarPtr); ok {
781 CopyFuncVarRef = cbRefPtr
782 } else {
783 fcb := func(arg0 uintptr, arg1 uintptr) uintptr {
784 cbFn := *CopyFuncVar
785 return cbFn(arg0, arg1)
786 }
787 CopyFuncVarRef = purego.NewCallback(fcb)
788 SaveCallbackWithClosure(CopyFuncVarPtr, CopyFuncVarRef, CopyFuncVar)
789 }
790 }
791
792 var ElementFreeFuncVarRef uintptr
793 if ElementFreeFuncVar != nil {
794 ElementFreeFuncVarPtr := uintptr(unsafe.Pointer(ElementFreeFuncVar))
795 if cbRefPtr, ok := GetCallback(ElementFreeFuncVarPtr); ok {
796 ElementFreeFuncVarRef = cbRefPtr
797 } else {
798 fcb := func(arg0 uintptr) {
799 cbFn := *ElementFreeFuncVar
800 cbFn(arg0)
801 }
802 ElementFreeFuncVarRef = purego.NewCallback(fcb)
803 SaveCallbackWithClosure(ElementFreeFuncVarPtr, ElementFreeFuncVarRef, ElementFreeFuncVar)
804 }
805 }
806
807 cret := xPtrArrayNewFromNullTerminatedArray(DataVar, CopyFuncVarRef, CopyFuncUserDataVar, ElementFreeFuncVarRef)
808
809 return cret
810}
811
812var xPtrArrayNewTake func([]uintptr, uint, uintptr) uintptr
813
814// Creates a new `GPtrArray` with @data as pointers, @len as length and a
815// reference count of 1.
816//
817// This avoids having to copy such data manually.
818// After this call, @data belongs to the `GPtrArray` and may no longer be
819// modified by the caller. The memory of @data has to be dynamically
820// allocated and will eventually be freed with [func@GLib.free].
821//
822// It also sets @element_free_func for freeing each element when the array is
823// destroyed either via [func@GLib.PtrArray.unref], when
824// [func@GLib.PtrArray.free] is called with @free_segment set to true or when
825// removing elements.
826//
827// Do not use it if @len is greater than [`G_MAXUINT`](types.html#guint).
828// `GPtrArray` stores the length of its data in `guint`, which may be shorter
829// than `gsize`.
830func PtrArrayNewTake(DataVar []uintptr, LenVar uint, ElementFreeFuncVar *DestroyNotify) uintptr {
831
832 var ElementFreeFuncVarRef uintptr
833 if ElementFreeFuncVar != nil {
834 ElementFreeFuncVarPtr := uintptr(unsafe.Pointer(ElementFreeFuncVar))
835 if cbRefPtr, ok := GetCallback(ElementFreeFuncVarPtr); ok {
836 ElementFreeFuncVarRef = cbRefPtr
837 } else {
838 fcb := func(arg0 uintptr) {
839 cbFn := *ElementFreeFuncVar
840 cbFn(arg0)
841 }
842 ElementFreeFuncVarRef = purego.NewCallback(fcb)
843 SaveCallbackWithClosure(ElementFreeFuncVarPtr, ElementFreeFuncVarRef, ElementFreeFuncVar)
844 }
845 }
846
847 cret := xPtrArrayNewTake(DataVar, LenVar, ElementFreeFuncVarRef)
848
849 return cret
850}
851
852var xPtrArrayNewTakeNullTerminated func([]uintptr, uintptr) uintptr
853
854// Creates a new `GPtrArray` with @data as pointers, computing the length of it
855// and setting the reference count to 1.
856//
857// This avoids having to copy such data manually.
858// After this call, @data belongs to the `GPtrArray` and may no longer be
859// modified by the caller. The memory of @data has to be dynamically
860// allocated and will eventually be freed with [func@GLib.free].
861//
862// The length is calculated by iterating through @data until the first `NULL`
863// element is found.
864//
865// It also sets @element_free_func for freeing each element when the array is
866// destroyed either via [func@GLib.PtrArray.unref], when
867// [func@GLib.PtrArray.free] is called with @free_segment set to true or when
868// removing elements.
869//
870// Do not use it if the @data length is greater than
871// [`G_MAXUINT`](types.html#guint). `GPtrArray` stores the length of its data
872// in `guint`, which may be shorter than `gsize`.
873func PtrArrayNewTakeNullTerminated(DataVar []uintptr, ElementFreeFuncVar *DestroyNotify) uintptr {
874
875 var ElementFreeFuncVarRef uintptr
876 if ElementFreeFuncVar != nil {
877 ElementFreeFuncVarPtr := uintptr(unsafe.Pointer(ElementFreeFuncVar))
878 if cbRefPtr, ok := GetCallback(ElementFreeFuncVarPtr); ok {
879 ElementFreeFuncVarRef = cbRefPtr
880 } else {
881 fcb := func(arg0 uintptr) {
882 cbFn := *ElementFreeFuncVar
883 cbFn(arg0)
884 }
885 ElementFreeFuncVarRef = purego.NewCallback(fcb)
886 SaveCallbackWithClosure(ElementFreeFuncVarPtr, ElementFreeFuncVarRef, ElementFreeFuncVar)
887 }
888 }
889
890 cret := xPtrArrayNewTakeNullTerminated(DataVar, ElementFreeFuncVarRef)
891
892 return cret
893}
894
895func init() {
896 core.SetPackageName("GLIB", "glib-2.0")
897 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
898 var libs []uintptr
899 for _, libPath := range core.GetPaths("GLIB") {
900 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
901 if err != nil {
902 panic(err)
903 }
904 libs = append(libs, lib)
905 }
906
907 core.PuregoSafeRegister(&xArrayNewTake, libs, "g_array_new_take")
908 core.PuregoSafeRegister(&xArrayNewTakeZeroTerminated, libs, "g_array_new_take_zero_terminated")
909 core.PuregoSafeRegister(&xByteArrayAppend, libs, "g_byte_array_append")
910 core.PuregoSafeRegister(&xByteArrayFree, libs, "g_byte_array_free")
911 core.PuregoSafeRegister(&xByteArrayFreeToBytes, libs, "g_byte_array_free_to_bytes")
912 core.PuregoSafeRegister(&xByteArrayNew, libs, "g_byte_array_new")
913 core.PuregoSafeRegister(&xByteArrayNewTake, libs, "g_byte_array_new_take")
914 core.PuregoSafeRegister(&xByteArrayPrepend, libs, "g_byte_array_prepend")
915 core.PuregoSafeRegister(&xByteArrayRef, libs, "g_byte_array_ref")
916 core.PuregoSafeRegister(&xByteArrayRemoveIndex, libs, "g_byte_array_remove_index")
917 core.PuregoSafeRegister(&xByteArrayRemoveIndexFast, libs, "g_byte_array_remove_index_fast")
918 core.PuregoSafeRegister(&xByteArrayRemoveRange, libs, "g_byte_array_remove_range")
919 core.PuregoSafeRegister(&xByteArraySetSize, libs, "g_byte_array_set_size")
920 core.PuregoSafeRegister(&xByteArraySizedNew, libs, "g_byte_array_sized_new")
921 core.PuregoSafeRegister(&xByteArraySort, libs, "g_byte_array_sort")
922 core.PuregoSafeRegister(&xByteArraySortWithData, libs, "g_byte_array_sort_with_data")
923 core.PuregoSafeRegister(&xByteArraySteal, libs, "g_byte_array_steal")
924 core.PuregoSafeRegister(&xByteArrayUnref, libs, "g_byte_array_unref")
925 core.PuregoSafeRegister(&xPtrArrayFind, libs, "g_ptr_array_find")
926 core.PuregoSafeRegister(&xPtrArrayFindWithEqualFunc, libs, "g_ptr_array_find_with_equal_func")
927 core.PuregoSafeRegister(&xPtrArrayNewFromArray, libs, "g_ptr_array_new_from_array")
928 core.PuregoSafeRegister(&xPtrArrayNewFromNullTerminatedArray, libs, "g_ptr_array_new_from_null_terminated_array")
929 core.PuregoSafeRegister(&xPtrArrayNewTake, libs, "g_ptr_array_new_take")
930 core.PuregoSafeRegister(&xPtrArrayNewTakeNullTerminated, libs, "g_ptr_array_new_take_null_terminated")
931
932 core.PuregoSafeRegister(&xArrayGLibType, libs, "g_array_get_type")
933
934 core.PuregoSafeRegister(&xByteArrayGLibType, libs, "g_byte_array_get_type")
935
936 core.PuregoSafeRegister(&xBytesGLibType, libs, "g_bytes_get_type")
937
938 core.PuregoSafeRegister(&xNewBytes, libs, "g_bytes_new")
939 core.PuregoSafeRegister(&xNewBytesStatic, libs, "g_bytes_new_static")
940 core.PuregoSafeRegister(&xNewBytesTake, libs, "g_bytes_new_take")
941 core.PuregoSafeRegister(&xNewBytesWithFreeFunc, libs, "g_bytes_new_with_free_func")
942
943 core.PuregoSafeRegister(&xBytesCompare, libs, "g_bytes_compare")
944 core.PuregoSafeRegister(&xBytesEqual, libs, "g_bytes_equal")
945 core.PuregoSafeRegister(&xBytesGetData, libs, "g_bytes_get_data")
946 core.PuregoSafeRegister(&xBytesGetRegion, libs, "g_bytes_get_region")
947 core.PuregoSafeRegister(&xBytesGetSize, libs, "g_bytes_get_size")
948 core.PuregoSafeRegister(&xBytesHash, libs, "g_bytes_hash")
949 core.PuregoSafeRegister(&xBytesNewFromBytes, libs, "g_bytes_new_from_bytes")
950 core.PuregoSafeRegister(&xBytesRef, libs, "g_bytes_ref")
951 core.PuregoSafeRegister(&xBytesUnref, libs, "g_bytes_unref")
952 core.PuregoSafeRegister(&xBytesUnrefToArray, libs, "g_bytes_unref_to_array")
953 core.PuregoSafeRegister(&xBytesUnrefToData, libs, "g_bytes_unref_to_data")
954
955 core.PuregoSafeRegister(&xPtrArrayGLibType, libs, "g_ptr_array_get_type")
956
957}