IPAddress *IPAddress_new(void) { IPAddress *self = io_calloc(1, sizeof(IPAddress)); self->sockaddr = io_calloc(1, sizeof(struct sockaddr_in)); self->size = sizeof(struct sockaddr_in); return self; }
IoObject *IoObject_justAlloc(IoState *state) { IoObject *child = Collector_newMarker(state->collector); CollectorMarker_setObject_(child, io_calloc(1, sizeof(IoObjectData))); IoObject_protos_(child, (IoObject **)io_calloc(2, sizeof(IoObject *))); return child; }
IPAddress *IPAddress_new(void) { IPAddress *self = io_calloc(1, sizeof(IPAddress)); self->sockaddr = io_calloc(1, sizeof(struct sockaddr_in)); self->size = sizeof(struct sockaddr_in); self->addr = Address_newWithIPAddress(self); IPAddress_setIp_(self, "0.0.0.0"); return self; }
IoLexer *IoLexer_new(void) { IoLexer *self = (IoLexer *)io_calloc(1, sizeof(IoLexer)); self->s = (char *)io_calloc(1, 1); self->s[0] = 0; self->posStack = Stack_new(); self->tokenStack = Stack_new(); self->tokenStream = List_new(); self->charLineIndex = List_new(); return self; }
Stack *Stack_new(void) { // size is the number of pointers, including the starting NULL. int size = STACK_START_SIZE; Stack *self = (Stack *)io_calloc(1, sizeof(Stack)); self->items = (void **)io_calloc(1, size*sizeof(void *)); // memEnd points past the end of the items memory block. self->memEnd = self->items + size; self->top = self->items; //self->lastMark = self->items; return self; }
BStream *BStream_new(void) { int flipEndian; BStream *self = (BStream *)io_calloc(1, sizeof(BStream)); self->ba = UArray_new(); self->index = 0; self->ownsUArray = 1; self->tmp = UArray_new(); self->errorBa = UArray_new(); flipEndian = 0; self->typeBuf = (unsigned char *)io_calloc(1, 512); return self; }
intptr_t marshal(IoDynLib *self, IoObject *arg) { intptr_t n = 0; if (ISNUMBER(arg)) { n = IoNumber_asInt(arg); } else if (ISSYMBOL(arg)) { n = (intptr_t)CSTRING(arg); } else if (ISLIST(arg)) { int i; intptr_t *l = io_calloc(1, IoList_rawSize(arg) * sizeof(intptr_t)); for (i = 0; i < IoList_rawSize(arg); i ++) l[i] = marshal(self, List_rawAt_(IoList_rawList(arg), i)); n = (intptr_t)l; } else if (ISBUFFER(arg)) { n = (intptr_t)IoSeq_rawBytes(arg); } else if (ISBLOCK(arg)) { unsigned char *blk = io_calloc(1, 20), *p = blk; // FIXME: need trampoline code for other architectures *p++ = 0x68; *((intptr_t *)p) = (intptr_t)arg; p += sizeof(intptr_t); *p++ = 0xb8; *((intptr_t *)p) = (intptr_t)bouncer; p += sizeof(intptr_t); *p++ = 0xff; *p++ = 0xd0; *p++ = 0x83; *p++ = 0xc4; *p++ = 0x04; *p++ = 0xc3; n = (intptr_t)blk; } else { n = (intptr_t)arg; //IONIL(self); } return n; }
UArray *UArray_newWithData_type_size_copy_(void *bytes, CTYPE type, size_t size, int copy) { UArray *self = (UArray *)io_calloc(1, sizeof(UArray)); UArray_setData_type_size_copy_(self, bytes, type, size, copy); self->encoding = CENCODING_ASCII; return self; }
Collector *Collector_new(void) { Collector *self = (Collector *)io_calloc(1, sizeof(Collector)); self->retainedValues = List_new(); self->whites = CollectorMarker_new(); self->grays = CollectorMarker_new(); self->blacks = CollectorMarker_new(); self->freed = CollectorMarker_new(); CollectorMarker_loop(self->whites); CollectorMarker_removeIfNeededAndInsertAfter_(self->grays, self->whites); CollectorMarker_removeIfNeededAndInsertAfter_(self->blacks, self->grays); CollectorMarker_removeIfNeededAndInsertAfter_(self->freed, self->blacks); // important to set colors *after* inserts, since inserts set colors CollectorMarker_setColor_(self->whites, COLLECTOR_INITIAL_WHITE); CollectorMarker_setColor_(self->blacks, COLLECTOR_INITIAL_BLACK); CollectorMarker_setColor_(self->grays, COLLECTOR_GRAY); CollectorMarker_setColor_(self->freed, COLLECTOR_FREE); Collector_setSafeModeOn_(self, 1); self->allocated = 0; self->allocatedSweepLevel = 3000; self->allocatedStep = 1.1f; self->marksPerAlloc = 2; self->clocksUsed = 0; Collector_check(self); return self; }
int CHash_resizeTo_(CHash *self, size_t newSize) { unsigned char *oldRecords = self->records; size_t oldSize = self->size; self->isResizing = 1; //printf("%p resizeTo %i/%i %i%%\n", (void *)self, self->keyCount, self->size, (int)(100.0*CHash_density(self))); do { self->size = newSize; self->records = io_calloc(1, sizeof(CHashRecord) * self->size); self->keyCount = 0; CHash_updateMask(self); if(CHash_insertRecords(self, oldRecords, oldSize) == 0) { self->isResizing = 0; } else { //printf("%p grow collision %i/%i\n", (void *)self, self->keyCount, self->size); newSize *= 2; io_free(self->records); } } while(self->isResizing); io_free(oldRecords); return 0; }
Levels *Levels_new(IoMessage *msg) { Levels *self = io_calloc(1, sizeof(Levels)); IoState *state = IoObject_state(msg); IoSymbol *operatorTableSymbol = IoState_symbolWithCString_(state, "OperatorTable"); // Be ultra flexable, and try to use the first message's operator table. IoObject *opTable = IoObject_rawGetSlot_(msg, operatorTableSymbol); // Otherwise, use Core OperatorTable, and if that doesn't exist, create it. if (opTable == NULL) { // There is a chance the message didn't have it, but the core did---due // to the Core not being part of the message's protos. Use Core // Message's OperatorTable opTable = IoObject_rawGetSlot_(state->core, operatorTableSymbol); // If Core doesn't have an OperatorTable, then create it. if (opTable == NULL) { opTable = IoObject_new(state); IoObject_setSlot_to_(state->core, operatorTableSymbol, opTable); IoObject_setSlot_to_(opTable, IoState_symbolWithCString_(state, "precedenceLevelCount"), IoState_numberWithDouble_(state, IO_OP_MAX_LEVEL)); } } self->operatorTable = getOpTable(opTable, "operators", IoState_createOperatorTable); self->assignOperatorTable = getOpTable(opTable, "assignOperators", IoState_createAssignOperatorTable); self->stack = List_new(); Levels_reset(self); return self; }
IoDynLib *IoDynLib_callPluginInitFunc(IoDynLib *self, IoObject *locals, IoMessage *m) { /*doc DynLib callPluginInit(functionName) Call's the dll function of the specified name. Returns the result as a Number or raises an exception on error. */ intptr_t rc = 0; intptr_t *params = NULL; void *f = DynLib_pointerForSymbolName_(DATA(self), CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0))); if (f == NULL) { IoState_error_(IOSTATE, m, "Error resolving call '%s'.", CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0))); return IONIL(self); } if (IoMessage_argCount(m) < 1) { IoState_error_(IOSTATE, m, "Error, you must give an init function name to check for."); return IONIL(self); } params = io_calloc(1, sizeof(intptr_t) * 2); params[0] = (intptr_t)IOSTATE; params[1] = (intptr_t)IOSTATE->lobby; rc = ((intptr_t (*)(intptr_t, intptr_t))f)(params[0], params[1]); io_free(params); return IONUMBER(rc); }
static void setenv(const char *varName, const char* value, int force) { const char *safeValue; char *buf; if (!varName) { return; } if (!value) { safeValue = ""; } else { safeValue = value; } // buffer for var and value plus '=' and the \0 buf = (char*)io_calloc(1, strlen(varName) + strlen(safeValue) + 2); if (!buf) { return; } strcpy(buf, varName); strcat(buf, "="); strcat(buf, safeValue); _putenv(buf); io_free(buf); }
IoCall *IoCall_proto(void *vState) { IoState *state = (IoState *)vState; IoMethodTable methodTable[] = { {"sender", IoCall_sender}, {"message", IoCall_message}, {"slotContext", IoCall_slotContext}, {"target", IoCall_target}, {"activated", IoCall_activated}, {"coroutine", IoCall_coroutine}, {"evalArgAt", IoCall_evalArgAt}, {"argAt", IoCall_argAt}, {"stopStatus", IoCall_stopStatus}, {"setStopStatus", IoCall_setStopStatus}, {NULL, NULL}, }; IoObject *self = IoObject_new(state); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoCallData))); IoObject_tag_(self, IoCall_newTag(state)); IoCall_initSlots(self); IoState_registerProtoWithFunc_((IoState *)state, self, IoCall_proto); IoObject_addMethodTable_(self, methodTable); return self; }
IoCFFIArray *IoCFFIArray_proto(void *state) { IoObject *self = IoCFFIDataType_new(state); IoObject_tag_(self, IoCFFIArray_newTag(state)); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoCFFIArrayData))); memset(DATA(self), 0, sizeof(IoCFFIArrayData)); DATA(self)->needToFreeBuffer = 0; IoState_registerProtoWithFunc_(state, self, IoCFFIArray_proto); { IoMethodTable methodTable[] = { {"address", IoCFFIArray_address}, {"asBuffer", IoCFFIArray_asBuffer}, {"at", IoCFFIArray_at}, {"atPut", IoCFFIArray_atPut}, {"setValue", IoCFFIArray_setValue}, {"size", IoCFFIArray_size}, {"with", IoCFFIArray_with}, {NULL, NULL}, }; IoObject_addMethodTable_(self, methodTable); } return self; }
IoCFFIArray *IoCFFIArray_with(IoCFFIArray *self, IoObject *locals, IoMessage *m) { IoCFFIDataType *type; int size, i; ffi_type *item_type; IoCFFIArray *o = IOCLONE(self); IoState_on_doCString_withLabel_(IoObject_state(o), o, "init", "IoCFFIArray_with"); type = IOCLONE(IoMessage_locals_valueArgAt_(m, locals, 0)); IoObject_setSlot_to_(o, IOSYMBOL("arrayType"), type); size = IoMessage_locals_intArgAt_(m, locals, 1); DATA(o)->arraySize = size; item_type = IoCFFIDataType_ffiType(type); DATA(o)->itemSize = item_type->size; // Fake libffi to think we are a Struct DATA(o)->ffiType.size = 0; DATA(o)->ffiType.alignment = 0; DATA(o)->ffiType.type = FFI_TYPE_STRUCT; DATA(o)->ffiType.elements = io_calloc(size + 1, sizeof(ffi_type *)); DATA(o)->needToFreeFFIType = 1; for ( i = 0 ; i < size ; i++ ) { DATA(o)->ffiType.elements[i] = item_type; } DATA(o)->ffiType.elements[size] = NULL; ffi_cif cif; ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &(DATA(o)->ffiType), NULL); return o; }
IoDirectory *IoDirectory_proto(void *state) { IoObject *self = IoObject_new(state); IoObject_tag_(self, IoDirectory_newTag(state)); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoDirectoryData))); DATA(self)->path = IOSYMBOL("."); IoState_registerProtoWithFunc_((IoState *)state, self, IoDirectory_proto); { IoMethodTable methodTable[] = { {"setPath", IoDirectory_setPath}, {"path", IoDirectory_path}, {"name", IoDirectory_name}, {"exists", IoDirectory_exists}, {"items", IoDirectory_items}, {"at", IoDirectory_at}, {"size", IoDirectory_size}, {"create", IoDirectory_create}, {"createSubdirectory", IoDirectory_createSubdirectory}, {"currentWorkingDirectory", IoDirectory_currentWorkingDirectory}, {"setCurrentWorkingDirectory", IoDirectory_setCurrentWorkingDirectory}, {NULL, NULL}, }; IoObject_addMethodTable_(self, methodTable); } return self; }
SHash *SHash_new(void) { SHash *self = (SHash *)io_calloc(1, sizeof(SHash)); self->numKeys = 0; SHash_tableInit_(self, 1); //printf("ok"); return self; }
char *IoNumber_asAllocedCString(IoNumber *self) { int size = 1024; char *s = (char *)io_calloc(1, size); memset(s, 0, size); IoNumber_Double_intoCString_(DATA(self), s, size - 1); return s; }
IoCFFIArray *IoCFFIArray_rawClone(IoCFFIArray *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoCFFIArrayData))); memset(DATA(self), 0, sizeof(IoCFFIArrayData)); IoObject* arrayType = IoObject_getSlot_(proto, IOSYMBOL("arrayType")); if ( !ISNIL(arrayType) ) { DATA(self)->ffiType = DATA(proto)->ffiType; DATA(self)->itemSize = DATA(proto)->itemSize; DATA(self)->arraySize = DATA(proto)->arraySize; DATA(self)->buffer = io_calloc(DATA(self)->arraySize, DATA(self)->itemSize); DATA(self)->needToFreeBuffer = 1; } return self; }
void SHash_tableInit_(SHash* self, int log2tableSize) { if (log2tableSize > 20) printf("ouuups"); self->log2tableSize = log2tableSize; self->tableSize = 1<<self->log2tableSize; self->records = (SHashRecord *)io_calloc(1, sizeof(SHashRecord) * self->tableSize * 2); self->mask = self->tableSize-1; }
Image *Image_new(void) { Image *self = (Image *)io_calloc(1, sizeof(Image)); Image_path_(self, ""); Image_fileType_(self, ""); self->byteArray = UArray_new(); self->ownsUArray = 1; self->componentCount = 4; self->encodingQuality = 1.0; return self; }
IoCoroutine *IoCoroutine_rawClone(IoCoroutine *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoCoroutineData))); DATA(self)->ioStack = Stack_new(); #ifdef STACK_POP_CALLBACK Stack_popCallback_(DATA(self)->ioStack, IoObject_freeIfUnreferenced); #endif DATA(self)->cid = (Coro *)NULL; return self; }
void PHash_resizeTo_(PHash *self, size_t newSize) { unsigned char *oldRecords = self->records; size_t oldSize = self->size; self->size = newSize; self->records = io_calloc(1, sizeof(PHashRecord) * self->size); self->keyCount = 0; PHash_updateMask(self); PHash_insertRecords(self, oldRecords, oldSize); io_free(oldRecords); }
IoCFunction *IoCFunction_proto(void *state) { IoObject *self = IoObject_new(state); IoObject_tag_(self, IoCFunction_newTag(state)); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoCFunctionData))); DATA(self)->func = IoObject_self; //IoObject_isActivatable_(self, 1); IoState_registerProtoWithFunc_((IoState *)state, self, IoCFunction_proto); return self; }
IoMessage *IoMessage_rawClone(IoMessage *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoMessageData))); DATA(self)->args = List_new(); IoMessage_rawSetName_(self, DATA(proto)->name); IoMessage_rawSetLabel_(self, DATA(proto)->label); //DATA(self)->name = DATA(proto)->name; //DATA(self)->label = DATA(proto)->label; /* any clone really needs to be a deep copy */ return self; }
Coro *Coro_new(void) { Coro *self = (Coro *)io_calloc(1, sizeof(Coro)); self->requestedStackSize = CORO_DEFAULT_STACK_SIZE; self->allocatedStackSize = 0; #ifdef USE_FIBERS self->fiber = NULL; #else self->stack = NULL; #endif return self; }
IoFnmatch *IoFnmatch_proto(void *state) { IoFnmatch *self = IoObject_new(state); IoObject_tag_(self, IoFnmatch_newTag(state)); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoFnmatchData))); DATA(self)->string = IOSYMBOL(""); DATA(self)->pattern = DATA(self)->string; IoState_registerProtoWithFunc_(state, self, IoFnmatch_proto); { IoMethodTable methodTable[] = { {"pattern", IoFnmatch_pattern}, {"setPattern", IoFnmatch_setPattern}, {"string", IoFnmatch_string}, {"setString", IoFnmatch_setString}, {"hasMatch", IoFnmatch_hasMatch}, {"matchFor", IoFnmatch_matchFor}, #ifdef FNM_NOESCAPE {"noEscapeOn", IoFnmatch_noEscapeOn}, {"noEscapeOff", IoFnmatch_noEscapeOff}, #endif #ifdef FNM_PATHNAME {"pathNameOn", IoFnmatch_pathNameOn}, {"pathNameOff", IoFnmatch_pathNameOff}, #endif #ifdef FNM_PERIOD {"periodOn", IoFnmatch_periodOn}, {"periodOff", IoFnmatch_periodOff}, #endif #ifdef FNM_LEADING_DIR {"leadingDirOn", IoFnmatch_leadingDirOn}, {"leadingDirOff", IoFnmatch_leadingDirOff}, #endif #ifdef FNM_CASEFOLD {"caseFoldOn", IoFnmatch_caseFoldOn}, {"caseFoldOff", IoFnmatch_caseFoldOff}, #endif {NULL, NULL}, }; IoObject_addMethodTable_(self, methodTable); } return self; }
IoTag *IoTag_new(void) { IoTag *self = (IoTag *)io_calloc(1, sizeof(IoTag)); #ifdef IOMESSAGE_INLINE_PERFORM self->performFunc = NULL; #else self->performFunc = (IoTagPerformFunc *)IoObject_perform; #endif self->referenceCount = 1; //self->recyclableInstances = Stack_new(); //self->maxRecyclableInstances = 10000; return self; }
static DIR *opendir(char *pSpec) { DIR *pDir = io_calloc(1, sizeof *pDir); char *longer_string = io_calloc(1, (strlen(pSpec) + 3) * sizeof *longer_string); strcpy(longer_string, pSpec); strcat(longer_string, "/*"); pDir->hFind = FindFirstFile(longer_string, &pDir->wfd); io_free(longer_string); pDir->valid = pDir->hFind != INVALID_HANDLE_VALUE; if (!pDir->valid) { DWORD err = GetLastError(); if (err == ERROR_PATH_NOT_FOUND) { io_free(pDir); return (DIR*)0; } } return pDir; }