| 1 | /* |
| 2 | * File: glib.c Replacements for glib functions used by pmidi |
| 3 | * |
| 4 | * Copyright (C) 1999 Steve Ratcliffe |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * Code is derived from garray.c which is copyright: |
| 16 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
| 17 | */ |
| 18 | |
| 19 | #include "glib.h"cxx . . $ `<file>/src/glib.h`/ |
| 20 | |
| 21 | /* |
| 22 | * There is no need to use this file, linking against glib is preferable |
| 23 | * if you have it. |
| 24 | */ |
| 25 | |
| 26 | #define MIN_ARRAY_SIZEcxx . . $ `src/glib.c:26:9`! 16 |
| 27 | |
| 28 | |
| 29 | static gintcxx . . $ gint# |
| 30 | g_nearest_powcxx . . $ g_nearest_pow(7864480464b09eea). (gintcxx . . $ gint# num) |
| 31 | { |
| 32 | gintcxx . . $ gint# n = 1; |
| 33 | |
| 34 | while (n < num) |
| 35 | n <<= 1; |
| 36 | |
| 37 | return n; |
| 38 | } |
| 39 | |
| 40 | /* Pointer Array |
| 41 | */ |
| 42 | typedef struct _GRealPtrArraycxx . . $ _GRealPtrArray# GRealPtrArraycxx . . $ GRealPtrArray#; |
| 43 | |
| 44 | struct _GRealPtrArraycxx . . $ _GRealPtrArray# |
| 45 | { |
| 46 | gpointercxx . . $ gpointer# *pdatacxx . . $ _GRealPtrArray#pdata.; |
| 47 | guintcxx . . $ guint# lencxx . . $ _GRealPtrArray#len.; |
| 48 | guintcxx . . $ guint# alloccxx . . $ _GRealPtrArray#alloc.; |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | GPtrArraycxx . . $ GPtrArray#* |
| 53 | g_ptr_array_newcxx . . $ g_ptr_array_new(61b5db61367ab387).(void) |
| 54 | { |
| 55 | GRealPtrArraycxx . . $ GRealPtrArray# *array; |
| 56 | |
| 57 | array = g_newcxx . . $ `src/glib.h:310:11`!(GRealPtrArray, 1); |
| 58 | |
| 59 | array->pdatacxx . . $ _GRealPtrArray#pdata. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 60 | array->lencxx . . $ _GRealPtrArray#len. = 0; |
| 61 | array->alloccxx . . $ _GRealPtrArray#alloc. = 0; |
| 62 | |
| 63 | return (GPtrArraycxx . . $ GPtrArray#*) array; |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | g_ptr_array_freecxx . . $ g_ptr_array_free(a9bf79c3455f9f51).(GPtrArraycxx . . $ GPtrArray# *array, gbooleancxx . . $ gboolean# free_segment) |
| 68 | { |
| 69 | |
| 70 | if (free_segment) |
| 71 | g_freecxx . . $ `src/glib.h:1302:9`!(array->pdata); |
| 72 | |
| 73 | g_freecxx . . $ `src/glib.h:1302:9`!(array); |
| 74 | } |
| 75 | |
| 76 | static void |
| 77 | g_ptr_array_maybe_expandcxx . . $ g_ptr_array_maybe_expand(ac8814b890fdc21b).(GRealPtrArraycxx . . $ GRealPtrArray# *array, gintcxx . . $ gint# len) |
| 78 | { |
| 79 | guintcxx . . $ guint# old_alloc; |
| 80 | |
| 81 | if ((array->lencxx . . $ _GRealPtrArray#len. + len) > array->alloccxx . . $ _GRealPtrArray#alloc.) |
| 82 | { |
| 83 | old_alloc = array->alloccxx . . $ _GRealPtrArray#alloc.; |
| 84 | |
| 85 | array->alloccxx . . $ _GRealPtrArray#alloc. = g_nearest_powcxx . . $ g_nearest_pow(7864480464b09eea).(array->lencxx . . $ _GRealPtrArray#len. + len); |
| 86 | array->alloccxx . . $ _GRealPtrArray#alloc. = MAXcxx . . $ `src/glib.h:134:9`!(array->alloc, MIN_ARRAY_SIZEcxx . . $ `src/glib.c:26:9`!); |
| 87 | if (array->pdatacxx . . $ _GRealPtrArray#pdata.) { |
| 88 | array->pdatacxx . . $ _GRealPtrArray#pdata. = g_realloccxx . . $ `src/glib.h:1301:9`!(array->pdata, |
| 89 | sizeof(gpointer) * array->alloc); |
| 90 | } else { |
| 91 | array->pdatacxx . . $ _GRealPtrArray#pdata. = g_new0cxx . . $ `src/glib.h:312:11`!(gpointer, array->alloc); |
| 92 | } |
| 93 | |
| 94 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(array->pdatacxx . . $ _GRealPtrArray#pdata. + old_alloc, 0, array->alloccxx . . $ _GRealPtrArray#alloc. - old_alloc); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | |
| 99 | gpointercxx . . $ gpointer# |
| 100 | g_ptr_array_remove_index_fastcxx . . $ g_ptr_array_remove_index_fast(1e8ea8549f363c82).(GPtrArraycxx . . $ GPtrArray#* farray, guintcxx . . $ guint# index) |
| 101 | { |
| 102 | GRealPtrArraycxx . . $ GRealPtrArray#* array = (GRealPtrArraycxx . . $ GRealPtrArray#*)farray; |
| 103 | gpointercxx . . $ gpointer# result; |
| 104 | |
| 105 | |
| 106 | result = array->pdatacxx . . $ _GRealPtrArray#pdata.[index]; |
| 107 | |
| 108 | if (index != array->lencxx . . $ _GRealPtrArray#len. - 1) |
| 109 | array->pdatacxx . . $ _GRealPtrArray#pdata.[index] = array->pdatacxx . . $ _GRealPtrArray#pdata.[array->lencxx . . $ _GRealPtrArray#len. - 1]; |
| 110 | |
| 111 | array->pdatacxx . . $ _GRealPtrArray#pdata.[array->lencxx . . $ _GRealPtrArray#len. - 1] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 112 | |
| 113 | array->lencxx . . $ _GRealPtrArray#len. -= 1; |
| 114 | |
| 115 | return result; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | |
| 120 | typedef struct _GRealArraycxx . . $ _GRealArray# GRealArraycxx . . $ GRealArray#; |
| 121 | |
| 122 | struct _GRealArraycxx . . $ _GRealArray# |
| 123 | { |
| 124 | guint8cxx . . $ guint8# *datacxx . . $ _GRealArray#data.; |
| 125 | guintcxx . . $ guint# lencxx . . $ _GRealArray#len.; |
| 126 | guintcxx . . $ guint# alloccxx . . $ _GRealArray#alloc.; |
| 127 | guintcxx . . $ guint# elt_sizecxx . . $ _GRealArray#elt_size.; |
| 128 | guintcxx . . $ guint# zero_terminatedcxx . . $ _GRealArray#zero_terminated. : 1; |
| 129 | guintcxx . . $ guint# clearcxx . . $ _GRealArray#clear. : 1; |
| 130 | }; |
| 131 | |
| 132 | void |
| 133 | g_ptr_array_addcxx . . $ g_ptr_array_add(3cd73f70a4ada9).(GPtrArraycxx . . $ GPtrArray#* farray, gpointercxx . . $ gpointer# data) |
| 134 | { |
| 135 | GRealPtrArraycxx . . $ GRealPtrArray#* array = (GRealPtrArraycxx . . $ GRealPtrArray#*) farray; |
| 136 | |
| 137 | g_ptr_array_maybe_expandcxx . . $ g_ptr_array_maybe_expand(ac8814b890fdc21b).(array, 1); |
| 138 | |
| 139 | array->pdatacxx . . $ _GRealPtrArray#pdata.[array->lencxx . . $ _GRealPtrArray#len.++] = data; |
| 140 | } |
| 141 | |
| 142 | static void |
| 143 | g_array_maybe_expandcxx . . $ g_array_maybe_expand(35c4c52e670fa219). (GRealArraycxx . . $ GRealArray# *array, gintcxx . . $ gint# len) |
| 144 | { |
| 145 | guintcxx . . $ guint# want_alloc = (array->lencxx . . $ _GRealArray#len. + len + array->zero_terminatedcxx . . $ _GRealArray#zero_terminated.) * array->elt_sizecxx . . $ _GRealArray#elt_size.; |
| 146 | if (want_alloc > array->alloccxx . . $ _GRealArray#alloc.) { |
| 147 | guintcxx . . $ guint# old_alloc = array->alloccxx . . $ _GRealArray#alloc.; |
| 148 | |
| 149 | array->alloccxx . . $ _GRealArray#alloc. = g_nearest_powcxx . . $ g_nearest_pow(7864480464b09eea). (want_alloc); |
| 150 | array->alloccxx . . $ _GRealArray#alloc. = MAXcxx . . $ `src/glib.h:134:9`!(array->alloc, MIN_ARRAY_SIZEcxx . . $ `src/glib.c:26:9`!); |
| 151 | |
| 152 | array->datacxx . . $ _GRealArray#data. = g_realloccxx . . $ `src/glib.h:1301:9`! (array->data, array->alloc); |
| 153 | |
| 154 | if (array->clearcxx . . $ _GRealArray#clear. || array->zero_terminatedcxx . . $ _GRealArray#zero_terminated.) |
| 155 | memsetcxx . . $ memset(d1de1e4fb215f1c6). (array->datacxx . . $ _GRealArray#data. + old_alloc, 0, array->alloccxx . . $ _GRealArray#alloc. - old_alloc); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | GArraycxx . . $ GArray#* |
| 160 | g_array_newcxx . . $ g_array_new(fe898421933afc00). (gbooleancxx . . $ gboolean# zero_terminated, gbooleancxx . . $ gboolean# clear, guintcxx . . $ guint# elt_size) |
| 161 | { |
| 162 | GRealArraycxx . . $ GRealArray# *array; |
| 163 | |
| 164 | array = g_newcxx . . $ `src/glib.h:310:11`!(GRealArray, 1); |
| 165 | |
| 166 | array->datacxx . . $ _GRealArray#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 167 | array->lencxx . . $ _GRealArray#len. = 0; |
| 168 | array->alloccxx . . $ _GRealArray#alloc. = 0; |
| 169 | array->zero_terminatedcxx . . $ _GRealArray#zero_terminated. = (zero_terminated ? 1 : 0); |
| 170 | array->clearcxx . . $ _GRealArray#clear. = (clear ? 1 : 0); |
| 171 | array->elt_sizecxx . . $ _GRealArray#elt_size. = elt_size; |
| 172 | |
| 173 | return (GArraycxx . . $ GArray#*) array; |
| 174 | } |
| 175 | |
| 176 | void |
| 177 | g_array_freecxx . . $ g_array_free(9bafc62c18d894b8). (GArraycxx . . $ GArray# *array, gbooleancxx . . $ gboolean# free_segment) |
| 178 | { |
| 179 | if (free_segment) |
| 180 | g_freecxx . . $ `src/glib.h:1302:9`! (array->data); |
| 181 | |
| 182 | g_freecxx . . $ `src/glib.h:1302:9`!(array); |
| 183 | } |
| 184 | |
| 185 | GArraycxx . . $ GArray#* |
| 186 | g_array_append_valscxx . . $ g_array_append_vals(59466536300baf72).(GArraycxx . . $ GArray# *farray, gconstpointercxx . . $ gconstpointer# data, guintcxx . . $ guint# len) |
| 187 | { |
| 188 | GRealArraycxx . . $ GRealArray# *array = (GRealArraycxx . . $ GRealArray#*) farray; |
| 189 | |
| 190 | g_array_maybe_expandcxx . . $ g_array_maybe_expand(35c4c52e670fa219). (array, len); |
| 191 | |
| 192 | memcpycxx . . $ memcpy(cc817cb175f282d). (array->datacxx . . $ _GRealArray#data. + array->elt_sizecxx . . $ _GRealArray#elt_size. * array->lencxx . . $ _GRealArray#len., data, array->elt_sizecxx . . $ _GRealArray#elt_size. * len); |
| 193 | |
| 194 | array->lencxx . . $ _GRealArray#len. += len; |
| 195 | |
| 196 | return farray; |
| 197 | } |