On Wed Oct 29 00:52:56 2025 +0000, Jacek Caban wrote:
As I said, some use of macros is fine, but I think some of the code that uses them doesn’t really need to. I’d need to try it myself to be sure, but I imagine we could have something like: ``` static double get_u8(const void *p) { return *(const UINT8 *)p; } static void set_u8(void *p, double v) { *(UINT8 *)p = double_to_int32(v); } static const ... Uint8Array_type = { .size = sizeof(UINT8), .get = get_u8, .set = set_u8 }; ``` Then, instead of passing the class id around, you could pass the type descriptor with `&name##_type`. We could do something similar for the remaining ones, like `prop_put` and `prop_get`. All conversions go through `to_number`, and that’s the annoying part since it may fail. We could just call it in the common code and let the per-type functions handle conversion to and from double. If you passed such a descriptor to `fill_typedarr_data_from_object` instead of the class id, you wouldn’t need the macro or the switch at all. While using the class id is possible, it seems inconvenient, so I’d be tempted to bend the abstraction slightly and store the array type descriptor pointer in `builtin_info_t` itself. `isView` could simply check whether it’s non-null, and “this” validation could use that instead of the id. I’m not entirely sure though, maybe that part (or more of above) is not worth it. So I tried a bunch of things and went with a compromise of sorts, still using only an `ALL_TYPED_ARRAYS` macro as suggested though. But now I'm passing "desc indices" around since I'm keeping the typed array descs into an array, which enables both looking it up and creating them by looping, and can also compute the class from them (needed in e.g. `TypedArray_get_byteLength`).
I didn't like the idea of extending `builtin_info_t` just for typed arrays, I think bleeding such object-specific entries outside arraybuf.c is not worth the complication. Also, isView should also work for DataView and those wouldn't have a desc in there. Note that I still generate some functions via the macros, but those functions are just forwards to the underlying implementations, we just need to pass the desc idx so they know which type of array it is supposed to be. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9275#note_120034