Ejemplo n.º 1
0
Archivo: IoBox.c Proyecto: ADTSH/io
IoObject *IoBox_containsPoint(IoBox *self, IoObject *locals, IoMessage *m)
{
	/*doc Box containsPoint(aPoint)
	Returns true if aPoint is within the receiver's bounds, false otherwise.
	*/

	int result;

	IoVector *otherPoint = IoMessage_locals_pointArgAt_(m, locals, 0);

	UArray *bo = IoSeq_rawUArray(IoBox_rawOrigin(self));
	UArray *bs = IoSeq_rawUArray(IoBox_rawSize(self));
	UArray *p  = IoSeq_rawUArray(otherPoint);

	// do a malloc since the vectors might be large

	UArray *b1 = UArray_clone(bo);
	UArray *b2 = UArray_clone(bs);

	// make bo2 the box endpoint

	UArray_add_(b2, b1);

	// ensure bo1 is on the left bottom and bo2 is on the top right

	UArray_Min(b1, b2);
	UArray_Max(b2, bo);

	result = UArray_greaterThanOrEqualTo_(p, b1) && UArray_greaterThanOrEqualTo_(b2, p);

	UArray_free(b1);
	UArray_free(b2);

	return IOBOOL(self, result);
}
Ejemplo n.º 2
0
void BStream_free(BStream *self)
{
	if (self->ownsUArray) UArray_free(self->ba);
	UArray_free(self->tmp);
	UArray_free(self->errorBa);
	io_free(self->typeBuf);
	io_free(self);
}
Ejemplo n.º 3
0
void UArray2_free(T *uarray2)
{
    int i;
    for(i = 0; i < (*uarray2) -> height; i++)
    {
        UArray_free(UArray_at((*uarray2) -> array, i));
    }
    UArray_free(&(*uarray2) -> array);
    FREE (*uarray2);
    return;
}
Ejemplo n.º 4
0
/*-----------------------------------------------------------------------------*
| UArray2_free
|       Purpose:   frees the memory allocated for the given UArray2
|       Arguments: a pointer to a pointer to a 2D array
|       Returns:   -
|       Fail cases:
|               - the pointer to the pointer to the 2D array is null
|               - the pointer to the 2D array is null
*-----------------------------------------------------------------------------*/
void UArray2_free (UArray2_T *uarray2) {
        assert((uarray2 != NULL) && (*uarray2 != NULL));
        UArray2_T temp = *uarray2;
        UArray_T array = temp->uarray;
        UArray_free(&array);
        free(temp);
}
Ejemplo n.º 5
0
IOIMAGE_API IoObject *IoImage_filterGauss(IoImage *self, IoObject *locals, IoMessage *m)
{
	/*doc Image filterGauss(sigma)
	Returns new image as a result of applying filter. Implements Gauss smoothing filtering with parameter sigma.
	*/
	double sigma = IoMessage_locals_doubleArgAt_(m, locals, 0);
	int filterSize = round(sigma * 2.5) * 2 + 1;
	UArray* filter = UArray_new();
	UArray_setItemType_(filter, CTYPE_int8_t);
	UArray_setEncoding_(filter, CENCODING_NUMBER);
	UArray_setSize_(filter, filterSize * filterSize);
	int8_t *filterBytes = UArray_mutableBytes(filter);
	int x, y, x1, y1;
	for(y = 0; y < filterSize; y++)
	{
		y1 = y - filterSize / 2;
		for(x = 0; x < filterSize; x++)
		{
			x1 = x - filterSize / 2;
			filterBytes[x + y * filterSize] = exp(-(x1*x1 + y1*y1)/2/sigma) * filterSize * filterSize * 2;
		}
	}
	IoImage* toReturn = IoImage_newWithImage_(IOSTATE, Image_applyLinearFilter(DATA(self)->image, filterSize, filterSize, filter));
	UArray_free(filter);
	return toReturn;
}
Ejemplo n.º 6
0
void PNGImage_free(PNGImage *self)
{
	if (self->ownsBuffer) UArray_free(self->byteArray);
	if (self->error) free(self->error);
	free(self->path);
	free(self);
}
Ejemplo n.º 7
0
Archivo: IoFile.c Proyecto: achoy/io
IO_METHOD(IoFile, contents)
{
	/*doc File contents
	Returns contents of the file as a mutable Sequence of bytes.
	*/

	UArray *ba = UArray_new();
	long result = -1;

	if (DATA(self)->stream == stdin)
	{
		result = UArray_readFromCStream_(ba, DATA(self)->stream);
	}
	else
	{
		result = UArray_readFromFilePath_(ba, IoSeq_rawUArray(DATA(self)->path));
	}

	if (result != -1)
	{
		return IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
	}
	else
	{
		UArray_free(ba);
		IoState_error_(IOSTATE, m, "unable to read file '%s'", UTF8CSTRING(DATA(self)->path));
	}

	return IONIL(self);
}
Ejemplo n.º 8
0
Archivo: IoCoroutine.c Proyecto: jdp/io
void IoCoroutine_rawPrintBackTrace(IoCoroutine *self)
{
	IoObject *e = IoCoroutine_rawException(self);
	IoMessage *caughtMessage = IoObject_rawGetSlot_(e, IOSYMBOL("caughtMessage"));

	if (IoObject_rawGetSlot_(e, IOSYMBOL("showStack"))) // sanity check
	{
		IoState_on_doCString_withLabel_(IOSTATE, e, "showStack", "[Coroutine]");
	}
	else
	{
		IoSymbol *error = IoObject_rawGetSlot_(e, IOSYMBOL("error"));

		if (error)
		{
			fputs(CSTRING(error), stderr);
			fputs("\n", stderr);
		}
		else
		{
			fputs("error: [missing error slot in Exception object]\n", stderr);
		}

		if (caughtMessage)
		{
			UArray *ba = IoMessage_asMinimalStackEntryDescription(caughtMessage);
			fputs(UArray_asCString(ba), stderr);
			fputs("\n", stderr);
			UArray_free(ba);
		}
	}
}
Ejemplo n.º 9
0
void Image_makeRGBA(Image *self)
{
	if (self->componentCount == 3)
	{
		//Image_addAlpha(self);
		//printf("converted component count from 3 to 4\n");
	} 
	else if (self->componentCount == 1)
	{
		UArray *outUArray = UArray_new();
		UArray_setSize_(outUArray, 4 * self->width * self->height);
		uint8_t *outData = (uint8_t *)UArray_bytes(outUArray);
		uint8_t *inData  = (uint8_t *)UArray_bytes(self->byteArray);
		size_t numPixels = self->width * self->height;
		size_t p1;
		size_t p2 = 0;
		
		for (p1 = 0; p1 < numPixels; p1 ++)
		{
			outData[p2] = inData[p1]; p2 ++;
			outData[p2] = inData[p1]; p2 ++;
			outData[p2] = inData[p1]; p2 ++;
			outData[p2] = 255; p2 ++;
		}
		
		UArray_copy_(self->byteArray, outUArray);
		UArray_free(outUArray);

		self->componentCount = 4;
		//printf("converted component count from 1 to 4\n");
	}
}
Ejemplo n.º 10
0
IoObject *IoTokyoCabinetPrefixCursor_key(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc TokyoCabinetPrefixCursor key
	Returns current cursor key or nil.
	*/
	
	int size;
	char *ks;
	
	IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix"));
	IOASSERT(ISSEQ(prefix), "prefix must be a sequence");
	IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor");
	ks = tcbdbcurkey(TokyoCabinetPrefixCursor(self), &size);

	if (ks)
	{
		UArray *k = UArray_newWithData_type_size_copy_(ks, CTYPE_uint8_t, size, 1);
	
		if (UArray_beginsWith_(k, IoSeq_rawUArray(prefix)))
		{
			//printf("prefix '%s'\n", UArray_bytes(IoSeq_rawUArray(prefix)));
			//printf("before clip '%s'\n", UArray_bytes(k));
			UArray_clipBeforeEndOf_(k, IoSeq_rawUArray(prefix));
			UArray_removeFirst(k); // remove separator
			//printf("after clip  '%s'\n", UArray_bytes(k));
			return IoSeq_newWithUArray_copy_(IOSTATE, k, 0);
		}

		UArray_free(k);
	}

	return IONIL(self);
}
Ejemplo n.º 11
0
void IoMessage_print(IoMessage *self)
{
	UArray *ba = IoMessage_description(self);

	//printf("%s\n", UArray_asCString(ba));
	IoState_print_(IOSTATE, UArray_asCString(ba));
	UArray_free(ba);
}
Ejemplo n.º 12
0
void HTTPParser_clearParseError(HTTPParser *self)
{
	if(self->parseError)
	{
		UArray_free(self->parseError);
	}
	self->parseError = NULL;
}
Ejemplo n.º 13
0
void AudioDevice_free(AudioDevice *self)
{
	self->isFreed = 1;
	AudioDevice_lock(self);
	/*
	 while (self->locked)
	 { printf("AudioDevice_free waiting on lock %i\n", self->locked); }
	 */
	AudioDevice_terminate(self);

	UArray_free(self->writeBuffer);
	UArray_free(self->nextWriteBuffer);

	UArray_free(self->readBuffer);
	UArray_free(self->nextReadBuffer);

	free(self);
}
Ejemplo n.º 14
0
Archivo: IoFile.c Proyecto: achoy/io
IO_METHOD(IoFile, readLine)
{
	/*doc File readLine
	Reads the next line of the file and returns it as a
	string without the return character. Returns Nil if the 
	end of the file has been reached.
	*/

	//char *path = UTF8CSTRING(DATA(self)->path); // tmp for debugging

	IoFile_assertOpen(self, locals, m);

	if (feof(DATA(self)->stream) != 0)
	{
		clearerr(DATA(self)->stream);
		return IONIL(self);
	}
	else
	{
		UArray *ba = UArray_new();
		int error;
		unsigned char didRead = UArray_readLineFromCStream_(ba, DATA(self)->stream);

		if (!didRead)
		{
			UArray_free(ba);
			return IONIL(self);
		}

		error = ferror(DATA(self)->stream);

		if (error != 0)
		{
			UArray_free(ba);
			clearerr(DATA(self)->stream);
			IoState_error_(IOSTATE, m, "error reading from file '%s'", UTF8CSTRING(DATA(self)->path));
			return IONIL(self);
		}

		return IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
		/*return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);*/
	}
}
Ejemplo n.º 15
0
void clean_up()
{
	free_segments(um->memory);
	free_IDs(um->unmapped_IDs);
	UArray_free(&um->registers);	

	FREE(um);

	return;
}
Ejemplo n.º 16
0
void IoAudioMixer_free(IoAudioMixer *self) 
{ 
	List_free(DATA(self)->sounds);
	List_free(DATA(self)->soundsToRemove);
	List_free(DATA(self)->events);
	List_free(DATA(self)->activeEvents);
	UArray_free(DATA(self)->mixBuffer);
	SoundTouch_free(DATA(self)->soundTouch);
	free(self->data); 
}
Ejemplo n.º 17
0
void BStream_setUArray_(BStream *self, UArray *ba)
{
	if (self->ownsUArray)
	{
		UArray_free(ba);
		self->ownsUArray = 0;
	}
	self->ba = ba;
	self->index = 0;
}
Ejemplo n.º 18
0
Archivo: IoSHA1.c Proyecto: ADTSH/io
IoObject *IoSHA1_sha1String(IoSHA1 *self, IoObject *locals, IoMessage *m)
{
	/*doc SHA1 sha1String
	Returns a string containing a hexadecimal representation of the sha1 hash.
	*/
	
	UArray *ba = IoSHA1_sha1UArray(self);
	UArray *baString = UArray_asNewHexStringUArray(ba);
	UArray_free(ba);
	return IoState_symbolWithUArray_copy_(IOSTATE, baString, 0);
}
Ejemplo n.º 19
0
/*
 * Frees all the memory associated with the Segment Manager
 * Parameter: sm - The Segment Manager Struct
 */
