@revizly/sharp-libvips-dev 1.0.31 → 1.0.33

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 (67) hide show
  1. package/README.md +15 -15
  2. package/include/aom/aom_codec.h +1 -1
  3. package/include/aom/aom_decoder.h +4 -0
  4. package/include/aom/aom_encoder.h +19 -8
  5. package/include/aom/aom_ext_ratectrl.h +664 -0
  6. package/include/aom/aom_image.h +93 -30
  7. package/include/aom/aom_tpl.h +99 -0
  8. package/include/aom/aomcx.h +89 -16
  9. package/include/aom/aomdx.h +12 -0
  10. package/include/expat.h +14 -2
  11. package/include/expat_config.h +6 -3
  12. package/include/expat_external.h +3 -2
  13. package/include/glib-2.0/glib/gvarianttype.h +16 -16
  14. package/include/glib-2.0/glib/gversionmacros.h +13 -0
  15. package/include/harfbuzz/hb-cplusplus.hh +9 -1
  16. package/include/harfbuzz/hb-draw.h +52 -0
  17. package/include/harfbuzz/hb-paint.h +209 -2
  18. package/include/harfbuzz/hb-version.h +2 -2
  19. package/include/hwy/aligned_allocator.h +44 -2
  20. package/include/hwy/auto_tune.h +22 -6
  21. package/include/hwy/base.h +60 -90
  22. package/include/hwy/bit_set.h +410 -0
  23. package/include/hwy/cache_control.h +3 -2
  24. package/include/hwy/detect_compiler_arch.h +134 -14
  25. package/include/hwy/detect_targets.h +82 -36
  26. package/include/hwy/highway.h +15 -0
  27. package/include/hwy/nanobenchmark.h +12 -3
  28. package/include/hwy/ops/arm_neon-inl.h +96 -25
  29. package/include/hwy/ops/arm_sve-inl.h +250 -95
  30. package/include/hwy/ops/emu128-inl.h +12 -7
  31. package/include/hwy/ops/generic_ops-inl.h +271 -131
  32. package/include/hwy/ops/loongarch_lasx-inl.h +31 -9
  33. package/include/hwy/ops/loongarch_lsx-inl.h +33 -12
  34. package/include/hwy/ops/ppc_vsx-inl.h +99 -19
  35. package/include/hwy/ops/rvv-inl.h +239 -130
  36. package/include/hwy/ops/scalar-inl.h +22 -7
  37. package/include/hwy/ops/set_macros-inl.h +158 -107
  38. package/include/hwy/ops/wasm_128-inl.h +13 -22
  39. package/include/hwy/ops/x86_128-inl.h +223 -120
  40. package/include/hwy/ops/x86_256-inl.h +70 -134
  41. package/include/hwy/ops/x86_512-inl.h +130 -134
  42. package/include/hwy/print-inl.h +2 -0
  43. package/include/hwy/profiler.h +355 -264
  44. package/include/hwy/robust_statistics.h +3 -1
  45. package/include/hwy/timer.h +44 -0
  46. package/include/lcms2.h +34 -4
  47. package/include/libexif/exif-utils.h +1 -1
  48. package/include/libheif/heif_context.h +13 -0
  49. package/include/libheif/heif_decoding.h +7 -0
  50. package/include/libheif/heif_sequences.h +12 -2
  51. package/include/libheif/heif_uncompressed.h +22 -10
  52. package/include/libheif/heif_uncompressed_types.h +27 -27
  53. package/include/libpng16/png.h +7 -7
  54. package/include/libpng16/pngconf.h +1 -1
  55. package/include/libpng16/pnglibconf.h +1 -1
  56. package/include/librsvg-2.0/librsvg/rsvg-version.h +2 -2
  57. package/include/libxml2/libxml/xmlversion.h +4 -4
  58. package/include/png.h +7 -7
  59. package/include/pngconf.h +1 -1
  60. package/include/pnglibconf.h +1 -1
  61. package/include/tiffconf.h +9 -10
  62. package/include/tiffio.h +10 -9
  63. package/include/tiffvers.h +1 -1
  64. package/include/ultrahdr_api.h +5 -11
  65. package/package.json +1 -1
  66. package/versions.json +13 -13
  67. package/include/librsvg-2.0/librsvg/rsvg-pixbuf.h +0 -235
