Ejemplo n.º 1
0
Archivo: IoDBI.c Proyecto: BMeph/io
IoObject *IoDBI_initWithDriversPath(IoDBI *self, IoObject *locals,
			IoMessage *m)
{
	/*doc DBI initWithDriversPath 
	Initialize the DBI environment with the specified libdbi driver path.
	*/
	IoObject *dir = IoMessage_locals_valueArgAt_(m, locals, 0);

	if (ISSYMBOL(dir))
	{
		DATA(self)->driverCount = dbi_initialize(CSTRING(dir));
	}
	else
	{
		IoState_error_(IOSTATE, m, "argument 0 to method '%s' must be a Symbol, not a '%s'\n",
			CSTRING(IoMessage_name(m)), IoObject_name(dir));
	}

	if (DATA(self)->driverCount == -1)
	{
		IoState_error_(IOSTATE, m, "*** IoDBI error during dbi_initialize\n");
	}
	else
	{
		DATA(self)->didInit = 1;
	}

	return IONUMBER(DATA(self)->driverCount);
}
Ejemplo n.º 2
0
Archivo: IoDBI.c Proyecto: BMeph/io
IoObject *IoDBI_with(IoDBI *self, IoObject *locals, IoMessage *m)
{
	//doc DBI with(driverName) Get a new connection with the given driver.
	
	IoObject *name = IoMessage_locals_valueArgAt_(m, locals, 0);
	if (!ISSYMBOL(name))
	{
		IoState_error_(IOSTATE, m, "argument 0 to method '%s' must be a Symbol, not a '%s'\n",
			CSTRING(IoMessage_name(m)), IoObject_name(name));
		return IONIL(self);
	}

	if (DATA(self)->didInit != 1)
	{
		IoDBI_init(self, locals, m);
	}

	dbi_conn c = dbi_conn_new(CSTRING(name));
	if (c == NULL)
	{
		IoState_error_(IOSTATE, m, "libdbi error during dbi_conn_new\n");
		return IONIL(self);
	}

	return IoDBIConn_new(IOSTATE, c);
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
IoSecureServer *IoSecureServer_setCRLFile(IoSecureServer *self, IoObject *locals, IoMessage *msg)
{
	SSL_CTX *ctx = OCTX(self);
	IoSeq *pathSeq = IoMessage_locals_seqArgAt_(msg, locals, 0);
	char *path = IoSeq_asCString(pathSeq);
	if(ctx == NULL)
	{
		IoState_error_(IOSTATE, msg, "SecureServer has no SSL_CTX");
		return IONIL(self);
	}
	X509_STORE *store = SSL_CTX_get_cert_store(ctx);
	X509_STORE_set_verify_cb_func(store, IoSecureSockets_Verify_CRL_Callback);
	X509_STORE_set_flags (store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
	X509_LOOKUP *lookup;
	if (!(lookup = X509_STORE_add_lookup (store, X509_LOOKUP_file ())))
	{
		ERR_print_errors_fp(stderr);
		IoState_error_(IOSTATE, msg, "Error creating X509_LOOKUP object.");
	  	return IONIL(self);
	}
	if (X509_load_crl_file(lookup, path, X509_FILETYPE_PEM) != 1)
	{
		ERR_print_errors_fp(stderr);
		IoState_error_(IOSTATE, msg, "Error loading CRL from file %s\n", path);
	  	return IONIL(self);
	}
	
	return self;
}
Ejemplo n.º 5
0
int Levels_levelForOp(Levels *self, char *messageName, IoSymbol *messageSymbol, IoMessage *msg)
{
	IoObject *value = IoMap_rawAt(self->operatorTable, messageSymbol);

	if (!value)
	{
		return -1;
	}

	if (ISNUMBER(value))
	{
		int precedence = IoNumber_asInt((IoNumber*)value);
		if (precedence < 0 || precedence >= IO_OP_MAX_LEVEL)
		{
			IoState_error_(IoObject_state(msg), msg, "compile error: Precedence for operators must be between 0 and %d. Precedence was %d.", IO_OP_MAX_LEVEL - 1, precedence);
		}

		return precedence;
	}
	else
	{
		IoState_error_(IoObject_state(msg), msg, "compile error: Value for '%s' in Message OperatorTable operators is not a number. Values in the OperatorTable operators are numbers which indicate the precedence of the operator.", messageName);
		return -1; // The C compiler does not know that IoState_error_() will never return.
	}
}
Ejemplo n.º 6
0
IO_METHOD(IoSeq, between)
{
	/*doc Sequence between(aSequence, anotherSequence)
	Returns a new Sequence containing the bytes between the
	occurance of aSequence and anotherSequence in the receiver.
	*/

	long start = 0;
	long end = 0;
	IoSeq *fromSeq, *toSeq;

	fromSeq = (IoSeq *)IoMessage_locals_valueArgAt_(m, locals, 0);

	if (ISSEQ(fromSeq))
	{
		start = UArray_find_from_(DATA(self), DATA(fromSeq), 0) + IoSeq_rawSize(fromSeq);

		if (start == -1)
		{
			start = 0;
		}
	}
	else if (ISNIL(fromSeq))
	{
		start = 0;
	}
	else
	{
		IoState_error_(IOSTATE, m, "Nil or Sequence argument required for arg 0, not a %s",
					IoObject_name((IoObject *)fromSeq));
	}

	toSeq = (IoSeq *)IoMessage_locals_valueArgAt_(m, locals, 1);

	if (ISSEQ(toSeq))
	{
		end = UArray_find_from_(DATA(self), DATA(toSeq), start);
		if (end == -1) start = UArray_size(DATA(self));
	}
	else if (ISNIL(toSeq))
	{
		end = UArray_size(DATA(self));
	}
	else
	{
		IoState_error_(IOSTATE, m, "Nil or Sequence argument required for arg 1, not a %s",
					IoObject_name((IoObject *)toSeq));
	}

	{
		UArray *ba = UArray_slice(DATA(self), start, end);
		IoSeq *result = IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
		return result;
	}
}
Ejemplo n.º 7
0
IoCairoSurface *IoCairoSurface_newWithRawSurface_(void *state, IoMessage *m, cairo_surface_t *surface)
{
	IoObject *self = 0;
	IoStateProtoFunc *initFunc = 0;

	checkStatus_(state, m, cairo_surface_status(surface));

	switch(cairo_surface_get_type(surface))
	{
		case CAIRO_SURFACE_TYPE_IMAGE:
			initFunc = IoCairoImageSurface_proto;
			break;
		case CAIRO_SURFACE_TYPE_PS:
			initFunc = IoCairoPSSurface_proto;
			break;
		case CAIRO_SURFACE_TYPE_PDF:
			initFunc = IoCairoPDFSurface_proto;
			break;
		case CAIRO_SURFACE_TYPE_SVG:
			initFunc = IoCairoSVGSurface_proto;
			break;
	default:
			IoState_error_(state, 0, "Unsupported surface type");
	}

	self = IOCLONE(IoState_protoWithId_(state, protoId));
	IoObject_setDataPointer_(self, surface);
	return self;
}
Ejemplo n.º 8
0
Archivo: IoDBI.c Proyecto: BMeph/io
void ReportDBIError(dbi_conn conn, void *state, IoMessage *m)
{
	const char *error;
	int errorCode = dbi_conn_error(conn, &error);

	IoState_error_(state, m, "libdbi: %i: %s\n", errorCode, error);
}
Ejemplo n.º 9
0
IoCFFIArray *IoCFFIArray_atPut(IoCFFIArray *self, IoObject *locals, IoMessage *m)
{
	int pos;
	IoObject *value, *arrayType, *d;
	char *ptr;

	pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
	value = IoMessage_locals_valueArgAt_(m, locals, 1);

	if ( pos >= DATA(self)->arraySize ) {
		IoState_error_(IOSTATE, m, "index out of bounds");
		return IONIL(self);
	}

	arrayType = IoObject_getSlot_(self, IOSYMBOL("arrayType"));
	ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos);

	d = IOCLONE(arrayType);
	IoCFFIDataType_rawSetValue(d, value);
	memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(self, d), DATA(self)->itemSize);

	if ( DATA(self)->keepValuesRefs ) {
		DATA(self)->keepValuesRefs[pos] = IOREF(d);
	}

	return self;
}
Ejemplo n.º 10
0
/*doc Memcached replace(key, value[, expiration])
Asks memcached to store the value identified by the key,
but only if the server *does* already hold data for this key.
Returns true on success, false if there is already data for this key.
Otherwise raises an exception.
*/
IoObject *IoMemcached_replace(IoMemcached *self, IoObject *locals, IoMessage *m)
{
	IoSeq    *key   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoObject *value = IoMessage_locals_quickValueArgAt_(m, locals, 1);

	time_t expiration = IoMessage_argCount(m) == 3 ? IoMessage_locals_intArgAt_(m, locals, 2) : 0;

	uint32_t flags;
	size_t size;
	char *cvalue = IoMemcached_serialize(self, locals, value, &size, &flags);

	memcached_return_t rc;
	rc = memcached_replace(DATA(self)->mc,
		CSTRING(key), IOSEQ_LENGTH(key),
		cvalue, size,
		expiration, flags
	);

	free(cvalue);

	if(rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTSTORED)
		IoState_error_(IOSTATE, m, memcached_strerror(DATA(self)->mc, rc));

	// MEMCACHED_NOTSTORED is a legitmate error in the case of a collision.
	if(rc == MEMCACHED_NOTSTORED)
		return IOSTATE->ioFalse;

	return IOSTATE->ioTrue; // MEMCACHED_SUCCESS
}
Ejemplo n.º 11
0
Archivo: IoFile.c Proyecto: achoy/io
IO_METHOD(IoFile, write)
{
	/*doc File write(aSequence1, aSequence2, ...)
	Writes the arguments to the receiver file. Returns self.
	*/

	int i;

	IoFile_assertOpen(self, locals, m);
	IoFile_assertWrite(self, locals, m);

	for (i = 0; i < IoMessage_argCount(m); i ++)
	{
		IoSymbol *string = IoMessage_locals_seqArgAt_(m, locals, i);
		UArray_writeToCStream_(IoSeq_rawUArray(string), DATA(self)->stream);

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

	return self;
}
Ejemplo n.º 12
0
Archivo: IoFile.c Proyecto: achoy/io
IO_METHOD(IoFile, moveTo_)
{
	/*doc File moveTo(pathString)
	Moves the file specified by the receiver's path to the
	new path pathString. Raises a File doesNotExist exception if the
	file does not exist or a File nameConflict exception if the file
	nameString already exists.
	*/

	IoSymbol *newPath = IoMessage_locals_symbolArgAt_(m, locals, 0);
	const char *fromPath = UTF8CSTRING(DATA(self)->path);
	const char *toPath = UTF8CSTRING(newPath);

	if(strcmp(fromPath, toPath) != 0)
	{
		int error;

		remove(toPath); // to make sure we do not get an error
		error = rename(fromPath, toPath);

		if (error)
		{
			IoState_error_(IOSTATE, m, "error moving file '%s' to '%s'", fromPath, toPath);
		}
	}

	return self;
}
Ejemplo n.º 13
0
Archivo: IoFile.c Proyecto: achoy/io
IO_METHOD(IoFile, remove)
{
	/*doc File remove
	Removes the file specified by the receiver's path.
	Raises an error if the file exists but is not removed. Returns self.
	*/

	int error = 0;

#if defined(__SYMBIAN32__)
	error = -1;
#elif defined(_MSC_VER) || defined(__MINGW32__)
	if(IoFile_justExists(self))
	{
		if(ISTRUE(IoFile_isDirectory(self, locals, m)))
		{
			error = rmdir(UTF8CSTRING(DATA(self)->path));
		}
		else
		{
			error = unlink(UTF8CSTRING(DATA(self)->path));
		}
	}
#else
	error = remove(UTF8CSTRING(DATA(self)->path));
#endif

	if (error && IoFile_justExists(self))
	{
		IoState_error_(IOSTATE, m, "error removing file '%s'", UTF8CSTRING(DATA(self)->path));
	}
	return self;
}
Ejemplo n.º 14
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.º 15
0
Archivo: IoAVCodec.c Proyecto: BMeph/io
IoObject *IoAVCodec_open(IoAVCodec *self, IoObject *locals, IoMessage *m)
{
	/*doc AVCodec open
	Opens the input file. Return self on success or raises an exception on error.
	*/
	
	int err;

	IoAVCodec_registerIfNeeded(self);
	IoAVCodec_freeContextIfNeeded(self);
	IoAVCodec_createContextIfNeeded(self);

	DATA(self)->isAtEnd = 0;

	err = IoAVCodec_openFile(self);

	if (err != 0)
	{
		IoObject *fileName = IoObject_symbolGetSlot_(self, IOSYMBOL("path"));
		IoState_error_(IOSTATE, m, "error %i opening file %s\n", err, CSTRING(fileName));
		return IONIL(self);
	}

	IoAVCodec_findStreams(self);
	av_read_play(DATA(self)->formatContext);

	return self;
}
Ejemplo n.º 16
0
IO_METHOD(IoSeq, replaceMap)
{
	/*doc Sequence replaceMap(aMap)
	In the receiver, the keys of aMap replaced with its values. Returns self.
	*/

	IoMap *map = IoMessage_locals_mapArgAt_(m, locals, 0);
	UArray *ba = DATA(self);

	IO_ASSERT_NOT_SYMBOL(self);

	PHASH_FOREACH(IoMap_rawHash(map), k, v,
		{
		IoSymbol *subSeq = k;
		IoSymbol *otherSeq = v;

		if (ISSEQ(otherSeq))
		{
			UArray_replace_with_(ba, DATA(subSeq), DATA(otherSeq));
		}
		else
		{
			IoState_error_(IOSTATE, m,
							"argument 0 to method '%s' must be a Map with Sequence values, not '%s'",
							CSTRING(IoMessage_name(m)), IoObject_name(otherSeq));
		}
		}
	);
Ejemplo n.º 17
0
IO_METHOD(IoSeq, asBinaryNumber)
{
	/*doc Sequence asBinaryNumber
	Returns a Number containing the first 8 bytes of the
	receiver without casting them to a double. Endian is same as machine.
	*/

	IoNumber *byteCount = IoMessage_locals_valueArgAt_(m, locals, 0);
	size_t max = UArray_size(DATA(self));
	int bc = sizeof(double);
	double d = 0;

	if (!ISNIL(byteCount))
	{
		bc = IoNumber_asInt(byteCount);
	}

	if (max < bc)
	{
		IoState_error_(IOSTATE, m, "requested first %i bytes, but Sequence only contians %i bytes", bc, max);
	}

	memcpy(&d, UArray_bytes(DATA(self)), bc);
	return IONUMBER(d);
}
Ejemplo n.º 18
0
IoObject *IoCFFIPointer_castTo(IoCFFIPointer *self, IoObject *locals, IoMessage *m)
{
    IoObject *toType = IoMessage_locals_valueArgAt_(m, locals, 0);
    IoObject *o = IoState_on_doCString_withLabel_(IOSTATE, toType, "?typeString", "IoCFFIPointer_castTo");

    if(!ISNIL(o)) {
        char *typeStr = CSTRING(o);

        switch(typeStr[0]) {
            case '^':
                toType = IOCLONE(toType);
                *(DATA(toType)->valuePointer) = *((void **)IoCFFIDataType_ValuePointerFromObject_(toType, self));
                return toType;
            case '*':
                toType = IOCLONE(toType);
                IoCFFIDataType_rawSetValue(toType, self);
                return toType;
            default:
                IoState_error_(IOSTATE, m, "Wrong type to cast to.");
                break;
        }
    }
    else {
        // Mm... well, if the type to cast to does not have a typeString slot,
        // it should be an Io Object, so the address stored here is a pointer to an
        // Io Object. Simply cast the pointer and return it... dangerous but...
        
        IoObject *obj = (IoObject *)*(DATA(self)->valuePointer);
        if(ISOBJECT(obj))
            return (IoObject *)*(DATA(self)->valuePointer);
    }

    return IONIL(self);
}
Ejemplo n.º 19
0
IO_METHOD(IoSeq, asBinarySignedInteger)
{
	/*doc Sequence asBinarySignedInteger
	Returns a Number with the bytes of the receiver interpreted as a binary signed integer. Endian is same as machine.
	*/

	const void *bytes = UArray_bytes(DATA(self));
	size_t byteCount = UArray_size(DATA(self));

	if(byteCount == 1)
	{
		return IONUMBER(*((const int8_t *)bytes));
	} 
	else if(byteCount == 2)
	{
		return IONUMBER(*((const int16_t *)bytes));
	} 
	else if(byteCount == 4)
	{
		return IONUMBER(*((const int32_t *)bytes));
	} 
	else 
	{
		IoState_error_(IOSTATE, m, "Sequence is %i bytes but only conversion of 1, 2, or 4 bytes is supported", byteCount);
	}

	return IONIL(self);
}
Ejemplo n.º 20
0
IO_METHOD(IoDirectory, createSubdirectory)
{
    /*doc Directory createSubdirectory(name)
    Create a subdirectory with the specified name.
    */

    IoState *state = IOSTATE;
    IoSymbol *subfolderName = IoMessage_locals_symbolArgAt_(m, locals, 0);
    IoObject *currentItem = IoDirectory_justAt(self, subfolderName);

    if (ISDIRECTORY(currentItem))
    {
        return currentItem;
    }

    if (ISFILE(currentItem))
    {
        IoState_error_(IOSTATE, m, "Attempt to create directory %s on top of existing file",
                       CSTRING(subfolderName));
    }
    else
    {
        IoSymbol *fullPath = IoDirectory_justFullPath(self, subfolderName);

        MKDIR(CSTRING(fullPath), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
        return IoDirectory_newWithPath_(state, fullPath);
    }

    return IONIL(self);
}
Ejemplo n.º 21
0
IO_METHOD(IoDirectory, items)
{
    /*doc Directory items
    Returns a list object containing File and Directory objects
    for the files and directories of the receiver's path.
    */

    IoList *items = IoList_new(IOSTATE);
    IoDirectoryData *data = DATA(self);
    DIR *dirp = opendir(CSTRING(data->path));
    struct dirent *dp;

    if (!dirp)
    {
        IoState_error_(IOSTATE, m, "Unable to open directory %s", CSTRING(DATA(self)->path));
    }

    while ((dp = readdir(dirp)) != NULL)
    {
        IoList_rawAppend_(items, IoDirectory_itemForDirent_(self, dp));
    }

    (void)closedir(dirp);
    return items;
}
Ejemplo n.º 22
0
Archivo: IoFile.c Proyecto: achoy/io
IO_METHOD(IoFile, assertOpen)
{
	if (!DATA(self)->stream)
	{
		IoState_error_(IOSTATE, m, "file '%s' not yet open", UTF8CSTRING(DATA(self)->path));
	}
	return self;
}
Ejemplo n.º 23
0
void IoMessage_assertArgCount_receiver_(IoMessage *self, int n, IoObject *receiver)
{
	if (List_size(DATA(self)->args) < n)
	{
		IoState_error_(IOSTATE, self, "[%s %s] requires %i arguments\n",
					   IoObject_name(receiver), CSTRING(DATA(self)->name), n);
	}
}
Ejemplo n.º 24
0
IoSecureServer *IoSecureServer_useDTLS(IoSecureServer *self, IoObject *locals, IoMessage *msg)
{
	#ifdef DTLS_IMPLEMENTED
	SSL_CTX *ctx = OCTX(self);
	if(SSL_CTX_set_ssl_version(ctx, DTLSv1_server_method()) != 1)
	{
		ERR_print_errors_fp(stderr);
		IoState_error_(IOSTATE, msg, "Error using DTLS");
		return IONIL(self);
	}
	SSL_CTX_set_read_ahead(ctx, 1);
	return self;
	#else
	IoState_error_(IOSTATE, msg, "Addon built against OpenSSL older than 0.9.8; DTLS is not supported.");
	return IONIL(self);
	#endif
}
Ejemplo n.º 25
0
/*doc Memcached stats
Returns a Map with servers' statistics. Keys are server addresses,
values are maps with actual stats.
*/
IoObject *IoMemcached_stats(IoMemcached *self, IoObject *locals, IoMessage *m)
{
	IoMap *results_map = IoMap_new(IOSTATE);

	int errors = 0;
	uint32_t pos = 0;
	while(pos < memcached_server_count(DATA(self)->mc)) {
		memcached_server_instance_st server = memcached_server_instance_by_position(DATA(self)->mc, pos);
		if(server == NULL)
			continue;

		const char *hostname = memcached_server_name(server);
		const in_port_t port = memcached_server_port(server);

		memcached_stat_st stats;
		memcached_return_t rc = memcached_stat_servername(&stats, "", hostname, port);
		if(rc != MEMCACHED_SUCCESS) {
			errors++;
			continue;
		}

		char **ckeys = memcached_stat_get_keys(DATA(self)->mc, &stats, &rc);
		if(rc != MEMCACHED_SUCCESS) {
			errors++;
			continue;
		}

		IoMap *per_server_map = IoMap_new(IOSTATE);
		char *ckey = *ckeys;
		while(ckey != NULL) {
			char *cvalue = memcached_stat_get_value(DATA(self)->mc, &stats, ckey, &rc);
			if(rc != MEMCACHED_SUCCESS) {
				errors++;
				continue;
			}

			IoMap_rawAtPut(per_server_map, IOSYMBOL(ckey), IOSYMBOL(cvalue));
			free(cvalue);
			ckey++;
		}

		free(ckeys);

		// "127.0.0.1:11211"
		char *server_key = (char *) malloc((strlen(hostname) + 1 + 5 + 1) * sizeof(char));
		sprintf(server_key, "%s:%d", hostname, port);

		IoMap_rawAtPut(results_map, IOSYMBOL(server_key), per_server_map);
		free(server_key);

		pos++;
	}

	if(errors > 0)
		IoState_error_(IOSTATE, m, memcached_strerror(DATA(self)->mc, MEMCACHED_SOME_ERRORS));

	return results_map;
}
Ejemplo n.º 26
0
void IoSeq_rawPio_reallocateToSize_(IoSeq *self, size_t size)
{
	if (ISSYMBOL(self))
	{
		IoState_error_(IOSTATE, NULL, "attempt to resize an immutable Sequence");
	}

	UArray_sizeTo_(DATA(self), size);
}
Ejemplo n.º 27
0
static void IoAssertNotSymbol(IoSeq *self, IoMessage *m)
{
	if (ISSYMBOL(self))
	{
		IoState_error_(IOSTATE, m,
					"'%s' cannot be called on an immutable Sequence",
					CSTRING(IoMessage_name(m)));
	}
}
Ejemplo n.º 28
0
void IoMessage_locals_numberArgAt_errorForType_(IoMessage *self,
												IoObject *locals,
												int n,
												const char *typeName)
{
	IoObject *v = IoMessage_locals_valueArgAt_(self, locals, n);
	IoState_error_(IOSTATE, self, "argument %i to method '%s' must be a %s, not a '%s'",
				   n, CSTRING(DATA(self)->name), typeName, IoObject_name(v));
}
Ejemplo n.º 29
0
Archivo: IoSyslog.c Proyecto: Akiyah/io
IoObject *IoSyslog_open(IoSyslog *self, IoObject *locals, IoMessage *m)
{
	/*doc Syslog open(aPriority, someOptions, optionalIdentity)
	Opens the syslog for writing. optionalIdentity need not be entered 
	and will default to the name of the distribution of Io you are running 
	or if you have embedded Io into your application and set 
	Lobby distribution = "foo", it will be set to "foo".
	*/
	 
	int syslog_facility, syslog_options;
	//int i, max;
	char *syslog_ident;

	if (DATA(self)->syslog_opened)
	{
		IoState_error_(IOSTATE, m, "System log is already open");
		return IONIL(self);
	}

	{
		DATA(self)->facility = IOREF(IoMessage_locals_numberArgAt_(m, locals, 0));
		if (ISNIL(DATA(self)->facility))
		{
			syslog_facility = LOG_USER;
		}
		else
		{
			syslog_facility = IoObject_dataUint32(DATA(self)->facility);
		}

		DATA(self)->options = IOREF(IoMessage_locals_listArgAt_(m, locals, 1));
		syslog_options = 0;
		if (ISNIL(DATA(self)->options))
		{
			syslog_options = LOG_PID | LOG_CONS;
		}
		else
		{
			List *list = IoList_rawList(DATA(self)->options);

			LIST_FOREACH(list, i, v,
				syslog_options |= (int)CNUMBER(v);
			);
		}

		syslog_ident = (char *)IOSYMBOL_BYTES(DATA(self)->ident);
		if ((strlen(syslog_ident) == 0) || ISNIL(DATA(self)->ident))
		{
			char *s = CSTRING(IoState_doCString_(IOSTATE, "Lobby distribution"));
			strncpy(syslog_ident, s, strlen(s));
		}

		openlog(syslog_ident, syslog_options, syslog_facility);
		DATA(self)->syslog_opened = 1;
		DATA(self)->syslog_mask = setlogmask(0);
		setlogmask(DATA(self)->syslog_mask);
	}
Ejemplo n.º 30
0
void IoImage_checkError(IoImage *self, IoObject *locals, IoMessage *m)
{
	const char *e = Image_error(DATA(self)->image);

	if (e != NULL)
	{
		IoState_error_(IOSTATE, m, "Image %s on %s", e, Image_path(DATA(self)->image));
	}
}