void segment_Free(Segment_Manager sm)
{
	Segment nextsegment;
	while (Seq_length(sm->Segment_Table) != 0) {
		nextsegment = (UArray_T)Seq_remhi(sm->Segment_Table);
		if (nextsegment != NULL)
			UArray_free(&nextsegment);
	};
	Seq_free(&(sm->Segment_Table));
	Seq_free(&(sm->ID_Stack));
	free(sm);
	return;
}
Ejemplo n.º 20
0
/* frees all of the segments and their contents */
void free_all(Segment outer)
{
	assert(outer);

	int num_segs = Seq_length(outer);

	for (int i = 0; i < num_segs; i++) {
		UArray_T inner = Seq_get(outer, i);
		UArray_free(&inner);
	}

	Seq_free(&outer);
}
Ejemplo n.º 21
0
void IoSeq_free(IoSeq *self)
{
	if (IoObject_isSymbol(self))
	{
		//if(strcmp(CSTRING(self), "_x_") == 0) { printf("Symbol free '%s'\n", CSTRING(self)); }
		//if(strlen(CSTRING(self)) < 100 && strncmp("0.", CSTRING(self), 2) != 0 ) { printf("Symbol free '%s'\n", CSTRING(self)); }
		IoState_removeSymbol_(IOSTATE, self);
	}

	if (DATA(self) != NULL)
	{
		UArray_free(DATA(self));
	}
}
Ejemplo n.º 22
0
/* deletes the memory contained in a segment and replaces it with a new
	sequence */
