コード例 #1
0
ファイル: IoCFFIArray.c プロジェクト: bomma/io
IoCFFIArray *IoCFFIArray_rawSetValue(IoCFFIArray *self, IoObject *source, void* data)
{
	if ( !ISCFFIArray(source) ) {
		IoState_error_(IOSTATE, NULL, "value is not an Array");
		return IONIL(self);
	}
	else {
		if ( DATA(self)->ffiType.size != DATA(source)->ffiType.size) {
			IoState_error_(IOSTATE, NULL, "Arrays have differente sizes");
			return IONIL(self);
		}
		else {
			memcpy(DATA(self)->buffer, data, DATA(self)->ffiType.size);
			DATA(self)->keepRef = IOREF(source);
		}
	}

	return self;
}
コード例 #2
0
ファイル: IoCFFIPointer.c プロジェクト: akimd/io
IoObject *IoCFFIPointer_value(IoCFFIPointer *self, IoObject *locals, IoMessage *m)
{
	IoObject *pointedToType;
	IoCFFIPointer *pointer;
	char *typeString, *cp, c;

	if (*(DATA(self)->valuePointer) == NULL)
	{
		//IoState_error_(IOSTATE, m, "attempt to dereference NULL pointer");
		return IONIL(self);
	}

    typeString = CSTRING(IoState_on_doCString_withLabel_(IOSTATE, self, "typeString", "IoCFFIPointer_value"));

    pointedToType = IoObject_getSlot_(self, IOSYMBOL("pointedToType"));

	if (ISCFFIPointer(pointedToType))
	{
		// we are a pointer to a pointer, so return a new Pointer
		// that points to the address of our ptr dereferenced

		cp = strrchr(typeString, '^');
		switch (c = *(++cp))
		{

#define IoCFFIPointer_value_SET_DATA_PTR(cType) \
	pointer = IOCLONE(IoCFFIPointer_ToType_(IoObject_getSlot_(pointedToType, IOSYMBOL("pointedToType")))); \
	*(DATA(pointer)->valuePointer) = *((cType **)(*(DATA(self)->valuePointer))); break
	//DATA(pointer)->ptr = *((cType **)(DATA(self)->ptr)); break

			case 'c':
			case 'b':
				IoCFFIPointer_value_SET_DATA_PTR(char);
			case 'C':
			case 'B':
				IoCFFIPointer_value_SET_DATA_PTR(unsigned char);
			case 's':
				IoCFFIPointer_value_SET_DATA_PTR(short);
			case 'S':
				IoCFFIPointer_value_SET_DATA_PTR(unsigned short);
			case 'i':
				IoCFFIPointer_value_SET_DATA_PTR(int);
			case 'I':
				IoCFFIPointer_value_SET_DATA_PTR(unsigned int);
			case 'l':
				IoCFFIPointer_value_SET_DATA_PTR(long);
			case 'L':
				IoCFFIPointer_value_SET_DATA_PTR(unsigned long);
			case 'f':
				IoCFFIPointer_value_SET_DATA_PTR(float);
			case 'd':
				IoCFFIPointer_value_SET_DATA_PTR(double);
			case '*':
				IoCFFIPointer_value_SET_DATA_PTR(char *);
			case '{':
			case '(':
			case '&':
			case '[':
			case 'v':
				IoCFFIPointer_value_SET_DATA_PTR(void);

#undef IoCFFIPointer_value_SET_DATA_PTR

			//case 'v':
			//	IoState_error_(IOSTATE, m, "attempt to dereference a void pointer");
			//	return IONIL(self);

			default:
				IoState_error_(IOSTATE, m, "unknown character '%c' in Pointer typeString", c);
				return IONIL(self);
			}
			return pointer;
	}
	else if(ISCFFIDataType(pointedToType) || ISCFFIStructure(pointedToType) || ISCFFIFunction(pointedToType) || ISCFFIArray(pointedToType))
	{
		return IoCFFIDataType_objectFromData_(pointedToType, *(DATA(self)->valuePointer));
	}
    else
	{
		IoState_error_(IOSTATE, m, "attempt to dereference Pointer object whose pointedToType is unknown.");
		return IONIL(self);
	}
}