Beispiel #1
0
VALUE
rb_str_ends_with_p( VALUE str, VALUE oth)
{
    long i;
    char *s, *o;
    VALUE ost;

#ifdef HAVE_HEADER_RUBY_H
#else
    if (!rb_str_comparable( str, oth))
        return Qnil;
#endif
    ost = rb_string_value( &oth);
    i = RSTRING_LEN( ost);
    if (i > RSTRING_LEN( str))
        return Qnil;
    s = RSTRING_END( str);
    o = RSTRING_END( ost);
    for (; i; i--)
        if (*--s != *--o)
            return Qnil;
#ifdef HAVE_HEADER_RUBY_H
    return INT2FIX( RSTRING_LEN( str) - RSTRING_LEN( ost));
#else
    return INT2FIX( rb_str_strlen( str) - rb_str_strlen( ost));
#endif
}
Beispiel #2
0
VALUE
rb_str_starts_with_p( VALUE str, VALUE oth)
{
    long i;
    char *s, *o;
    VALUE ost;

#ifdef HAVE_HEADER_RUBY_H
#else
    if (!rb_str_comparable( str, oth))
        return Qnil;
#endif
    ost = rb_string_value( &oth);
    i = RSTRING_LEN( ost);
    if (i > RSTRING_LEN( str))
        return Qnil;
    s = RSTRING_PTR( str);
    o = RSTRING_PTR( ost);
    for (; i; i--, s++, o++) {
        if (*s != *o)
            return Qnil;
    }
#ifdef HAVE_HEADER_RUBY_H
    return INT2FIX( RSTRING_LEN( ost));
#else
    return INT2FIX( rb_str_strlen( ost));
#endif
}
Beispiel #3
0
static int hash_to_zval(VALUE key, VALUE value, VALUE zval_array) {
    zval *v;
    zval *ary;

    if (key == Qundef) {
        return ST_CONTINUE;
    }

    ary = (zval *)zval_array;
    v = value_to_zval(value);

    if (key == Qtrue) {
        zend_hash_index_update(Z_ARRVAL_P(ary), 1, &v, sizeof(zval *), NULL);
        return ST_CONTINUE;
    }

    if (key == Qfalse || key == Qnil) {
        zend_hash_index_update(Z_ARRVAL_P(ary), 0, &v, sizeof(zval *), NULL);
        return ST_CONTINUE;
    }

    if (TYPE(key) == T_FIXNUM) {
        int idx = FIX2INT(key);
        zend_hash_index_update(Z_ARRVAL_P(ary), idx, &v, sizeof(zval *), NULL);
        return ST_CONTINUE;
    }

    switch (TYPE(key)) {
        case T_BIGNUM:
            key = rb_big2str(key, 10);
            break;
        case T_SYMBOL:
            key = rb_sym_to_s(key);
            break;
        case T_STRING:
            key = rb_string_value(&key);
            break;
        default:
            rb_raise(rb_eRuntimeError, "invalid key (%d)", TYPE(key));
    }

    //ZEND_HANDLE_NUMERIC(RSTRING_PTR(key), RSTRING_LEN(key), zend_hash_index_update(Z_ARRVAL_P(ary), idx, &v, sizeof(zval *), NULL));
    zend_symtable_update(Z_ARRVAL_P(ary), RSTRING_PTR(key), RSTRING_LEN(key) + 1, &v, sizeof(zval *), NULL);

    return ST_CONTINUE;
}
Beispiel #4
0
VALUE CRbWin32API::call(int argc, VALUE * argv, VALUE obj)
{
	struct 
	{
		u32 params[16];
	} param;

	VALUE obj_proc		= rb_iv_get(obj, "__proc__");
	VALUE obj_import	= rb_iv_get(obj, "__import__");
	VALUE obj_export	= rb_iv_get(obj, "__export__");
	FARPROC ApiFunction	= (FARPROC)rb_num2ulong(obj_proc);

	VALUE args;

	int items	= rb_scan_args(argc, argv, "0*", &args);
	int nimport	= RARRAY_LEN(obj_import);

	if (items != nimport)
		rb_raise(rb_eSinError, "wrong number of parameters: expected %d, got %d", nimport, items);

	for (int i = 0; i < nimport; ++i) 
	{
		u32 lParam = 0;
		switch (FIX2INT(rb_ary_entry(obj_import, i))) 
		{
			VALUE str;
		case _T_NUMBER:
		case _T_INTEGER:
		default:
			lParam = rb_num2ulong(rb_ary_entry(args, i));
			break;
		case _T_POINTER:
			str = rb_ary_entry(args, i);
			if (NIL_P(str)) 
			{
				lParam = 0;
			} 
			else if (FIXNUM_P(str))
			{
				lParam = rb_num2ulong(str);
			} 
			else 
			{
				rb_string_value(&str);
				rb_str_modify(str);
				lParam = (u32)rb_string_value_ptr(&str);
			}
			break;
		}
		param.params[i] = lParam;
	}

	u32 retval;

	__try
	{
		__asm
		{
			mov			ebx, esp
			sub			esp, 40h
			mov			ecx, 10h
			lea			esi, [param]
			mov			edi, esp
			rep movs	dword ptr es:[edi], dword ptr [esi] 
			call        dword ptr [ApiFunction] 
			mov         esp, ebx
			mov         dword ptr [retval], eax 
		}
	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		rb_raise(rb_eSinError, "Api Crashed...");
	}

	switch (FIX2INT(obj_export)) 
	{
	case _T_NUMBER:
	case _T_INTEGER:
		return rb_int2inum(retval);
	case _T_POINTER:
		return (retval ? rb_str_new2((char *)retval) : Qnil);
	case _T_VOID:
	default:
		return INT2FIX(0);
	}
}