Beispiel #1
0
void* getFieldValue(int location, int type) {
    char buffer[8];
    long retval = 0;
    switch(type) {

        case INT:
            dread(buffer, location, 2);
            retval = (long) getSignedInt(buffer);
            break;

        case UINT:
            dread(buffer, location, 2);
            retval = (long) getUnsignedInt(buffer);
            break;

        case ULINT:
            dread(buffer, location, 3);
            retval = getUnsignedLong(buffer);
            break;

        case DATE:
            dread(buffer, location, 5);
            //printf("DEBUG: getFieldValue DATE[%04x] - %d %d %d %d %d\n", location, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
            retval = (long) strDate(buffer);
            break;

        case CHAR:
        default:
            dread(buffer, location, 1);
            retval = (long) buffer[0];
            break;
    }
    return (void*) retval;
}
Beispiel #2
0
AXIR AXLexer::getIR(unsigned int index, int *len){
	AXIR ir;
	unsigned short typeWord = 0;
	bool isLong = 0;
	
	typeWord = getUnsignedShort();
	ir.type   = typeWord & 0x1FFF;/* CSTYPE */
	ir.isTop  = typeWord & 0x2000;/* EXFLG_1 */
	ir.isSepr = typeWord & 0x4000;/* EXFLG_2 */
	isLong     = typeWord & 0x8000;/* If the IR code of these bytes is Long */

	if(isLong){
		ir.code = getUnsignedInt();
		*len = *len + 6;
	}else{
		ir.code = getUnsignedShort();
		*len = *len + 4;
	}

	/* TYPE_CMPCMD has an address which is for jumping to else or its end */
	if(ir.type == TYPE_CMPCMD){
		JumpToQueue rewriter;

		*len = *len + 2;

		rewriter.jumpto = index;
		ir.jump = 0;
		rewriter.bytes = getUnsignedShort() * 2 + *len;

		jumpToQueue.push_back(rewriter);
	}
	return ir;
}
Beispiel #3
0
void
rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, NativeType* paramTypes,
                      FFIStorage* paramStorage, void** ffiValues,
                      VALUE* callbackParameters, int callbackCount, VALUE enums)
{
    VALUE callbackProc = Qnil;
    FFIStorage* param = &paramStorage[0];
    int i, argidx, cbidx, argCount;

    if (paramCount != -1 && paramCount != argc) {
        if (argc == (paramCount - 1) && callbackCount == 1 && rb_block_given_p()) {
            callbackProc = rb_block_proc();
        } else {
            rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, paramCount);
        }
    }

    argCount = paramCount != -1 ? paramCount : argc;

    for (i = 0, argidx = 0, cbidx = 0; i < argCount; ++i) {
        int type = argidx < argc ? TYPE(argv[argidx]) : T_NONE;
        ffiValues[i] = param;

        switch (paramTypes[i]) {

        case NATIVE_INT8:
            param->s8 = getSignedInt(argv[argidx++], type, -128, 127, "char", Qnil);
            ADJ(param, INT8);
            break;


        case NATIVE_INT16:
            param->s16 = getSignedInt(argv[argidx++], type, -0x8000, 0x7fff, "short", Qnil);
            ADJ(param, INT16);
            break;


        case NATIVE_INT32:
        case NATIVE_ENUM:
            param->s32 = getSignedInt(argv[argidx++], type, -0x80000000, 0x7fffffff, "int", enums);
            ADJ(param, INT32);
            break;


        case NATIVE_BOOL:
            if (type != T_TRUE && type != T_FALSE) {
                rb_raise(rb_eTypeError, "wrong argument type  (expected a boolean parameter)");
            }
            param->s8 = argv[argidx++] == Qtrue;
            ADJ(param, INT8);
            break;


        case NATIVE_UINT8:
            param->u8 = getUnsignedInt(argv[argidx++], type, 0xff, "unsigned char");
            ADJ(param, INT8);
            break;


        case NATIVE_UINT16:
            param->u16 = getUnsignedInt(argv[argidx++], type, 0xffff, "unsigned short");
            ADJ(param, INT16);
            break;


        case NATIVE_UINT32:
            /* Special handling/checking for unsigned 32 bit integers */
            param->u32 = getUnsignedInt32(argv[argidx++], type);
            ADJ(param, INT32);
            break;


        case NATIVE_INT64:
            if (type != T_FIXNUM && type != T_BIGNUM) {
                rb_raise(rb_eTypeError, "Expected an Integer parameter");
            }
            param->i64 = NUM2LL(argv[argidx]);
            ADJ(param, INT64);
            ++argidx;
            break;


        case NATIVE_UINT64:
            if (type != T_FIXNUM && type != T_BIGNUM) {
                rb_raise(rb_eTypeError, "Expected an Integer parameter");
            }
            param->u64 = NUM2ULL(argv[argidx]);
            ADJ(param, INT64);
            ++argidx;
            break;

        case NATIVE_LONG:
            *(ffi_sarg *) param = NUM2LONG(argv[argidx]);
            ADJ(param, LONG);
            ++argidx;
            break;

        case NATIVE_ULONG:
            *(ffi_arg *) param = NUM2ULONG(argv[argidx]);
            ADJ(param, LONG);
            ++argidx;
            break;

        case NATIVE_FLOAT32:
            if (type != T_FLOAT && type != T_FIXNUM) {
                rb_raise(rb_eTypeError, "Expected a Float parameter");
            }
            param->f32 = (float) NUM2DBL(argv[argidx]);
            ADJ(param, FLOAT32);
            ++argidx;
            break;

        case NATIVE_FLOAT64:
            if (type != T_FLOAT && type != T_FIXNUM) {
                rb_raise(rb_eTypeError, "Expected a Float parameter");
            }
            param->f64 = NUM2DBL(argv[argidx]);
            ADJ(param, FLOAT64);
            ++argidx;
            break;


        case NATIVE_STRING:
            param->ptr = getString(argv[argidx++], type);
            ADJ(param, ADDRESS);
            break;

        case NATIVE_POINTER:
        case NATIVE_BUFFER_IN:
        case NATIVE_BUFFER_OUT:
        case NATIVE_BUFFER_INOUT:
            param->ptr = getPointer(argv[argidx++], type);
            ADJ(param, ADDRESS);
            break;


        case NATIVE_FUNCTION:
        case NATIVE_CALLBACK:
            if (callbackProc != Qnil) {
                param->ptr = callback_param(callbackProc, callbackParameters[cbidx++]);
            } else {
                param->ptr = callback_param(argv[argidx], callbackParameters[cbidx++]);
                ++argidx;
            }
            ADJ(param, ADDRESS);
            break;

        case NATIVE_STRUCT:
            ffiValues[i] = getPointer(argv[argidx++], type);
            break;

        default:
            rb_raise(rb_eArgError, "Invalid parameter type: %d", paramTypes[i]);
        }
    }
}
Beispiel #4
0
static long
rbffi_GetLongValue(int idx, VALUE* argv, FunctionType* fnInfo)
{
    VALUE value = argv[idx];
    NativeType nativeType = fnInfo->nativeParameterTypes[idx];
    int type = TYPE(value);

    switch (nativeType) {
    case NATIVE_INT8:
        return getSignedInt(value, type, -128, 127, "char", fnInfo->rbEnums);

    case NATIVE_INT16:
        return getSignedInt(value, type, -0x8000, 0x7fff, "short", fnInfo->rbEnums);

    case NATIVE_INT32:
    case NATIVE_ENUM:
        return getSignedInt(value, type, -0x80000000, 0x7fffffff, "int", fnInfo->rbEnums);

    case NATIVE_BOOL:
        if (type != T_TRUE && type != T_FALSE) {
            rb_raise(rb_eTypeError, "Expected a Boolean parameter");
        }
        return RTEST(value) ? 1 : 0;

    case NATIVE_UINT8:
        return getUnsignedInt(value, type, 0xff, "unsigned char");

    case NATIVE_UINT16:
        return getUnsignedInt(value, type, 0xffff, "unsigned short");

    case NATIVE_UINT32:
        /* Special handling/checking for unsigned 32 bit integers */
        return getUnsignedInt32(value, type);

    case NATIVE_LONG:
        return NUM2LONG(value);

    case NATIVE_ULONG:
        return NUM2ULONG(value);

#ifdef __x86_64__
    case NATIVE_INT64:
        if (type != T_FIXNUM && type != T_BIGNUM) {
            rb_raise(rb_eTypeError, "Expected an Integer parameter");
        }
        return NUM2LL(value);

    case NATIVE_UINT64:
        if (type != T_FIXNUM && type != T_BIGNUM) {
            rb_raise(rb_eTypeError, "Expected an Integer parameter");
        }
        return NUM2ULL(value);
#endif
    case NATIVE_STRING:
        return (intptr_t) getString(value, type);

    case NATIVE_POINTER:
    case NATIVE_BUFFER_IN:
    case NATIVE_BUFFER_OUT:
    case NATIVE_BUFFER_INOUT:
        return (intptr_t) getPointer(value, type);

    default:
        rb_raise(rb_eTypeError, "unsupported integer type %d", nativeType);
        return 0;
    }
}
Beispiel #5
0
unsigned int getInterval() {
    char buffer[2];

    dread(buffer, L_INTERVAL, 2);
    return getUnsignedInt(buffer);
}
Beispiel #6
0
unsigned int getRecordsStored() {
    char buffer[2];

    dread(buffer, L_RECORDS, 2);
    return getUnsignedInt(buffer);
}
Beispiel #7
0
unsigned int getLocationOfCurrent() {
    char buffer[2];

    dread(buffer, L_CURRENT, 2);
    return getUnsignedInt(buffer);
}