fix blocksruntime wasm build

This commit is contained in:
Judah Caruso 2026-02-19 23:38:59 -07:00
parent 280688b615
commit 22ee3e232c

View file

@ -8,10 +8,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to permit * distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following * persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -23,10 +23,23 @@
*/ */
#include "Block_private.h" #include "Block_private.h"
#include <stdio.h>
#include <stdlib.h> #ifdef PLATFORM_WASM
#include <string.h> void* malloc(unsigned long s);
void free(void* ptr);
int printf_(const char*, ...);
#define printf printf_
int sprintf(char* restrict, const char* restrict, ...);
#define memmove(a, b, c) __builtin_memmove(a, b, c)
#define exit(a) do { if (a != 0) { __builtin_trap(); } } while (0)
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
#include <stdint.h> #include <stdint.h>
#include <stddef.h>
#include "config.h" #include "config.h"
@ -259,7 +272,7 @@ void _Block_use_GC5( void *(*alloc)(const unsigned long, const bool isOne, const
_Block_use_GC(alloc, setHasRefcount, gc_assign, gc_assign_weak, _Block_memmove_gc_broken); _Block_use_GC(alloc, setHasRefcount, gc_assign, gc_assign_weak, _Block_memmove_gc_broken);
} }
/* /*
* Called from objc-auto to alternatively turn on retain/release. * Called from objc-auto to alternatively turn on retain/release.
* Prior to this the only "object" support we can provide is for those * Prior to this the only "object" support we can provide is for those
@ -286,10 +299,10 @@ static void *_Block_copy_internal(const void *arg, const int flags) {
struct Block_layout *aBlock; struct Block_layout *aBlock;
const bool wantsOne = (WANTS_ONE & flags) == WANTS_ONE; const bool wantsOne = (WANTS_ONE & flags) == WANTS_ONE;
//printf("_Block_copy_internal(%p, %x)\n", arg, flags); //printf("_Block_copy_internal(%p, %x)\n", arg, flags);
if (!arg) return NULL; if (!arg) return NULL;
// The following would be better done as a switch statement // The following would be better done as a switch statement
aBlock = (struct Block_layout *)arg; aBlock = (struct Block_layout *)arg;
if (aBlock->flags & BLOCK_NEEDS_FREE) { if (aBlock->flags & BLOCK_NEEDS_FREE) {
@ -368,7 +381,7 @@ static void *_Block_copy_internal(const void *arg, const int flags) {
static void _Block_byref_assign_copy(void *dest, const void *arg, const int flags) { static void _Block_byref_assign_copy(void *dest, const void *arg, const int flags) {
struct Block_byref **destp = (struct Block_byref **)dest; struct Block_byref **destp = (struct Block_byref **)dest;
struct Block_byref *src = (struct Block_byref *)arg; struct Block_byref *src = (struct Block_byref *)arg;
//printf("_Block_byref_assign_copy called, byref destp %p, src %p, flags %x\n", destp, src, flags); //printf("_Block_byref_assign_copy called, byref destp %p, src %p, flags %x\n", destp, src, flags);
//printf("src dump: %s\n", _Block_byref_dump(src)); //printf("src dump: %s\n", _Block_byref_dump(src));
if (src->forwarding->flags & BLOCK_IS_GC) { if (src->forwarding->flags & BLOCK_IS_GC) {
@ -417,7 +430,7 @@ static void _Block_byref_release(const void *arg) {
// dereference the forwarding pointer since the compiler isn't doing this anymore (ever?) // dereference the forwarding pointer since the compiler isn't doing this anymore (ever?)
shared_struct = shared_struct->forwarding; shared_struct = shared_struct->forwarding;
//printf("_Block_byref_release %p called, flags are %x\n", shared_struct, shared_struct->flags); //printf("_Block_byref_release %p called, flags are %x\n", shared_struct, shared_struct->flags);
// To support C++ destructors under GC we arrange for there to be a finalizer for this // To support C++ destructors under GC we arrange for there to be a finalizer for this
// by using an isa that directs the code to a finalizer that calls the byref_destroy method. // by using an isa that directs the code to a finalizer that calls the byref_destroy method.
@ -519,7 +532,7 @@ unsigned long int Block_size(void *arg) {
#pragma mark Compiler SPI entry points #pragma mark Compiler SPI entry points
#endif /* if 0 */ #endif /* if 0 */
/******************************************************* /*******************************************************
Entry points used by the compiler - the real API! Entry points used by the compiler - the real API!
@ -548,7 +561,7 @@ So the __block copy/dispose helpers will generate flag values of 3 or 7 for obje
__weak block id 128+3+16 __weak block id 128+3+16
__block (^Block) 128+7 __block (^Block) 128+7
__weak __block (^Block) 128+7+16 __weak __block (^Block) 128+7+16
The implementation of the two routines would be improved by switch statements enumerating the eight cases. The implementation of the two routines would be improved by switch statements enumerating the eight cases.
********************************************************/ ********************************************************/
@ -697,4 +710,3 @@ const char *_Block_byref_dump(struct Block_byref *src) {
} }
return buffer; return buffer;
} }