GC_PTR GC_local_malloc_atomic(size_t bytes) { if (EXPECT(!SMALL_ENOUGH(bytes), 0)) { return(GC_malloc_atomic(bytes)); } else { int index = INDEX_FROM_BYTES(bytes); ptr_t * my_fl = ((GC_thread)GC_getspecific(GC_thread_key)) -> ptrfree_freelists + index; ptr_t my_entry = *my_fl; if (EXPECT((word)my_entry >= HBLKSIZE, 1)) { GC_PTR result = (GC_PTR)my_entry; *my_fl = obj_link(my_entry); return result; } else if ((word)my_entry - 1 < DIRECT_GRANULES) { *my_fl = my_entry + index + 1; return GC_malloc_atomic(bytes); } else { GC_generic_malloc_many(BYTES_FROM_INDEX(index), PTRFREE, my_fl); /* *my_fl is updated while the collector is excluded; */ /* the free list is always visible to the collector as */ /* such. */ if (*my_fl == 0) return GC_oom_fn(bytes); return GC_local_malloc_atomic(bytes); } } }
bool sym_file::init() { // open the file. if (!open()) return false; // read the header. should make sure it is a valid .xSYM file, etc. DiskSymbolHeaderBlock& header = mHeader; long count = sizeof(header); if (::FSRead(mFileRef, (long*) &count, &header) != noErr || count != sizeof(header)) return false; // read the name table. // mNameTable = new UInt8*[header.dshb_nte.dti_page_count]; mNameTable = (UInt8**) GC_malloc_ignore_off_page(header.dshb_nte.dti_page_count * sizeof(UInt8*)); if (mNameTable == NULL) return false; // seek to first page of the name table. ::SetFPos(mFileRef, fsFromStart, header.dshb_nte.dti_first_page * header.dshb_page_size); // read all of the pages into memory, for speed. for (int i = 0; i < header.dshb_nte.dti_page_count; i++) { // allocate each page atomically, so GC won't have to scan them. UInt8* page = mNameTable[i] = (UInt8*) GC_malloc_atomic(header.dshb_page_size); if (page == NULL) return false; count = header.dshb_page_size; if (::FSRead(mFileRef, &count, page) != noErr || count != header.dshb_page_size) return false; } // allocate the page buffer and initialize offsets. // mPageBuffer = (UInt8*) new UInt8[header.dshb_page_size]; mPageBuffer = (UInt8*) GC_malloc_atomic(header.dshb_page_size); // read the RTE tables. seek(header.dshb_rte.dti_first_page * header.dshb_page_size + sizeof(ResourceTableEntry)); for (int i = 1; i <= header.dshb_rte.dti_object_count; i++) { ResourceTableEntry resEntry; if (read(&resEntry, sizeof(resEntry)) == sizeof(resEntry)) { switch (resEntry.rte_ResType) { case 'CODE': mCodeEntry = resEntry; break; case 'DATA': break; } } } return true; }
const char * SimpleString::copy_to_c_string() const { char * s = (char *) GC_malloc_atomic(_capacity + 1); memcpy(s, _chars, _capacity); s[_capacity] = 0; return s; }
char * lc2c(longchar * x, int len) { static char y[100]; int i = 0, j = 0; char *r; while (x[j].type != RE_TYPE_END && j < len) { if (x[j].type == RE_WHICH_RANGE) y[i++] = '-'; #ifdef USE_M17N else if (x[j].type == RE_TYPE_WCHAR_T) { char buf[20]; sprintf(buf, "[%x-%x]", x[j].wch.ccs, x[j].wch.code); strcpy(&y[i], buf); i += strlen(buf); } #endif else y[i++] = x[j].ch; j++; } y[i] = '\0'; r = GC_malloc_atomic(i + 1); strcpy(r, y); return r; }
ParamPaths__Path ParamPaths__ParsePatterns_PathList_NewPath(unsigned char* str, int str_0d) { register int i0, i1, i2; { char *_mem, *_var; _mem = GC_malloc(_not_zero(8)+8); if (!_mem) _new_failed(_P(6224)); _var = _mem+8; ((_Type*)_var)[-1] = &ParamPaths__PathDesc_td.td; i0 = (int)_var; } i2 = Strings__Length((const unsigned char*)(int)str, str_0d); i1 = i0 + 4; i2++; { char *_mem, *_var; int* _dim_ptr; if(i2 < 0) _invalid_length(i2, _P(6281)); _mem = GC_malloc_atomic(_not_zero(i2*1)+8); if (!_mem) _new_failed(_P(6244)); _var = _mem+8; _dim_ptr = (void*)(_var-4); *(--_dim_ptr) = i2; i2 = (int)_var; } *(void**)i1 = (void*)i2; i1 = (int)*(void**)i1; i2 = *(int*)(i1-8); _string_copy(i1, (int)str, i2); *(void**)i0 = (void*)0; return (void*)i0; }
void GLnormal3d(gl_vertex *v, double x, double y, double z) { vecteur3d p = (vecteur3d) GC_malloc_atomic(sizeof(vecteur3d_cell)); p->x = x; p->y = y; p->z = z; v->normal_type = GL_DOUBLE; v->normal.a3d = p; }
void GLnormal3f(gl_vertex *v, float x, float y, float z) { vecteur3f p = (vecteur3f) GC_malloc_atomic(sizeof(vecteur3f_cell)); p->x = x; p->y = y; p->z = z; v->normal_type = GL_FLOAT; v->normal.a3f = p; }
void *talloc_atomic__(size_t size, const char *filename, int linenumber){ void *ret; //return GC_malloc_atomic(size); ret=tracker_alloc__(size,GC_malloc_atomic, filename, linenumber); if(ret!=NULL) return ret; #if 0 if(tmemoryisused==0){ tmemoryisused=1; GC_free(tmemory); tmemory=NULL; } # ifndef DISABLE_BDWGC ret=GC_malloc_atomic(size); # else ret=OS_getmem(size); // For debugging. (wrong use of GC_malloced memory could be very difficult to trace) # endif #endif RWarning("Out of memory. I'll try to continue by allocating a different way, but you should save and quit now.\n"); ret = calloc(1,size); if(ret!=NULL) return ret; RWarning("Out of memory. Quitting\n"); ShutDownYepp(); return NULL; }
void * (cu_gallocz_atomic)(size_t size) { void *p = GC_malloc_atomic(size); if (!p) cu_raise_out_of_memory(size); memset(p, 0, size); return p; }
GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_atomic(size_t lb, GC_EXTRA_PARAMS) { void * result = GC_malloc_atomic(SIZET_SAT_ADD(lb, DEBUG_BYTES)); return store_debug_info(result, lb, "GC_debug_malloc_atomic", OPT_RA s, i); }
TreeNode* alloc_integer_node(int64_t xx) { TreeNode* tn = alloc_tree_node(INTEGER_TYPE); tn->data = GC_malloc_atomic(sizeof(int64_t)); *((int64_t*)tn->data) = xx; return tn; }
void * objc_atomic_malloc (size_t size) { void *res = (void *)(GC_malloc_atomic (size)); if (! res) _objc_abort ("Virtual memory exhausted\n"); return res; }
static void* allocate(std::size_t n, norefs_tag) { IMMER_GC_INIT_GUARD_; auto p = GC_malloc_atomic(n); if (IMMER_UNLIKELY(!p)) throw std::bad_alloc{}; return p; }
char* lstrdup(const char* aa) { size_t size = strlen(aa) + 1; char* bb = (char*) GC_malloc_atomic(size); strlcpy(bb, aa, size); return bb; }
TreeNode* alloc_float_node(double xx) { TreeNode* tn = alloc_tree_node(FLOAT_TYPE); tn->data = GC_malloc_atomic(sizeof(double)); *((double*)tn->data) = xx; return tn; }
AbstractVector * SimpleString::adjust_vector(INDEX new_capacity, Value initial_element, Value initial_contents) { if (initial_contents != NIL) { BASE_CHAR * new_chars = (BASE_CHAR *) GC_malloc_atomic(new_capacity + 1); if (listp(initial_contents)) { Value list = initial_contents; for (unsigned long i = 0; i < new_capacity; i++) { new_chars[i] = char_value(car(list)); list = xcdr(list); } } else if (vectorp(initial_contents)) { AbstractVector * v = the_vector(initial_contents); for (unsigned long i = 0; i < new_capacity; i++) new_chars[i] = char_value(v->aref(i)); } else signal_type_error(initial_contents, S_sequence); new_chars[new_capacity] = 0; return new_simple_string(new_capacity, new_chars); } if (_capacity != new_capacity) { BASE_CHAR * new_chars = (BASE_CHAR *) GC_malloc_atomic(new_capacity + 1); unsigned long limit = (_capacity < new_capacity) ? _capacity : new_capacity; for (unsigned long i = 0; i < limit; i++) new_chars[i] = _chars[i]; if (_capacity < new_capacity) { BASE_CHAR c = char_value(initial_element); for (unsigned long i = _capacity; i < new_capacity; i++) new_chars[i] = c; } new_chars[new_capacity] = 0; return new_simple_string(new_capacity, new_chars); } // No change. return this; }
static oop newString(char *cstr) { size_t len= strlen(cstr) + 1; char *gstr= GC_malloc_atomic(len); memcpy(gstr, cstr, len); GC_PROTECT(gstr); oop obj= newOops(String); set(obj, String,bits, gstr); GC_UNPROTECT(gstr); return obj; }
// FIXME enforce array-dimension-limit // FIXME not thread-safe void Vector_UB32::ensure_capacity(INDEX n) { if (_data) { if (_capacity < n) { // FIXME check for overflow INDEX new_capacity = _capacity * 2; if (new_capacity < n) new_capacity = n; unsigned int * new_data = (unsigned int *) GC_malloc_atomic(new_capacity * sizeof(unsigned int)); INDEX i; INDEX limit = length(); for (i = 0; i < limit; i++) new_data[i] = _data[i]; while (i < new_capacity) new_data[i++] = 0; _data = new_data; _capacity = new_capacity; } } else { // displaced if (_capacity < n || _array->total_size() - _offset < n) { // copy array // FIXME check for overflow INDEX new_capacity = _capacity * 2; if (new_capacity < n) new_capacity = n; _data = (unsigned int *) GC_malloc_atomic(new_capacity * sizeof(unsigned int)); INDEX limit = _capacity; if (limit > _array->total_size() - _offset) limit = _array->total_size() - _offset; for (INDEX i = 0; i < limit; i++) aset(i, _array->aref(i + _offset)); _capacity = new_capacity; _array = NULL; _offset = 0; } } }
void * GC_AllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear ) { if (ptrFree) { void * result = (void *)GC_malloc_atomic(size); if (clear && result != 0) BZERO(result, size); return(result); } else { return((void *)GC_malloc(size)); } }
/* Caller does not hold allocation lock. */ STATIC signed_word GC_add_ext_descriptor(const word * bm, word nbits) { size_t nwords = divWORDSZ(nbits + WORDSZ-1); signed_word result; size_t i; word last_part; size_t extra_bits; DCL_LOCK_STATE; LOCK(); while (GC_avail_descr + nwords >= GC_ed_size) { ext_descr * newExtD; size_t new_size; word ed_size = GC_ed_size; if (ed_size == 0) { GC_ASSERT((word)(&GC_ext_descriptors) % sizeof(word) == 0); GC_push_typed_structures = GC_push_typed_structures_proc; UNLOCK(); new_size = ED_INITIAL_SIZE; } else { UNLOCK(); new_size = 2 * ed_size; if (new_size > MAX_ENV) return(-1); } newExtD = (ext_descr *)GC_malloc_atomic(new_size * sizeof(ext_descr)); if (NULL == newExtD) return -1; LOCK(); if (ed_size == GC_ed_size) { if (GC_avail_descr != 0) { BCOPY(GC_ext_descriptors, newExtD, GC_avail_descr * sizeof(ext_descr)); } GC_ed_size = new_size; GC_ext_descriptors = newExtD; } /* else another thread already resized it in the meantime */ } result = GC_avail_descr; for (i = 0; i < nwords-1; i++) { GC_ext_descriptors[result + i].ed_bitmap = bm[i]; GC_ext_descriptors[result + i].ed_continued = TRUE; } last_part = bm[i]; /* Clear irrelevant bits. */ extra_bits = nwords * WORDSZ - nbits; last_part <<= extra_bits; last_part >>= extra_bits; GC_ext_descriptors[result + i].ed_bitmap = last_part; GC_ext_descriptors[result + i].ed_continued = FALSE; GC_avail_descr += nwords; UNLOCK(); return(result); }
inline void resize_samples_vector() { INDEX new_size = samples_size * 2; INDEX * new_samples = (INDEX *) GC_malloc_atomic(new_size * sizeof(unsigned long *)); for (INDEX i = 0; i < samples_size; i++) new_samples[i] = samples[i]; for (INDEX i = samples_size; i < new_size; i++) new_samples[i] = 0; samples = new_samples; samples_size = new_size; }
static void cache_put(const char* data, size_t size, const char* hash) { int nn = cache_next; cache[nn].size = size; cache[nn].data = GC_malloc_atomic(size); memcpy(cache[nn].data, data, size); cache[nn].hash = lstrdup(hash); cache_next = (nn + 1) % MAX_CACHE_SIZE; }
char* lstrcat(const char* aa, const char* bb) { size_t size = strlen(aa) + strlen(bb) + 1; char* cc = (char*) GC_malloc_atomic(size); cc[0] = 0; strlcat(cc, aa, size); strlcat(cc, bb, size); return cc; }
static int directory_load(module_t *Module, const char *FileName) { DWORD FileAttributes = GetFileAttributes(FileName); if (FileAttributes & FILE_ATTRIBUTE_DIRECTORY) { int Length = strlen(FileName); char *Path = GC_malloc_atomic(Length + 2); strcpy(Path, FileName); Path[Length] = '\\'; Path[Length + 1] = 0; module_setup(Module, Path, (module_importer)directory_import); } else { return 0; }; };
gl_vertex* GLvertex3d(double x, double y,double z) { gl_vertex* v = (gl_vertex*) GC_malloc(sizeof(gl_vertex)); point3d p = (point3d) GC_malloc_atomic(sizeof(point3d_cell)); p->x = x; p->y = y; p->z = z; v->vertex_type = GL_DOUBLE; v->normal_type = 0; v->dim = 3; v->coord.a3d = p; v->normal.raw = NULL; return v; }
gl_vertex* GLvertex2d(double x, double y) { gl_vertex* v = (gl_vertex*) GC_malloc(sizeof(gl_vertex)); point2d p = (point2d) GC_malloc_atomic(sizeof(point2d_cell)); p->x = x; p->y = y; v->vertex_type = GL_DOUBLE; v->normal_type = 0; v->dim = 2; v->coord.a2d = p; v->normal.raw = NULL; return v; }
gl_vertex* GLvertex3f(float x, float y,float z) { gl_vertex* v = (gl_vertex*) GC_malloc(sizeof(gl_vertex)); point3f p = (point3f) GC_malloc_atomic(sizeof(point3f_cell)); p->x = x; p->y = y; p->z = z; v->vertex_type = GL_FLOAT; v->normal_type = 0; v->dim = 3; v->coord.a3f = p; v->normal.raw = NULL; return v; }
gl_vertex* GLvertex2f(float x, float y) { gl_vertex* v = (gl_vertex*) GC_malloc(sizeof(gl_vertex)); point2f p = (point2f) GC_malloc_atomic(sizeof(point2f_cell)); p->x = x; p->y = y; v->vertex_type = GL_FLOAT; v->normal_type = 0; v->dim = 2; v->coord.a2f = p; v->normal.raw = NULL; return v; }
unsigned long Array_T::set_initial_contents(unsigned long axis, unsigned long rank, unsigned long dims[], Value contents, unsigned long index) { if (rank == 0) { if (index < _total_size) _data[index] = contents; else { signal_lisp_error("Bad initial contents for array."); // not reached return 0; } ++index; } else { unsigned long dim = dims[0]; if (dim != length(contents)) { signal_lisp_error("Bad initial contents for array."); // Not reached. return 0; } unsigned long * new_dims = (unsigned long *) GC_malloc_atomic((rank - 1) * sizeof(unsigned long)); for (unsigned long i = 1; i < rank; i++) new_dims[i - 1] = dims[i]; if (listp(contents)) { for (unsigned long i = length(contents); i-- > 0;) { Value content = car(contents); index = set_initial_contents(axis + 1, rank - 1, new_dims, content, index); contents = xcdr(contents); } } else { AbstractVector * v = check_vector(contents); const unsigned long length = v->length(); for (unsigned long i = 0; i < length; i++) { Value content = v->aref(i); index = set_initial_contents(axis + 1, rank - 1, new_dims, content, index); } } } return index; }
char* lsubstr(const char* ss, int offset, int length) { char* yy = GC_malloc_atomic(length + 1); int ii; for (ii = 0; ii < length; ++ii) { yy[ii] = ss[ii + offset]; } yy[length] = 0; return yy; }