@@ -33,6 +33,19 @@
33
33
 
34
34
  /* Version boundaries checks */
35
35
 
36
+ /**
37
+ * G_ENCODE_VERSION:
38
+ * @major: major version number
39
+ * @minor: minor version number
40
+ *
41
+ * Encode a major.minor version as a single integer.
42
+ *
43
+ * This is the encoding used by macros such as `GLIB_VERSION_2_84` and
44
+ * `GLIB_VERSION_CUR_STABLE`, and is intended to be used when (for example)
45
+ * setting the value of `GLIB_VERSION_MAX_ALLOWED`.
46
+ *
47
+ * Since: 2.32
48
+ */
36
49
  #define G_ENCODE_VERSION(major, minor) ((major) << 16 | (minor) << 8)
37
50
 
38
51
  /**
@@ -185,7 +185,15 @@ HB_DEFINE_VTABLE (vector_paint, nullptr);
185
185
 
186
186
  #endif
187
187
 
188
- #undef HB_DEFINE_VTABLE
188
+
189
+ #ifdef HB_GPU_H
190
+
191
+ HB_DEFINE_VTABLE (gpu_draw, nullptr);
192
+
193
+ #endif
194
+
195
+ /* HB_DEFINE_VTABLE stays available for subsystem headers' paired tail
196
+ * blocks (see hb-raster.h, hb-vector.h, hb-gpu.h, hb-subset.h). */
189
197
 
190
198
 
191
199
  } // namespace hb
@@ -335,6 +335,58 @@ hb_draw_close_path (hb_draw_funcs_t *dfuncs, void *draw_data,
335
335
  hb_draw_state_t *st);
336
336
 
337
337
 
338
+ /* Shape helpers.
339
+ *
340
+ * Emit common primitives (tapered line, rectangle, circle) into
341
+ * any pen. The helpers are thin wrappers over the individual
342
+ * move_to / line_to / cubic_to / close_path calls: callers can
343
+ * always hand-roll the same shapes if they need a variation.
344
+ *
345
+ * For rect / circle the @stroke_width parameter selects between
346
+ * filled and stroked: a positive finite value is the stroke
347
+ * width of the outline; NaN means "filled" (no stroke).
348
+ */
349
+
350
+ /**
351
+ * hb_draw_line_cap_t:
352
+ * @HB_DRAW_LINE_CAP_BUTT: No cap; the line ends exactly at
353
+ * its endpoint.
354
+ * @HB_DRAW_LINE_CAP_SQUARE: Square cap; the line is extended
355
+ * past its endpoint by half the local stroke width. Useful
356
+ * for composing closed shapes from line segments (e.g. a
357
+ * rectangle made from four lines).
358
+ *
359
+ * End-cap shape for hb_draw_line().
360
+ *
361
+ * Since: 14.2.0
362
+ **/
363
+ typedef enum {
364
+ HB_DRAW_LINE_CAP_BUTT = 0,
365
+ HB_DRAW_LINE_CAP_SQUARE = 1,
366
+ } hb_draw_line_cap_t;
367
+
368
+ HB_EXTERN void
369
+ hb_draw_line (hb_draw_funcs_t *dfuncs, void *draw_data,
370
+ hb_draw_state_t *st,
371
+ float x0, float y0, float w0,
372
+ float x1, float y1, float w1,
373
+ hb_draw_line_cap_t cap);
374
+
375
+ HB_EXTERN void
376
+ hb_draw_rectangle (hb_draw_funcs_t *dfuncs, void *draw_data,
377
+ hb_draw_state_t *st,
378
+ float x, float y,
379
+ float w, float h,
380
+ float stroke_width);
381
+
382
+ HB_EXTERN void
383
+ hb_draw_circle (hb_draw_funcs_t *dfuncs, void *draw_data,
384
+ hb_draw_state_t *st,
385
+ float cx, float cy,
386
+ float r,
387
+ float stroke_width);
388
+
389
+
338
390
  HB_END_DECLS
