Skip to content

Commit 5c35863

Browse files
authored
Rename __zipos_free -> __zipos_drop (#1043)
Removes the separate decref function, uses keep/drop in the internal API.
1 parent fd772b9 commit 5c35863

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

libc/runtime/zipos-close.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int __zipos_close(int fd) {
3939
if (!__vforked) {
4040
struct ZiposHandle *h;
4141
h = (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle;
42-
__zipos_free(h);
42+
__zipos_drop(h);
4343
}
4444
return rc;
4545
}

libc/runtime/zipos-open.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,11 @@ struct ZiposHandle *__zipos_keep(struct ZiposHandle *h) {
8888
return h;
8989
}
9090

91-
static bool __zipos_drop(struct ZiposHandle *h) {
92-
if (!atomic_fetch_sub_explicit(&h->refs, 1, memory_order_release)) {
93-
atomic_thread_fence(memory_order_acquire);
94-
return true;
95-
}
96-
return false;
97-
}
98-
99-
void __zipos_free(struct ZiposHandle *h) {
100-
if (!__zipos_drop(h)) {
91+
void __zipos_drop(struct ZiposHandle *h) {
92+
if (atomic_fetch_sub_explicit(&h->refs, 1, memory_order_release)) {
10193
return;
10294
}
95+
atomic_thread_fence(memory_order_acquire);
10396
if (IsAsan()) {
10497
__asan_poison((char *)h + sizeof(struct ZiposHandle),
10598
h->mapsize - sizeof(struct ZiposHandle), kAsanHeapFree);
@@ -227,7 +220,7 @@ static int __zipos_load(struct Zipos *zipos, size_t cf, int flags,
227220
}
228221
__fds_unlock();
229222
}
230-
__zipos_free(h);
223+
__zipos_drop(h);
231224
return -1;
232225
}
233226

@@ -238,7 +231,7 @@ void __zipos_postdup(int oldfd, int newfd) {
238231
BLOCK_SIGNALS;
239232
__fds_lock();
240233
if (__isfdkind(newfd, kFdZip)) {
241-
__zipos_free((struct ZiposHandle *)(intptr_t)g_fds.p[newfd].handle);
234+
__zipos_drop((struct ZiposHandle *)(intptr_t)g_fds.p[newfd].handle);
242235
if (!__isfdkind(oldfd, kFdZip)) {
243236
bzero(g_fds.p + newfd, sizeof(*g_fds.p));
244237
}

libc/runtime/zipos.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
.yoink __zipos_mmap
3636
.yoink __zipos_postdup
3737
.yoink __zipos_keep
38-
.yoink __zipos_free
38+
.yoink __zipos_drop
3939

4040
// TODO(jart): why does corruption happen when zip has no assets?
4141
.yoink .cosmo

libc/runtime/zipos.internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct Zipos {
3838
};
3939

4040
int __zipos_close(int);
41-
void __zipos_free(struct ZiposHandle *);
41+
void __zipos_drop(struct ZiposHandle *);
4242
struct ZiposHandle *__zipos_keep(struct ZiposHandle *);
4343
struct Zipos *__zipos_get(void) pureconst;
4444
size_t __zipos_normpath(char *, const char *, size_t);

0 commit comments

Comments
 (0)