bool clear_seg(Segment s, uint32_t ID)
{
	TRY
		assert(s);

		UArray_T to_rmv = Seq_put(s, ID, UArray_new(0, sizeof(uint32_t)));
		UArray_free(&to_rmv);

	EXCEPT(Mem_Failed)
		return false;
	END_TRY;

	return true;
}
Ejemplo n.º 23
0
void UArray2b_free(T *array2b) {
  assert(array2b && *array2b);
  T a2b = *array2b;
  int bwidth = UArray2_width(a2b->blocks);
  int bheight = UArray2_height(a2b->blocks);
  for (int i=0; i<bwidth; i++) {
    for (int j=0; j<bheight; j++) {
      UArray_free(UArray2_at(a2b->blocks,i,j));
    }
  }
  UArray2_free(&(a2b->blocks));
  free(*array2b);
  *array2b = NULL;
}
Ejemplo n.º 24
0
Archivo: IoFile.c Proyecto: achoy/io
UArray *IoFile_readUArrayOfLength_(IoFile *self, IoObject *locals, IoMessage *m)
{
	size_t length = IoMessage_locals_sizetArgAt_(m, locals, 0);
	UArray *ba = UArray_new();
	IoFile_assertOpen(self, locals, m);

	UArray_readNumberOfItems_fromCStream_(ba, length, DATA(self)->stream);

	if (ferror(DATA(self)->stream) != 0)
	{
		clearerr(DATA(self)->stream);
		UArray_free(ba);
		IoState_error_(IOSTATE, m, "error reading file '%s'", UTF8CSTRING(DATA(self)->path));
	}

	if (!UArray_size(ba))
	{
		UArray_free(ba);
		return NULL;
	}

	return ba;
}
Ejemplo n.º 25
0
Archivo: IoFile.c Proyecto: achoy/io
IoObject *IoFile_rawAsString(IoFile *self)
{
	UArray *ba = UArray_new();

	if (UArray_readFromFilePath_(ba, IoSeq_rawUArray(DATA(self)->path)) == 1)
	{
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}
	else
	{
		UArray_free(ba);
		IoState_error_(IOSTATE, NULL, "unable to read file '%s'", UTF8CSTRING(DATA(self)->path));
	}

	return IONIL(self);
}
Ejemplo n.º 26
0
IoSymbol *IoSeq_newSymbolWithUArray_copy_(void *state, UArray *ba, int copy)
{
	IoObject *self = IoSeq_new(state);

	if (copy)
	{
		UArray_copy_(DATA(self), ba);
	}
	else
	{
		UArray_free(DATA(self));
		IoObject_setDataPointer_(self, ba);
	}

	return self;
}
Ejemplo n.º 27
0
IOIMAGE_API IoObject *IoImage_filterMedian(IoImage *self, IoObject *locals, IoMessage *m)
{
	/*doc Image filterMedian(filterSizeX, filterSizeY)
	Returns new image as a result of applying filter.
	*/
	int filterSizeX = IoMessage_locals_intArgAt_(m, locals, 0);
	int filterSizeY = IoMessage_locals_intArgAt_(m, locals, 1);
	UArray* filter = UArray_new();
	UArray_setItemType_(filter, CTYPE_int8_t);
	UArray_setEncoding_(filter, CENCODING_NUMBER);
	UArray_setSize_(filter, filterSizeX * filterSizeY);
	memset(UArray_mutableBytes(filter), 1, filterSizeX * filterSizeY);
	IoImage* toReturn = IoImage_newWithImage_(IOSTATE, Image_applyWeightedMedianFilter(DATA(self)->image, filterSizeX, filterSizeY, filter));
	UArray_free(filter);
	return toReturn;
}
Ejemplo n.º 28
0
void Image_free(Image *self)
{
	if (self->ownsUArray)
	{
		UArray_free(self->byteArray);
	}

	if (self->error)
	{
		io_free(self->error);
	}

	io_free(self->fileType);
	io_free(self->path);

	io_free(self);
}
Ejemplo n.º 29
0
IoSymbol *IoState_symbolWithUArray_copy_(IoState *self, UArray *ba, int copy)
{
	IoSymbol *ioSymbol = CHash_at_(self->symbols, ba);

	if (!ioSymbol)
	{
		ioSymbol = IoSeq_newSymbolWithUArray_copy_(self, ba, copy);
		return IoState_addSymbol_(self, ioSymbol);
	}

	if (!copy)
	{
		UArray_free(ba);
	}

	IoState_stackRetain_(self, ioSymbol);
	return ioSymbol;
}
Ejemplo n.º 30
0
Archivo: IoDate.c Proyecto: bomma/io
IoDate *IoDate_fromSerialization(IoDate *self, IoObject *locals, IoMessage *m)
{
	/*doc Date fromSerialization
	Sets the date based on the serialization sequence.  Return self.
	*/
	
	IoSeq *serializationSeq = IoMessage_locals_seqArgAt_(m, locals, 0);
	UArray *serialization = UArray_clone(IoSeq_rawUArray(serializationSeq));
	
	UArray_setItemType_(serialization, CTYPE_int32_t);
	if(UArray_size(serialization) != 4)
	{
		IoState_error_(IOSTATE, self, "Expected a serialization sequence comprising 4 int32 items.");
	}
	
	Date_fromSerialization(DATA(self), serialization);
	
	UArray_free(serialization);
	
	return self;
}