339
391
 
340
392
  #endif /* HB_DRAW_H */
@@ -30,6 +30,7 @@
30
30
  #define HB_PAINT_H
31
31
 
32
32
  #include "hb-common.h"
33
+ #include "hb-draw.h"
33
34
 
34
35
  HB_BEGIN_DECLS
35
36
 
@@ -212,6 +213,53 @@ typedef void (*hb_paint_push_clip_rectangle_func_t) (hb_paint_funcs_t *funcs,
212
213
  float xmax, float ymax,
213
214
  void *user_data);
214
215
 
216
+ /**
217
+ * hb_paint_push_clip_path_start_func_t:
218
+ * @funcs: paint functions object
219
+ * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
220
+ * @draw_data: (out): location to store the draw data the caller should
221
+ * pass alongside the returned draw funcs.
222
+ * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_path_start_func()
223
+ *
224
+ * A virtual method for the #hb_paint_funcs_t to begin clipping
225
+ * to an arbitrary path. The backend returns an
226
+ * #hb_draw_funcs_t it owns (the caller must not free it)
227
+ * that the caller feeds the clip outline to via hb_draw_*()
228
+ * calls, plus a @draw_data value to pass alongside those
229
+ * calls. Both are only valid until the matching
230
+ * #hb_paint_push_clip_path_end_func_t call; no other paint
231
+ * calls should be made in between. The clip remains
232
+ * in effect until a later #hb_paint_pop_clip_func_t call.
233
+ *
234
+ * Return value: (transfer none): draw funcs that accumulate
235
+ * the clip path, or `NULL` if arbitrary-path clipping is not
236
+ * supported.
237
+ *
238
+ * Since: 14.2.0
239
+ */
240
+ typedef hb_draw_funcs_t * (*hb_paint_push_clip_path_start_func_t) (hb_paint_funcs_t *funcs,
241
+ void *paint_data,
242
+ void **draw_data,
243
+ void *user_data);
244
+
245
+ /**
246
+ * hb_paint_push_clip_path_end_func_t:
247
+ * @funcs: paint functions object
248
+ * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
249
+ * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_path_end_func()
250
+ *
251
+ * A virtual method for the #hb_paint_funcs_t to close the
252
+ * clip path started by the #hb_paint_push_clip_path_start_func_t
253
+ * vfunc. The emitted path is now active as a clip; subsequent
254
+ * paint ops are masked by it until a matching
255
+ * #hb_paint_pop_clip_func_t call.
256
+ *
257
+ * Since: 14.2.0
258
+ */
259
+ typedef void (*hb_paint_push_clip_path_end_func_t) (hb_paint_funcs_t *funcs,
260
+ void *paint_data,
261
+ void *user_data);
262
+
215
263
  /**
216
264
  * hb_paint_pop_clip_func_t:
217
265
  * @funcs: paint functions object
@@ -219,8 +267,9 @@ typedef void (*hb_paint_push_clip_rectangle_func_t) (hb_paint_funcs_t *funcs,
219
267
  * @user_data: User data pointer passed to hb_paint_funcs_set_pop_clip_func()
220
268
  *
221
269
  * A virtual method for the #hb_paint_funcs_t to undo
222
- * the effect of a prior call to the #hb_paint_funcs_push_clip_glyph_func_t
223
- * or #hb_paint_funcs_push_clip_rectangle_func_t vfuncs.
270
+ * the effect of a prior call to the #hb_paint_funcs_push_clip_glyph_func_t,
271
+ * #hb_paint_funcs_push_clip_rectangle_func_t, or
272
+ * #hb_paint_funcs_push_clip_path_end_func_t vfuncs.
224
273
  *
225
274
  * Since: 7.0.0
226
275
  */
