1
+ #include " rust_box.h"
1
2
#include " rust_gc.h"
2
3
#include " rust_internal.h"
3
4
#include " rust_unwind.h"
@@ -76,6 +77,25 @@ upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) {
76
77
return (uintptr_t ) p;
77
78
}
78
79
80
+ extern " C" CDECL rust_box *
81
+ upcall_malloc_box (rust_task *task, size_t nbytes, type_desc *td) {
82
+ LOG_UPCALL_ENTRY (task);
83
+
84
+ gc::maybe_gc (task);
85
+
86
+ rust_box *box = reinterpret_cast <rust_box *>
87
+ (task->malloc (nbytes + sizeof (rust_box), " tdesc" , td));
88
+ box->ref_count = 1 ;
89
+ box->tydesc = td;
90
+
91
+ box->gc_prev = NULL ;
92
+ if ((box->gc_next = task->gc_alloc_chain ) != NULL )
93
+ box->gc_next ->gc_prev = box;
94
+ task->gc_alloc_chain = box;
95
+
96
+ return box;
97
+ }
98
+
79
99
/* *
80
100
* Called whenever an object's ref count drops to zero.
81
101
*/
@@ -90,6 +110,24 @@ upcall_free(rust_task *task, void* ptr, uintptr_t is_gc) {
90
110
task->free (ptr, (bool ) is_gc);
91
111
}
92
112
113
+ extern " C" CDECL void
114
+ upcall_free_box (rust_task *task, rust_box *box) {
115
+ LOG_UPCALL_ENTRY (task);
116
+
117
+ assert (!box->ref_count && " Box reference count is nonzero on free!" );
118
+
119
+ if (box->gc_prev )
120
+ box->gc_prev ->gc_next = box->gc_next ;
121
+ else
122
+ task->gc_alloc_chain = box->gc_next ;
123
+ if (box->gc_next )
124
+ box->gc_next ->gc_prev = box->gc_prev ;
125
+
126
+ box->tydesc ->drop_glue (NULL , task, (void *)box->tydesc ,
127
+ box->tydesc ->first_param , box->data );
128
+ task->free (box, false );
129
+ }
130
+
93
131
extern " C" CDECL uintptr_t
94
132
upcall_shared_malloc (rust_task *task, size_t nbytes, type_desc *td) {
95
133
LOG_UPCALL_ENTRY (task);
0 commit comments