4 /* If a runtime function needs to call another function which potentially
5 allocates memory, it must wrap any local variable references to Factor
6 objects in gc_root instances */
7 extern std::vector<cell> gc_locals;
10 struct gc_root : public tagged<T>
12 void push() { check_tagged_pointer(tagged<T>::value()); gc_locals.push_back((cell)this); }
14 explicit gc_root(cell value_) : tagged<T>(value_) { push(); }
15 explicit gc_root(T *value_) : tagged<T>(value_) { push(); }
17 const gc_root<T>& operator=(const T *x) { tagged<T>::operator=(x); return *this; }
18 const gc_root<T>& operator=(const cell &x) { tagged<T>::operator=(x); return *this; }
22 assert(gc_locals.back() == (cell)this);
28 /* A similar hack for the bignum implementation */
29 extern std::vector<cell> gc_bignums;
35 gc_bignum(bignum **addr_) : addr(addr_) {
37 check_data_pointer(*addr_);
38 gc_bignums.push_back((cell)addr);
43 assert(gc_bignums.back() == (cell)addr);
45 gc_bignums.pop_back();
49 #define GC_BIGNUM(x) gc_bignum x##__gc_root(&x)