Skip to content

Commit 06b6268

Browse files
committed
[embedded] Implement more refcounting in the arrays test
1 parent efd8f08 commit 06b6268

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

test/embedded/Inputs/tiny-runtime-dummy-refcounting.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <stdlib.h>
44
#include <stdbool.h>
55

6-
size_t _swiftEmptyArrayStorage[] = { /*isa*/0, /*refcount*/0, /*count*/0, /*flags*/1 };
6+
size_t _swiftEmptyArrayStorage[] = { /*isa*/0, /*refcount*/-1, /*count*/0, /*flags*/1 };
77

88
typedef struct HeapObject {
99
void *metadata;
@@ -21,12 +21,12 @@ void *swift_allocObject(void *metadata, size_t requiredSize, size_t requiredAlig
2121
}
2222

2323
void swift_deallocClassInstance(HeapObject *object, size_t allocatedSize, size_t allocatedAlignMask) {
24-
// don't deallocate ¯\_(ツ)_/¯
24+
free(object);
2525
}
2626

2727
HeapObject *swift_initStackObject(void *metadata, HeapObject *object) {
2828
object->metadata = metadata;
29-
object->refcount = 1;
29+
object->refcount = -1;
3030
return object;
3131
}
3232

@@ -35,17 +35,17 @@ bool swift_isUniquelyReferenced_nonNull_native(HeapObject *object) {
3535
}
3636

3737
void swift_release(HeapObject *object) {
38-
// don't release ¯\_(ツ)_/¯
38+
if (object->refcount == -1) return;
39+
40+
object->refcount -= 1;
41+
if (object->refcount == 0) {
42+
free(object);
43+
}
3944
}
4045

4146
HeapObject *swift_retain(HeapObject *object) {
47+
if (object->refcount == -1) return object;
48+
4249
object->refcount += 1;
4350
return object;
4451
}
45-
46-
void swift_setDeallocating(HeapObject *object) {
47-
// don't deallocate ¯\_(ツ)_/¯
48-
}
49-
50-
void swift_beginAccess(void *pointer, void *buffer, uintptr_t flags, void *pc) { }
51-
void swift_endAccess(void *buffer) { }

0 commit comments

Comments
 (0)