noobs 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/COPYING +339 -0
  2. package/README.md +46 -0
  3. package/bin/64bit/obs.lib +0 -0
  4. package/binding.gyp +23 -0
  5. package/dist/bin/Qt6Core.dll +0 -0
  6. package/dist/bin/Qt6Gui.dll +0 -0
  7. package/dist/bin/Qt6Network.dll +0 -0
  8. package/dist/bin/Qt6Svg.dll +0 -0
  9. package/dist/bin/Qt6Widgets.dll +0 -0
  10. package/dist/bin/Qt6Xml.dll +0 -0
  11. package/dist/bin/avcodec-61.dll +0 -0
  12. package/dist/bin/avdevice-61.dll +0 -0
  13. package/dist/bin/avfilter-10.dll +0 -0
  14. package/dist/bin/avformat-61.dll +0 -0
  15. package/dist/bin/avutil-59.dll +0 -0
  16. package/dist/bin/datachannel.dll +0 -0
  17. package/dist/bin/libcurl.dll +0 -0
  18. package/dist/bin/libobs-d3d11.dll +0 -0
  19. package/dist/bin/libobs-opengl.dll +0 -0
  20. package/dist/bin/libobs-winrt.dll +0 -0
  21. package/dist/bin/librist.dll +0 -0
  22. package/dist/bin/libx264-164.dll +0 -0
  23. package/dist/bin/lua51.dll +0 -0
  24. package/dist/bin/obs-amf-test.exe +0 -0
  25. package/dist/bin/obs-ffmpeg-mux.exe +0 -0
  26. package/dist/bin/obs-frontend-api.dll +0 -0
  27. package/dist/bin/obs-scripting.dll +0 -0
  28. package/dist/bin/obs.dll +0 -0
  29. package/dist/bin/srt.dll +0 -0
  30. package/dist/bin/swresample-5.dll +0 -0
  31. package/dist/bin/swscale-8.dll +0 -0
  32. package/dist/bin/w32-pthreads.dll +0 -0
  33. package/dist/bin/zlib.dll +0 -0
  34. package/dist/effects/area.effect +250 -0
  35. package/dist/effects/bicubic_scale.effect +236 -0
  36. package/dist/effects/bilinear_lowres_scale.effect +123 -0
  37. package/dist/effects/color.effect +172 -0
  38. package/dist/effects/default.effect +254 -0
  39. package/dist/effects/default_rect.effect +84 -0
  40. package/dist/effects/deinterlace_base.effect +325 -0
  41. package/dist/effects/deinterlace_blend.effect +21 -0
  42. package/dist/effects/deinterlace_blend_2x.effect +21 -0
  43. package/dist/effects/deinterlace_discard.effect +21 -0
  44. package/dist/effects/deinterlace_discard_2x.effect +21 -0
  45. package/dist/effects/deinterlace_linear.effect +21 -0
  46. package/dist/effects/deinterlace_linear_2x.effect +21 -0
  47. package/dist/effects/deinterlace_yadif.effect +21 -0
  48. package/dist/effects/deinterlace_yadif_2x.effect +21 -0
  49. package/dist/effects/format_conversion.effect +1823 -0
  50. package/dist/effects/lanczos_scale.effect +292 -0
  51. package/dist/effects/opaque.effect +159 -0
  52. package/dist/effects/premultiplied_alpha.effect +38 -0
  53. package/dist/effects/repeat.effect +36 -0
  54. package/dist/effects/solid.effect +80 -0
  55. package/dist/noobs.node +0 -0
  56. package/dist/plugins/obs-ffmpeg.dll +0 -0
  57. package/dist/plugins/obs-x264.dll +0 -0
  58. package/dist/plugins/win-capture.dll +0 -0
  59. package/include/audio-monitoring/osx/mac-helpers.h +13 -0
  60. package/include/audio-monitoring/pulse/pulseaudio-wrapper.h +212 -0
  61. package/include/audio-monitoring/win32/wasapi-output.h +22 -0
  62. package/include/callback/calldata.h +195 -0
  63. package/include/callback/decl.h +61 -0
  64. package/include/callback/proc.h +52 -0
  65. package/include/callback/signal.h +73 -0
  66. package/include/graphics/axisang.h +65 -0
  67. package/include/graphics/bounds.h +108 -0
  68. package/include/graphics/device-exports.h +177 -0
  69. package/include/graphics/effect-parser.h +290 -0
  70. package/include/graphics/effect.h +190 -0
  71. package/include/graphics/graphics-internal.h +335 -0
  72. package/include/graphics/graphics.h +1024 -0
  73. package/include/graphics/half.h +100 -0
  74. package/include/graphics/image-file.h +124 -0
  75. package/include/graphics/input.h +34 -0
  76. package/include/graphics/libnsgif/libnsgif.h +142 -0
  77. package/include/graphics/math-defs.h +45 -0
  78. package/include/graphics/math-extra.h +61 -0
  79. package/include/graphics/matrix3.h +98 -0
  80. package/include/graphics/matrix4.h +102 -0
  81. package/include/graphics/plane.h +85 -0
  82. package/include/graphics/quat.h +170 -0
  83. package/include/graphics/shader-parser.h +273 -0
  84. package/include/graphics/srgb.h +177 -0
  85. package/include/graphics/vec2.h +148 -0
  86. package/include/graphics/vec3.h +224 -0
  87. package/include/graphics/vec4.h +241 -0
  88. package/include/media-io/audio-io.h +228 -0
  89. package/include/media-io/audio-math.h +43 -0
  90. package/include/media-io/audio-resampler.h +44 -0
  91. package/include/media-io/format-conversion.h +50 -0
  92. package/include/media-io/frame-rate.h +29 -0
  93. package/include/media-io/media-io-defs.h +20 -0
  94. package/include/media-io/media-remux.h +37 -0
  95. package/include/media-io/video-frame.h +64 -0
  96. package/include/media-io/video-io.h +338 -0
  97. package/include/media-io/video-scaler.h +43 -0
  98. package/include/obs-audio-controls.h +250 -0
  99. package/include/obs-av1.h +47 -0
  100. package/include/obs-avc.h +55 -0
  101. package/include/obs-config.h +52 -0
  102. package/include/obs-data.h +311 -0
  103. package/include/obs-defs.h +52 -0
  104. package/include/obs-encoder.h +361 -0
  105. package/include/obs-ffmpeg-compat.h +13 -0
  106. package/include/obs-hevc.h +81 -0
  107. package/include/obs-hotkey.h +271 -0
  108. package/include/obs-hotkeys.h +653 -0
  109. package/include/obs-interaction.h +56 -0
  110. package/include/obs-internal.h +1459 -0
  111. package/include/obs-missing-files.h +53 -0
  112. package/include/obs-module.h +181 -0
  113. package/include/obs-nal.h +37 -0
  114. package/include/obs-nix-platform.h +53 -0
  115. package/include/obs-nix-wayland.h +24 -0
  116. package/include/obs-nix-x11.h +22 -0
  117. package/include/obs-nix.h +42 -0
  118. package/include/obs-output.h +96 -0
  119. package/include/obs-properties.h +364 -0
  120. package/include/obs-scene.h +127 -0
  121. package/include/obs-service.h +115 -0
  122. package/include/obs-source.h +568 -0
  123. package/include/obs.h +2608 -0
  124. package/include/obsconfig.h +13 -0
  125. package/include/obsversion.h +5 -0
  126. package/include/util/apple/cfstring-utils.h +16 -0
  127. package/include/util/array-serializer.h +37 -0
  128. package/include/util/base.h +97 -0
  129. package/include/util/bitstream.h +28 -0
  130. package/include/util/bmem.h +94 -0
  131. package/include/util/buffered-file-serializer.h +32 -0
  132. package/include/util/c99defs.h +75 -0
  133. package/include/util/cf-lexer.h +199 -0
  134. package/include/util/cf-parser.h +281 -0
  135. package/include/util/circlebuf.h +319 -0
  136. package/include/util/config-file.h +103 -0
  137. package/include/util/crc32.h +29 -0
  138. package/include/util/curl/curl-helper.h +35 -0
  139. package/include/util/darray.h +606 -0
  140. package/include/util/deque.h +319 -0
  141. package/include/util/dstr.h +320 -0
  142. package/include/util/file-serializer.h +34 -0
  143. package/include/util/lexer.h +273 -0
  144. package/include/util/pipe.h +52 -0
  145. package/include/util/platform.h +223 -0
  146. package/include/util/profiler.h +97 -0
  147. package/include/util/serializer.h +158 -0
  148. package/include/util/simde/check.h +285 -0
  149. package/include/util/simde/debug-trap.h +117 -0
  150. package/include/util/simde/hedley.h +2123 -0
  151. package/include/util/simde/simde-align.h +481 -0
  152. package/include/util/simde/simde-arch.h +537 -0
  153. package/include/util/simde/simde-common.h +918 -0
  154. package/include/util/simde/simde-constify.h +925 -0
  155. package/include/util/simde/simde-detect-clang.h +114 -0
  156. package/include/util/simde/simde-diagnostic.h +447 -0
  157. package/include/util/simde/simde-features.h +550 -0
  158. package/include/util/simde/simde-math.h +1858 -0
  159. package/include/util/simde/x86/mmx.h +2456 -0
  160. package/include/util/simde/x86/sse.h +4479 -0
  161. package/include/util/simde/x86/sse2.h +7549 -0
  162. package/include/util/source-profiler.h +66 -0
  163. package/include/util/sse-intrin.h +32 -0
  164. package/include/util/task.h +22 -0
  165. package/include/util/text-lookup.h +45 -0
  166. package/include/util/threading-posix.h +77 -0
  167. package/include/util/threading-windows.h +142 -0
  168. package/include/util/threading.h +103 -0
  169. package/include/util/utf8.h +35 -0
  170. package/include/util/uthash.h +34 -0
  171. package/include/util/util_uint128.h +108 -0
  172. package/include/util/util_uint64.h +34 -0
  173. package/include/util/windows/device-enum.h +14 -0
  174. package/include/util/windows/obfuscate.h +16 -0
  175. package/include/util/windows/win-registry.h +37 -0
  176. package/include/util/windows/win-version.h +57 -0
  177. package/include/util/windows/window-helpers.h +47 -0
  178. package/index.d.ts +38 -0
  179. package/index.js +8 -0
  180. package/package.json +31 -0
  181. package/src/main.cpp +321 -0
  182. package/src/obs_interface.cpp +605 -0
  183. package/src/obs_interface.h +74 -0
  184. package/src/utils.cpp +80 -0
  185. package/src/utils.h +3 -0
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright (c) 2023 Lain Bailey <lain@obsproject.com>
3
+ *
4
+ * Permission to use, copy, modify, and distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include "c99defs.h"
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ EXPORT uint32_t calc_crc32(uint32_t crc, const void *buf, size_t size);
26
+
27
+ #ifdef __cplusplus
28
+ }
29
+ #endif
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (c) 2023 Lain Bailey <lain@obsproject.com>
3
+ *
4
+ * Permission to use, copy, modify, and distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <curl/curl.h>
20
+
21
+ #if defined(_WIN32) && LIBCURL_VERSION_NUM >= 0x072c00
22
+
23
+ #ifdef CURLSSLOPT_REVOKE_BEST_EFFORT
24
+ #define CURL_OBS_REVOKE_SETTING CURLSSLOPT_REVOKE_BEST_EFFORT
25
+ #else
26
+ #define CURL_OBS_REVOKE_SETTING CURLSSLOPT_NO_REVOKE
27
+ #endif
28
+
29
+ #define curl_obs_set_revoke_setting(handle) curl_easy_setopt(handle, CURLOPT_SSL_OPTIONS, CURL_OBS_REVOKE_SETTING)
30
+
31
+ #else
32
+
33
+ #define curl_obs_set_revoke_setting(handle)
34
+
35
+ #endif
@@ -0,0 +1,606 @@
1
+ /*
2
+ * Copyright (c) 2023 Lain Bailey <lain@obsproject.com>
3
+ *
4
+ * Permission to use, copy, modify, and distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include "c99defs.h"
20
+ #include <string.h>
21
+ #include <stdlib.h>
22
+ #include <assert.h>
23
+
24
+ #include "bmem.h"
25
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+ /*
31
+ * Dynamic array.
32
+ *
33
+ * NOTE: Not type-safe when using directly.
34
+ * Specifying size per call with inline maximizes compiler optimizations
35
+ *
36
+ * See DARRAY macro at the bottom of the file for slightly safer usage.
37
+ */
38
+
39
+ #define DARRAY_INVALID ((size_t)-1)
40
+
41
+ struct darray {
42
+ void *array;
43
+ size_t num;
44
+ size_t capacity;
45
+ };
46
+
47
+ static inline void darray_init(struct darray *dst)
48
+ {
49
+ dst->array = NULL;
50
+ dst->num = 0;
51
+ dst->capacity = 0;
52
+ }
53
+
54
+ static inline void darray_free(struct darray *dst)
55
+ {
56
+ bfree(dst->array);
57
+ dst->array = NULL;
58
+ dst->num = 0;
59
+ dst->capacity = 0;
60
+ }
61
+
62
+ static inline size_t darray_alloc_size(const size_t element_size, const struct darray *da)
63
+ {
64
+ return element_size * da->num;
65
+ }
66
+
67
+ static inline void *darray_item(const size_t element_size, const struct darray *da, size_t idx)
68
+ {
69
+ return (void *)(((uint8_t *)da->array) + element_size * idx);
70
+ }
71
+
72
+ static inline void *darray_end(const size_t element_size, const struct darray *da)
73
+ {
74
+ if (!da->num)
75
+ return NULL;
76
+
77
+ return darray_item(element_size, da, da->num - 1);
78
+ }
79
+
80
+ static inline void darray_reserve(const size_t element_size, struct darray *dst, const size_t capacity)
81
+ {
82
+ void *ptr;
83
+ if (capacity == 0 || capacity <= dst->capacity)
84
+ return;
85
+
86
+ ptr = bmalloc(element_size * capacity);
87
+ if (dst->array) {
88
+ if (dst->num)
89
+ memcpy(ptr, dst->array, element_size * dst->num);
90
+
91
+ bfree(dst->array);
92
+ }
93
+ dst->array = ptr;
94
+ dst->capacity = capacity;
95
+ }
96
+
97
+ static inline void darray_ensure_capacity(const size_t element_size, struct darray *dst, const size_t new_size)
98
+ {
99
+ size_t new_cap;
100
+ void *ptr;
101
+ if (new_size <= dst->capacity)
102
+ return;
103
+
104
+ new_cap = (!dst->capacity) ? new_size : dst->capacity * 2;
105
+ if (new_size > new_cap)
106
+ new_cap = new_size;
107
+ ptr = bmalloc(element_size * new_cap);
108
+ if (dst->array) {
109
+ if (dst->capacity)
110
+ memcpy(ptr, dst->array, element_size * dst->capacity);
111
+
112
+ bfree(dst->array);
113
+ }
114
+ dst->array = ptr;
115
+ dst->capacity = new_cap;
116
+ }
117
+
118
+ static inline void darray_clear(struct darray *dst)
119
+ {
120
+ dst->num = 0;
121
+ }
122
+
123
+ static inline void darray_resize(const size_t element_size, struct darray *dst, const size_t size)
124
+ {
125
+ int b_clear;
126
+ size_t old_num;
127
+
128
+ if (size == dst->num) {
129
+ return;
130
+ } else if (size == 0) {
131
+ dst->num = 0;
132
+ return;
133
+ }
134
+
135
+ b_clear = size > dst->num;
136
+ old_num = dst->num;
137
+
138
+ darray_ensure_capacity(element_size, dst, size);
139
+ dst->num = size;
140
+
141
+ if (b_clear)
142
+ memset(darray_item(element_size, dst, old_num), 0, element_size * (dst->num - old_num));
143
+ }
144
+
145
+ static inline void darray_copy(const size_t element_size, struct darray *dst, const struct darray *da)
146
+ {
147
+ if (da->num == 0) {
148
+ darray_free(dst);
149
+ } else {
150
+ darray_resize(element_size, dst, da->num);
151
+ memcpy(dst->array, da->array, element_size * da->num);
152
+ }
153
+ }
154
+
155
+ static inline void darray_copy_array(const size_t element_size, struct darray *dst, const void *array, const size_t num)
156
+ {
157
+ darray_resize(element_size, dst, num);
158
+ memcpy(dst->array, array, element_size * dst->num);
159
+ }
160
+
161
+ static inline void darray_move(struct darray *dst, struct darray *src)
162
+ {
163
+ darray_free(dst);
164
+ memcpy(dst, src, sizeof(struct darray));
165
+ src->array = NULL;
166
+ src->capacity = 0;
167
+ src->num = 0;
168
+ }
169
+
170
+ static inline size_t darray_find(const size_t element_size, const struct darray *da, const void *item, const size_t idx)
171
+ {
172
+ size_t i;
173
+
174
+ assert(idx <= da->num);
175
+
176
+ for (i = idx; i < da->num; i++) {
177
+ void *compare = darray_item(element_size, da, i);
178
+ if (memcmp(compare, item, element_size) == 0)
179
+ return i;
180
+ }
181
+
182
+ return DARRAY_INVALID;
183
+ }
184
+
185
+ static inline size_t darray_push_back(const size_t element_size, struct darray *dst, const void *item)
186
+ {
187
+ darray_ensure_capacity(element_size, dst, ++dst->num);
188
+ memcpy(darray_end(element_size, dst), item, element_size);
189
+
190
+ return dst->num - 1;
191
+ }
192
+
193
+ static inline void *darray_push_back_new(const size_t element_size, struct darray *dst)
194
+ {
195
+ void *last;
196
+
197
+ darray_ensure_capacity(element_size, dst, ++dst->num);
198
+
199
+ last = darray_end(element_size, dst);
200
+ memset(last, 0, element_size);
201
+ return last;
202
+ }
203
+
204
+ static inline size_t darray_push_back_array(const size_t element_size, struct darray *dst, const void *array,
205
+ const size_t num)
206
+ {
207
+ size_t old_num;
208
+ if (!dst)
209
+ return 0;
210
+ if (!array || !num)
211
+ return dst->num;
212
+
213
+ old_num = dst->num;
214
+ darray_resize(element_size, dst, dst->num + num);
215
+ memcpy(darray_item(element_size, dst, old_num), array, element_size * num);
216
+
217
+ return old_num;
218
+ }
219
+
220
+ static inline size_t darray_push_back_darray(const size_t element_size, struct darray *dst, const struct darray *da)
221
+ {
222
+ return darray_push_back_array(element_size, dst, da->array, da->num);
223
+ }
224
+
225
+ static inline void darray_insert(const size_t element_size, struct darray *dst, const size_t idx, const void *item)
226
+ {
227
+ void *new_item;
228
+ size_t move_count;
229
+
230
+ assert(idx <= dst->num);
231
+
232
+ if (idx == dst->num) {
233
+ darray_push_back(element_size, dst, item);
234
+ return;
235
+ }
236
+
237
+ move_count = dst->num - idx;
238
+ darray_ensure_capacity(element_size, dst, ++dst->num);
239
+
240
+ new_item = darray_item(element_size, dst, idx);
241
+
242
+ memmove(darray_item(element_size, dst, idx + 1), new_item, move_count * element_size);
243
+ memcpy(new_item, item, element_size);
244
+ }
245
+
246
+ static inline void *darray_insert_new(const size_t element_size, struct darray *dst, const size_t idx)
247
+ {
248
+ void *item;
249
+ size_t move_count;
250
+
251
+ assert(idx <= dst->num);
252
+ if (idx == dst->num)
253
+ return darray_push_back_new(element_size, dst);
254
+
255
+ move_count = dst->num - idx;
256
+ darray_ensure_capacity(element_size, dst, ++dst->num);
257
+
258
+ item = darray_item(element_size, dst, idx);
259
+ memmove(darray_item(element_size, dst, idx + 1), item, move_count * element_size);
260
+
261
+ memset(item, 0, element_size);
262
+ return item;
263
+ }
264
+
265
+ static inline void darray_insert_array(const size_t element_size, struct darray *dst, const size_t idx,
266
+ const void *array, const size_t num)
267
+ {
268
+ size_t old_num;
269
+
270
+ assert(array != NULL);
271
+ assert(num != 0);
272
+ assert(idx <= dst->num);
273
+
274
+ old_num = dst->num;
275
+ darray_resize(element_size, dst, dst->num + num);
276
+
277
+ memmove(darray_item(element_size, dst, idx + num), darray_item(element_size, dst, idx),
278
+ element_size * (old_num - idx));
279
+ memcpy(darray_item(element_size, dst, idx), array, element_size * num);
280
+ }
281
+
282
+ static inline void darray_insert_darray(const size_t element_size, struct darray *dst, const size_t idx,
283
+ const struct darray *da)
284
+ {
285
+ darray_insert_array(element_size, dst, idx, da->array, da->num);
286
+ }
287
+
288
+ static inline void darray_erase(const size_t element_size, struct darray *dst, const size_t idx)
289
+ {
290
+ assert(idx < dst->num);
291
+
292
+ if (idx >= dst->num || !--dst->num)
293
+ return;
294
+
295
+ memmove(darray_item(element_size, dst, idx), darray_item(element_size, dst, idx + 1),
296
+ element_size * (dst->num - idx));
297
+ }
298
+
299
+ static inline void darray_erase_item(const size_t element_size, struct darray *dst, const void *item)
300
+ {
301
+ size_t idx = darray_find(element_size, dst, item, 0);
302
+ if (idx != DARRAY_INVALID)
303
+ darray_erase(element_size, dst, idx);
304
+ }
305
+
306
+ static inline void darray_erase_range(const size_t element_size, struct darray *dst, const size_t start,
307
+ const size_t end)
308
+ {
309
+ size_t count, move_count;
310
+
311
+ assert(start <= dst->num);
312
+ assert(end <= dst->num);
313
+ assert(end > start);
314
+
315
+ count = end - start;
316
+ if (count == 1) {
317
+ darray_erase(element_size, dst, start);
318
+ return;
319
+ } else if (count == dst->num) {
320
+ dst->num = 0;
321
+ return;
322
+ }
323
+
324
+ move_count = dst->num - end;
325
+ if (move_count)
326
+ memmove(darray_item(element_size, dst, start), darray_item(element_size, dst, end),
327
+ move_count * element_size);
328
+
329
+ dst->num -= count;
330
+ }
331
+
332
+ static inline void darray_pop_front(const size_t element_size, struct darray *dst)
333
+ {
334
+ assert(dst->num != 0);
335
+
336
+ if (dst->num)
337
+ darray_erase(element_size, dst, 0);
338
+ }
339
+
340
+ static inline void darray_pop_back(const size_t element_size, struct darray *dst)
341
+ {
342
+ assert(dst->num != 0);
343
+
344
+ if (dst->num)
345
+ darray_erase(element_size, dst, dst->num - 1);
346
+ }
347
+
348
+ static inline void darray_join(const size_t element_size, struct darray *dst, struct darray *da)
349
+ {
350
+ darray_push_back_darray(element_size, dst, da);
351
+ darray_free(da);
352
+ }
353
+
354
+ static inline void darray_split(const size_t element_size, struct darray *dst1, struct darray *dst2,
355
+ const struct darray *da, const size_t idx)
356
+ {
357
+ struct darray temp;
358
+
359
+ assert(da->num >= idx);
360
+ assert(dst1 != dst2);
361
+
362
+ darray_init(&temp);
363
+ darray_copy(element_size, &temp, da);
364
+
365
+ darray_free(dst1);
366
+ darray_free(dst2);
367
+
368
+ if (da->num) {
369
+ if (idx)
370
+ darray_copy_array(element_size, dst1, temp.array, temp.num);
371
+ if (idx < temp.num - 1)
372
+ darray_copy_array(element_size, dst2, darray_item(element_size, &temp, idx), temp.num - idx);
373
+ }
374
+
375
+ darray_free(&temp);
376
+ }
377
+
378
+ static inline void darray_move_item(const size_t element_size, struct darray *dst, const size_t from, const size_t to)
379
+ {
380
+ void *temp, *p_from, *p_to;
381
+
382
+ if (from == to)
383
+ return;
384
+
385
+ temp = malloc(element_size);
386
+ if (!temp) {
387
+ bcrash("darray_move_item: out of memory");
388
+ return;
389
+ }
390
+
391
+ p_from = darray_item(element_size, dst, from);
392
+ p_to = darray_item(element_size, dst, to);
393
+
394
+ memcpy(temp, p_from, element_size);
395
+
396
+ if (to < from)
397
+ memmove(darray_item(element_size, dst, to + 1), p_to, element_size * (from - to));
398
+ else
399
+ memmove(p_from, darray_item(element_size, dst, from + 1), element_size * (to - from));
400
+
401
+ memcpy(p_to, temp, element_size);
402
+ free(temp);
403
+ }
404
+
405
+ static inline void darray_swap(const size_t element_size, struct darray *dst, const size_t a, const size_t b)
406
+ {
407
+ void *temp, *a_ptr, *b_ptr;
408
+
409
+ assert(a < dst->num);
410
+ assert(b < dst->num);
411
+
412
+ if (a == b)
413
+ return;
414
+
415
+ temp = malloc(element_size);
416
+ if (!temp)
417
+ bcrash("darray_swap: out of memory");
418
+
419
+ a_ptr = darray_item(element_size, dst, a);
420
+ b_ptr = darray_item(element_size, dst, b);
421
+
422
+ memcpy(temp, a_ptr, element_size);
423
+ memcpy(a_ptr, b_ptr, element_size);
424
+ memcpy(b_ptr, temp, element_size);
425
+
426
+ free(temp);
427
+ }
428
+
429
+ /*
430
+ * Defines to make dynamic arrays more type-safe.
431
+ * Note: Still not 100% type-safe but much better than using darray directly
432
+ * Makes it a little easier to use as well.
433
+ *
434
+ * I did -not- want to use a gigantic macro to generate a crapload of
435
+ * typesafe inline functions per type. It just feels like a mess to me.
436
+ */
437
+
438
+ #define DARRAY(type) \
439
+ union { \
440
+ struct darray da; \
441
+ struct { \
442
+ type *array; \
443
+ size_t num; \
444
+ size_t capacity; \
445
+ }; \
446
+ }
447
+
448
+ #define da_init(v) darray_init(&(v).da)
449
+
450
+ #define da_free(v) darray_free(&(v).da)
451
+
452
+ #define da_alloc_size(v) (sizeof(*(v).array) * (v).num)
453
+
454
+ #define da_end(v) darray_end(sizeof(*(v).array), &(v).da)
455
+
456
+ #define da_reserve(v, capacity) darray_reserve(sizeof(*(v).array), &(v).da, capacity)
457
+
458
+ #define da_resize(v, size) darray_resize(sizeof(*(v).array), &(v).da, size)
459
+
460
+ #define da_clear(v) darray_clear(&(v).da)
461
+
462
+ #define da_copy(dst, src) darray_copy(sizeof(*(dst).array), &(dst).da, &(src).da)
463
+
464
+ #define da_copy_array(dst, src_array, n) darray_copy_array(sizeof(*(dst).array), &(dst).da, src_array, n)
465
+
466
+ #define da_move(dst, src) darray_move(&(dst).da, &(src).da)
467
+
468
+ #ifdef ENABLE_DARRAY_TYPE_TEST
469
+ #ifdef __cplusplus
470
+ #define da_type_test(v, item) \
471
+ ({ \
472
+ if (false) { \
473
+ auto _t = (v).array; \
474
+ _t = (item); \
475
+ (void)_t; \
476
+ *(v).array = *(item); \
477
+ } \
478
+ })
479
+ #else
480
+ #define da_type_test(v, item) \
481
+ ({ \
482
+ if (false) { \
483
+ const typeof(*(v).array) *_t; \
484
+ _t = (item); \
485
+ (void)_t; \
486
+ *(v).array = *(item); \
487
+ } \
488
+ })
489
+ #endif
490
+ #endif // ENABLE_DARRAY_TYPE_TEST
491
+
492
+ #ifdef ENABLE_DARRAY_TYPE_TEST
493
+ #define da_find(v, item, idx) \
494
+ ({ \
495
+ da_type_test(v, item); \
496
+ darray_find(sizeof(*(v).array), &(v).da, item, idx); \
497
+ })
498
+ #else
499
+ #define da_find(v, item, idx) darray_find(sizeof(*(v).array), &(v).da, item, idx)
500
+ #endif
501
+
502
+ #ifdef ENABLE_DARRAY_TYPE_TEST
503
+ #define da_push_back(v, item) \
504
+ ({ \
505
+ da_type_test(v, item); \
506
+ darray_push_back(sizeof(*(v).array), &(v).da, item); \
507
+ })
508
+ #else
509
+ #define da_push_back(v, item) darray_push_back(sizeof(*(v).array), &(v).da, item)
510
+ #endif
511
+
512
+ #ifdef __GNUC__
513
+ /* GCC 12 with -O2 generates a warning -Wstringop-overflow in da_push_back_new,
514
+ * which could be false positive. Extract the macro here to avoid the warning.
515
+ */
516
+ #define da_push_back_new(v) \
517
+ ({ \
518
+ __typeof__(v) *d = &(v); \
519
+ darray_ensure_capacity(sizeof(*d->array), &d->da, ++d->num); \
520
+ memset(&d->array[d->num - 1], 0, sizeof(*d->array)); \
521
+ &d->array[d->num - 1]; \
522
+ })
523
+ #else
524
+ #define da_push_back_new(v) darray_push_back_new(sizeof(*(v).array), &(v).da)
525
+ #endif
526
+
527
+ #ifdef ENABLE_DARRAY_TYPE_TEST
528
+ #define da_push_back_array(dst, src_array, n) \
529
+ ({ \
530
+ da_type_test(dst, src_array); \
531
+ darray_push_back_array(sizeof(*(dst).array), &(dst).da, src_array, n); \
532
+ })
533
+ #else
534
+ #define da_push_back_array(dst, src_array, n) darray_push_back_array(sizeof(*(dst).array), &(dst).da, src_array, n)
535
+ #endif
536
+
537
+ #ifdef ENABLE_DARRAY_TYPE_TEST
538
+ #define da_push_back_da(dst, src) \
539
+ ({ \
540
+ da_type_test(dst, (src).array); \
541
+ darray_push_back_darray(sizeof(*(dst).array), &(dst).da, &(src).da); \
542
+ })
543
+ #else
544
+ #define da_push_back_da(dst, src) darray_push_back_darray(sizeof(*(dst).array), &(dst).da, &(src).da)
545
+ #endif
546
+
547
+ #ifdef ENABLE_DARRAY_TYPE_TEST
548
+ #define da_insert(v, idx, item) \
549
+ ({ \
550
+ da_type_test(v, item); \
551
+ darray_insert(sizeof(*(v).array), &(v).da, idx, item); \
552
+ })
553
+ #else
554
+ #define da_insert(v, idx, item) darray_insert(sizeof(*(v).array), &(v).da, idx, item)
555
+ #endif
556
+
557
+ #define da_insert_new(v, idx) darray_insert_new(sizeof(*(v).array), &(v).da, idx)
558
+
559
+ #ifdef ENABLE_DARRAY_TYPE_TEST
560
+ #define da_insert_array(dst, idx, src_array, n) \
561
+ ({ \
562
+ da_type_test(dst, src_array); \
563
+ darray_insert_array(sizeof(*(dst).array), &(dst).da, idx, src_array, n); \
564
+ })
565
+ #else
566
+ #define da_insert_array(dst, idx, src_array, n) darray_insert_array(sizeof(*(dst).array), &(dst).da, idx, src_array, n)
567
+ #endif
568
+
569
+ #ifdef ENABLE_DARRAY_TYPE_TEST
570
+ #define da_insert_da(dst, idx, src) \
571
+ ({ \
572
+ da_type_test(dst, (src).array); \
573
+ darray_insert_darray(sizeof(*(dst).array), &(dst).da, idx, &(src).da); \
574
+ })
575
+ #else
576
+ #define da_insert_da(dst, idx, src) darray_insert_darray(sizeof(*(dst).array), &(dst).da, idx, &(src).da)
577
+ #endif
578
+
579
+ #define da_erase(dst, idx) darray_erase(sizeof(*(dst).array), &(dst).da, idx)
580
+
581
+ #ifdef ENABLE_DARRAY_TYPE_TEST
582
+ #define da_erase_item(dst, item) \
583
+ ({ \
584
+ da_type_test(dst, item); \
585
+ darray_erase_item(sizeof(*(dst).array), &(dst).da, item); \
586
+ })
587
+ #else
588
+ #define da_erase_item(dst, item) darray_erase_item(sizeof(*(dst).array), &(dst).da, item)
589
+ #endif
590
+
591
+ #define da_erase_range(dst, from, to) darray_erase_range(sizeof(*(dst).array), &(dst).da, from, to)
592
+
593
+ #define da_pop_front(dst) darray_pop_front(sizeof(*(dst).array), &(dst).da);
594
+ #define da_pop_back(dst) darray_pop_back(sizeof(*(dst).array), &(dst).da);
595
+
596
+ #define da_join(dst, src) darray_join(sizeof(*(dst).array), &(dst).da, &(src).da)
597
+
598
+ #define da_split(dst1, dst2, src, idx) darray_split(sizeof(*(src).array), &(dst1).da, &(dst2).da, &(src).da, idx)
599
+
600
+ #define da_move_item(v, from, to) darray_move_item(sizeof(*(v).array), &(v).da, from, to)
601
+
602
+ #define da_swap(v, idx1, idx2) darray_swap(sizeof(*(v).array), &(v).da, idx1, idx2)
603
+
604
+ #ifdef __cplusplus
605
+ }
606
+ #endif