@@ -239,6 +288,23 @@ typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs,
239
288
  * A virtual method for the #hb_paint_funcs_t to paint a
240
289
  * color everywhere within the current clip.
241
290
  *
291
+ * When @is_foreground is true, this color originates from the
292
+ * foreground-color sentinel in the font's color data. The
293
+ * @color parameter still carries a fully resolved RGBA value
294
+ * (with any paint-tree alpha already applied), so backends
295
+ * that do not need to distinguish the foreground can simply
296
+ * use @color directly.
297
+ *
298
+ * Backends that defer foreground resolution (e.g. to honor a
299
+ * CSS `currentColor` or a runtime uniform) should substitute
300
+ * their own foreground RGB when @is_foreground is true, but
301
+ * must combine the alpha from @color with their foreground
302
+ * alpha, since it encodes additional modulation from the
303
+ * paint tree. For this mode to work correctly, the caller
304
+ * should pass a fully-opaque foreground color to
305
+ * hb_font_paint_glyph(), so that the alpha in @color
306
+ * reflects only the paint-tree contribution.
307
+ *
242
308
  * Since: 7.0.0
243
309
  */
244
310
  typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs,
@@ -322,6 +388,9 @@ typedef hb_bool_t (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
322
388
  * Color lines typically have offsets ranging between 0 and 1,
323
389
  * but that is not required.
324
390
  *
391
+ * The @is_foreground and @color fields have the same semantics
392
+ * as in #hb_paint_color_func_t.
393
+ *
325
394
  * Note: despite @color being unpremultiplied here, interpolation in
326
395
  * gradients shall happen in premultiplied space. See the OpenType spec
327
396
  * [COLR](https://learn.microsoft.com/en-us/typography/opentype/spec/colr)
@@ -660,6 +729,28 @@ typedef void (*hb_paint_push_group_func_t) (hb_paint_funcs_t *funcs,
660
729
  void *paint_data,
661
730
  void *user_data);
662
731
 
732
+ /**
733
+ * hb_paint_push_group_for_func_t:
734
+ * @funcs: paint functions object
735
+ * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
736
+ * @mode: the compositing mode that will be used when the group is popped
737
+ * @user_data: User data pointer passed to hb_paint_funcs_set_push_group_for_func()
738
+ *
739
+ * A virtual method for the #hb_paint_funcs_t to use
740
+ * an intermediate surface for subsequent paint calls,
741
+ * with the compositing mode known in advance.
742
+ *
743
+ * This is like #hb_paint_push_group_func_t, but the
744
+ * compositing mode is provided at push time. By default
745
+ * this calls #hb_paint_push_group_func_t.
746
+ *
747
+ * Since: 14.2.0
748
+ */
749
+ typedef void (*hb_paint_push_group_for_func_t) (hb_paint_funcs_t *funcs,
750
+ void *paint_data,
751
+ hb_paint_composite_mode_t mode,
752
+ void *user_data);
753
+
663
754
  /**
664
755
  * hb_paint_pop_group_func_t:
665
756
  * @funcs: paint functions object
@@ -797,6 +888,40 @@ hb_paint_funcs_set_push_clip_rectangle_func (hb_paint_funcs_t
797
888
  void *user_data,
798
889
  hb_destroy_func_t destroy);
799
890
 
891
+ /**
892
+ * hb_paint_funcs_set_push_clip_path_start_func:
893
+ * @funcs: A paint functions struct
894
+ * @func: (closure user_data) (destroy destroy) (scope notified): The push-clip-path-start callback
895
+ * @user_data: Data to pass to @func
896
+ * @destroy: (nullable): Function to call when @user_data is no longer needed
897
+ *
898
+ * Sets the push-clip-path-start callback on the paint functions struct.
899
+ *
900
+ * Since: 14.2.0
901
+ */
902
+ HB_EXTERN void
903
+ hb_paint_funcs_set_push_clip_path_start_func (hb_paint_funcs_t *funcs,
904
+ hb_paint_push_clip_path_start_func_t func,
905
+ void *user_data,
906
+ hb_destroy_func_t destroy);
907
+
908
+ /**
909
+ * hb_paint_funcs_set_push_clip_path_end_func:
910
+ * @funcs: A paint functions struct
911
+ * @func: (closure user_data) (destroy destroy) (scope notified): The push-clip-path-end callback
912
+ * @user_data: Data to pass to @func
913
+ * @destroy: (nullable): Function to call when @user_data is no longer needed
914
+ *
915
+ * Sets the push-clip-path-end callback on the paint functions struct.
916
+ *
917
+ * Since: 14.2.0
918
+ */
919
+ HB_EXTERN void
920
+ hb_paint_funcs_set_push_clip_path_end_func (hb_paint_funcs_t *funcs,
921
+ hb_paint_push_clip_path_end_func_t func,
922
+ void *user_data,
923
+ hb_destroy_func_t destroy);
924
+
800
925
  /**
801
926
  * hb_paint_funcs_set_pop_clip_func:
802
927
  * @funcs: A paint functions struct
@@ -916,6 +1041,23 @@ hb_paint_funcs_set_push_group_func (hb_paint_funcs_t *funcs,
916
1041
  void *user_data,
917
1042
  hb_destroy_func_t destroy);
918
1043
 
1044
+ /**
1045
+ * hb_paint_funcs_set_push_group_for_func:
1046
+ * @funcs: A paint functions struct
1047
+ * @func: (closure user_data) (destroy destroy) (scope notified): The push-group-for callback
1048
+ * @user_data: Data to pass to @func
1049
+ * @destroy: (nullable): Function to call when @user_data is no longer needed
1050
+ *
1051
+ * Sets the push-group-for callback on the paint functions struct.
1052
+ *
1053
+ * Since: 14.2.0
1054
+ */
1055
+ HB_EXTERN void
1056
+ hb_paint_funcs_set_push_group_for_func (hb_paint_funcs_t *funcs,
1057
+ hb_paint_push_group_for_func_t func,
1058
+ void *user_data,
1059
+ hb_destroy_func_t destroy);
1060
+
919
1061
  /**
920
1062
  * hb_paint_funcs_set_pop_group_func:
921
1063
  * @funcs: A paint functions struct
@@ -985,6 +1127,15 @@ hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data,
985
1127
  float xmin, float ymin,
986
1128
  float xmax, float ymax);
987
1129
 
1130
+ HB_EXTERN hb_draw_funcs_t *
1131
+ hb_paint_push_clip_path_start (hb_paint_funcs_t *funcs,
1132
+ void *paint_data,
1133
+ void **draw_data);
1134
+
1135
+ HB_EXTERN void
1136
+ hb_paint_push_clip_path_end (hb_paint_funcs_t *funcs,
1137
+ void *paint_data);
1138
+
988
1139
  HB_EXTERN void
989
1140
  hb_paint_pop_clip (hb_paint_funcs_t *funcs, void *paint_data);
990
1141
 
@@ -1026,6 +1177,10 @@ hb_paint_sweep_gradient (hb_paint_funcs_t *funcs, void *paint_data,
1026
1177
  HB_EXTERN void
1027
1178
  hb_paint_push_group (hb_paint_funcs_t *funcs, void *paint_data);
1028
1179
 
1180
+ HB_EXTERN void
1181
+ hb_paint_push_group_for (hb_paint_funcs_t *funcs, void *paint_data,
1182
+ hb_paint_composite_mode_t mode);
1183
+
1029
1184
  HB_EXTERN void
1030
1185
  hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data,
1031
1186
  hb_paint_composite_mode_t mode);
@@ -1035,6 +1190,58 @@ hb_paint_custom_palette_color (hb_paint_funcs_t *funcs, void *paint_data,
1035
1190
  unsigned int color_index,
1036
1191
  hb_color_t *color);
1037
1192
 
1193
+
1194
+ /*
1195
+ * Gradient helpers for paint backends.
1196
+ *
1197
+ * These are small, self-contained utilities that every COLRv1
1198
+ * renderer ends up reinventing. Exposed here so third-party
1199
+ * paint backends can consume a single canonical implementation
1200
+ * instead of forking one per project.
1201
+ */
1202
+
1203
+ HB_EXTERN void
1204
+ hb_paint_reduce_linear_anchors (float x0, float y0,
1205
+ float x1, float y1,
1206
+ float x2, float y2,
1207
+ float *xx0, float *yy0,
1208
+ float *xx1, float *yy1);
1209
+
1210
+ HB_EXTERN void
1211
+ hb_paint_normalize_color_line (hb_color_stop_t *stops,
1212
+ unsigned int len,
1213
+ float *min,
1214
+ float *max);
1215
+
1216
+ /**
1217
+ * hb_paint_sweep_gradient_tile_func_t:
1218
+ * @a0: segment start angle, in radians.
1219
+ * @c0: segment start color.
1220
+ * @a1: segment end angle, in radians.
1221
+ * @c1: segment end color.
1222
+ * @user_data: user data passed to hb_paint_sweep_gradient_tiles().
1223
+ *
1224
+ * Callback invoked once per (a0, a1) sector of a sweep
1225
+ * gradient tiling. See hb_paint_sweep_gradient_tiles().
1226
+ *
1227
+ * Since: 14.2.0
1228
+ **/
1229
+ typedef void (*hb_paint_sweep_gradient_tile_func_t) (float a0,
1230
+ hb_color_t c0,
1231
+ float a1,
1232
+ hb_color_t c1,
1233
+ void *user_data);
1234
+
1235
+ HB_EXTERN void
1236
+ hb_paint_sweep_gradient_tiles (hb_color_stop_t *stops,
1237
+ unsigned int n_stops,
1238
+ hb_paint_extend_t extend,
1239
+ float start_angle,
1240
+ float end_angle,
1241
+ hb_paint_sweep_gradient_tile_func_t emit_patch,
1242
+ void *user_data);
1243
+
1244
+
1038
1245
  HB_END_DECLS
1039
1246
 
1040
1247
  #endif /* HB_PAINT_H */
@@ -47,7 +47,7 @@ HB_BEGIN_DECLS
47
47
  *
48
48
  * The minor component of the library version available at compile-time.
49
49
  */
50
- #define HB_VERSION_MINOR 1
50
+ #define HB_VERSION_MINOR 2
51
51
  /**
52
52
  * HB_VERSION_MICRO:
53
53
  *
@@ -60,7 +60,7 @@ HB_BEGIN_DECLS
60
60
  *
61
61
  * A string literal containing the library version available at compile-time.
62
62
  */
63
- #define HB_VERSION_STRING "14.1.0"
63
+ #define HB_VERSION_STRING "14.2.0"
64
64
 
65
65
  /**
66
66
  * HB_VERSION_ATLEAST:
@@ -119,8 +119,21 @@ template <typename T, typename... Args>
119
119
  AlignedUniquePtr<T> MakeUniqueAlignedWithAlloc(AllocPtr alloc, FreePtr free,
120
120
  void* opaque, Args&&... args) {
121
121
  T* ptr = static_cast<T*>(AllocateAlignedBytes(sizeof(T), alloc, opaque));
122
+ if (HWY_UNLIKELY(ptr == nullptr)) {
123
+ return AlignedUniquePtr<T>(nullptr, AlignedDeleter(free, opaque));
124
+ }
125
+ #ifdef HWY_EXCEPTIONS_ENABLED
126
+ try {
127
+ return AlignedUniquePtr<T>(new (ptr) T(std::forward<Args>(args)...),
128
+ AlignedDeleter(free, opaque));
129
+ } catch (...) {
130
+ FreeAlignedBytes(ptr, free, opaque);
131
+ throw;
132
+ }
133
+ #else
122
134
  return AlignedUniquePtr<T>(new (ptr) T(std::forward<Args>(args)...),
123
135
  AlignedDeleter(free, opaque));
136
+ #endif
124
137
  }
125
138
 
126
139
  // Similar to MakeUniqueAlignedWithAlloc but using the default alloc/free
@@ -128,8 +141,21 @@ AlignedUniquePtr<T> MakeUniqueAlignedWithAlloc(AllocPtr alloc, FreePtr free,
128
141
  template <typename T, typename... Args>
129
142
  AlignedUniquePtr<T> MakeUniqueAligned(Args&&... args) {
130
143
  T* ptr = static_cast<T*>(AllocateAlignedBytes(sizeof(T)));
144
+ if (HWY_UNLIKELY(ptr == nullptr)) {
145
+ return AlignedUniquePtr<T>(nullptr, AlignedDeleter());
146
+ }
147
+ #ifdef HWY_EXCEPTIONS_ENABLED
148
+ try {
149
+ return AlignedUniquePtr<T>(new (ptr) T(std::forward<Args>(args)...),
150
+ AlignedDeleter());
151
+ } catch (...) {
152
+ FreeAlignedBytes(ptr, nullptr, nullptr);
153
+ throw;
154
+ }
155
+ #else
131
156
  return AlignedUniquePtr<T>(new (ptr) T(std::forward<Args>(args)...),
132
157
  AlignedDeleter());
158
+ #endif
133
159
  }
134
160
 
135
161
  template <class T>
@@ -147,8 +173,13 @@ struct AlignedAllocator {
147
173
  "AlignedAllocator only supports integer types");
148
174
  static_assert(sizeof(V) <= sizeof(std::size_t),
149
175
  "V n must be smaller or equal size_t to avoid overflow");
176
+ const size_t count = static_cast<std::size_t>(n);
177
+ if (HWY_LIKELY(count != 0) && sizeof(value_type) > SIZE_MAX / count) {
178
+ HWY_ABORT("AlignedAllocator: allocation size overflow "
179
+ "(%zu * %zu exceeds size_t)", count, sizeof(value_type));
180
+ }
150
181
  return static_cast<value_type*>(
151
- AllocateAlignedBytes(static_cast<std::size_t>(n) * sizeof(value_type)));
182
+ AllocateAlignedBytes(count * sizeof(value_type)));
152
183
  }
153
184
 
154
185
  template <class V>
@@ -208,7 +239,7 @@ AlignedUniquePtr<T[]> MakeUniqueAlignedArrayWithAlloc(
208
239
  T* ptr = detail::AllocateAlignedItems<T>(items, alloc, opaque);
209
240
  if (ptr != nullptr) {
210
241
  for (size_t i = 0; i < items; i++) {
211
- new (ptr + i) T(std::forward<Args>(args)...);
242
+ new (ptr + i) T(args...);
212
243
  }
213
244
  }
214
245
  return AlignedUniquePtr<T[]>(ptr, AlignedDeleter(free, opaque));
@@ -399,6 +430,10 @@ class AlignedNDArray {
399
430
  size_t offset = 0;
400
431
  size_t shape_index = 0;
401
432
  for (const size_t axis_index : indices) {
433
+ if (HWY_UNLIKELY(axis_index >= shape_[shape_index])) {
434
+ HWY_ABORT("AlignedNDArray index %zu out of bounds (axis %zu, size %zu)",
435
+ axis_index, shape_index, shape_[shape_index]);
436
+ }
402
437
  offset += memory_sizes_[shape_index + 1] * axis_index;
403
438
  shape_index++;
404
439
  }
@@ -417,6 +452,13 @@ class AlignedNDArray {
417
452
  sizes[axis] = 1;
418
453
  while (axis > 0) {
419
454
  --axis;
455
+ // Check for integer overflow in dimension multiplication.
456
+ if (HWY_LIKELY(shape[axis] != 0) &&
457
+ sizes[axis + 1] > SIZE_MAX / shape[axis]) {
458
+ HWY_ABORT("AlignedNDArray: dimension overflow at axis %zu "
459
+ "(%zu * %zu exceeds size_t)",
460
+ axis, sizes[axis + 1], shape[axis]);
461
+ }
420
462
  sizes[axis] = sizes[axis + 1] * shape[axis];
421
463
  }
422
464
  return sizes;
@@ -25,7 +25,18 @@
25
25
 
26
26
  #include "hwy/aligned_allocator.h" // Span
27
27
  #include "hwy/base.h" // HWY_MIN
28
- #include "hwy/contrib/sort/vqsort.h"
28
+
29
+ // configuration to allow auto_tune to use std::sort instead of VQSort
30
+ // (also enabled in header only mode).
31
+ #if defined(HWY_HEADER_ONLY)
32
+ #define HWY_AUTOTUNE_STDSORT
33
+ #endif
34
+
35
+ #ifdef HWY_AUTOTUNE_STDSORT
36
+ #include <algorithm> // std::sort
37
+ #else
38
+ #include "hwy/contrib/sort/vqsort.h" // VQSort
39
+ #endif
29
40
 
30
41
  // Infrastructure for auto-tuning (choosing optimal parameters at runtime).
31
42
 
@@ -104,6 +115,10 @@ class CostDistribution {
104
115
  private:
105
116
  static double Median(double* to_sort, size_t n) {
106
117
  HWY_DASSERT(n >= 2);
118
+
119
+ #ifdef HWY_AUTOTUNE_STDSORT
120
+ std::sort(to_sort, to_sort + n);
121
+ #else
107
122
  // F64 is supported everywhere except Armv7.
108
123
  #if !HWY_ARCH_ARM_V7
109
124
  VQSort(to_sort, n, SortAscending());
@@ -112,6 +127,8 @@ class CostDistribution {
112
127
  // equivalent.
113
128
  VQSort(reinterpret_cast<uint64_t*>(to_sort), n, SortAscending());
114
129
  #endif
130
+ #endif
131
+
115
132
  if (n & 1) return to_sort[n / 2];
116
133
  // Even length: average of two middle elements.
117
134
  return (to_sort[n / 2] + to_sort[n / 2 - 1]) * 0.5;
@@ -405,10 +422,9 @@ class AutoTune {
405
422
  const Config* Best() const { return best_; }
406
423
 
407
424
  // If false, caller must call `SetCandidates` before `NextConfig`.
408
- bool HasCandidates() const {
409
- HWY_DASSERT(!Best());
410
- return !candidates_.empty();
411
- }
425
+ // NOTE: also called after Best() is non-null.
426
+ bool HasCandidates() const { return !candidates_.empty(); }
427
+
412
428
  // WARNING: invalidates `Best()`, do not call if that is non-null.
413
429
  void SetCandidates(std::vector<Config> candidates) {
414
430
  HWY_DASSERT(!Best() && !HasCandidates());
@@ -429,7 +445,7 @@ class AutoTune {
429
445
 
430
446
  // Returns the current `Config` to measure.
431
447
  const Config& NextConfig() const {
432
- HWY_DASSERT(!Best() && HasCandidates());
448
+ HWY_DASSERT(HasCandidates());
433
449
  return candidates_[config_idx_];
434
450
  }
435
451