added FMTC_BLOB in mod/ffi.c
This commit is contained in:
		@ -272,7 +272,7 @@ static int is_normalized_integer (moo_t* moo, moo_oop_t oop)
 | 
			
		||||
			sz = MOO_OBJ_GET_SIZE(oop);
 | 
			
		||||
			MOO_ASSERT (moo, sz >= 1);
 | 
			
		||||
 | 
			
		||||
			return MOO_OBJ_GET_LIWORD_SLOT(oop)[sz - 1] == 0? 0: 1;
 | 
			
		||||
			return MOO_OBJ_GET_LIWORD_VAL(oop, sz - 1) == 0? 0: 1;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -590,7 +590,7 @@ static MOO_INLINE moo_oop_t make_bloated_bigint_with_ooi (moo_t* moo, moo_ooi_t
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!z) return MOO_NULL;
 | 
			
		||||
	MOO_OBJ_GET_LIWORD_SLOT(z)[0] = w;
 | 
			
		||||
	MOO_OBJ_SET_LIWORD_VAL (z, 0, w);
 | 
			
		||||
	return z;
 | 
			
		||||
 | 
			
		||||
#elif (MOO_LIW_BITS == MOO_OOHW_BITS)
 | 
			
		||||
@ -616,8 +616,8 @@ static MOO_INLINE moo_oop_t make_bloated_bigint_with_ooi (moo_t* moo, moo_ooi_t
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!z) return MOO_NULL;
 | 
			
		||||
	MOO_OBJ_GET_LIWORD_SLOT(z)[0] = hw[0];
 | 
			
		||||
	if (hw[1] > 0) MOO_OBJ_GET_LIWORD_SLOT(z)[1] = hw[1];
 | 
			
		||||
	MOO_OBJ_SET_LIWORD_VAL (z, 0, hw[0]);
 | 
			
		||||
	if (hw[1] > 0) MOO_OBJ_SET_LIWORD_VAL (z, 1, hw[1]);
 | 
			
		||||
	return z;
 | 
			
		||||
#else
 | 
			
		||||
#	error UNSUPPORTED LIW BIT SIZE
 | 
			
		||||
@ -694,7 +694,7 @@ static MOO_INLINE moo_oop_t expand_bigint (moo_t* moo, moo_oop_t oop, moo_oow_t
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < count; i++)
 | 
			
		||||
	{
 | 
			
		||||
		MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(oop)[i];
 | 
			
		||||
		MOO_OBJ_SET_LIWORD_VAL (z, i, MOO_OBJ_GET_LIWORD_VAL(oop, i));
 | 
			
		||||
	}
 | 
			
		||||
	return z;
 | 
			
		||||
}
 | 
			
		||||
@ -715,7 +715,7 @@ static MOO_INLINE moo_oop_t _clone_bigint (moo_t* moo, moo_oop_t oop, moo_oow_t
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < count; i++)
 | 
			
		||||
	{
 | 
			
		||||
		MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(oop)[i];
 | 
			
		||||
		MOO_OBJ_SET_LIWORD_VAL (z, i, MOO_OBJ_GET_LIWORD_VAL(oop, i));
 | 
			
		||||
	}
 | 
			
		||||
	return z;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -59,6 +59,7 @@
 | 
			
		||||
#define FMTC_LONGLONG 'L'
 | 
			
		||||
#define FMTC_BCS 's'
 | 
			
		||||
#define FMTC_UCS 'S'
 | 
			
		||||
#define FMTC_BLOB 'b'
 | 
			
		||||
#define FMTC_POINTER 'p'
 | 
			
		||||
 | 
			
		||||
typedef struct link_t link_t;
 | 
			
		||||
@ -419,9 +420,6 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
 | 
			
		||||
			break;
 | 
			
		||||
		#endif
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
		case 'B': /* byte array */
 | 
			
		||||
#endif
 | 
			
		||||
		case FMTC_BCS:
 | 
			
		||||
		{
 | 
			
		||||
			moo_bch_t* ptr;
 | 
			
		||||
@ -472,6 +470,22 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		case FMTC_BLOB:
 | 
			
		||||
		{
 | 
			
		||||
			void* ptr;
 | 
			
		||||
 | 
			
		||||
			if (MOO_OBJ_IS_BYTE_POINTER(arg)) goto inval_arg_value;
 | 
			
		||||
			ptr = MOO_OBJ_GET_BYTE_SLOT(arg);
 | 
			
		||||
 | 
			
		||||
		#if defined(USE_DYNCALL)
 | 
			
		||||
			dcArgPointer (ffi->dc, ptr);
 | 
			
		||||
		#elif defined(USE_LIBFFI)
 | 
			
		||||
			ffi->arg_values[ffi->arg_count] = &ffi->arg_svs[ffi->arg_count].p;
 | 
			
		||||
			ffi->arg_svs[ffi->arg_count].p = ptr;
 | 
			
		||||
		#endif
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		case FMTC_POINTER:
 | 
			
		||||
		{
 | 
			
		||||
			void* ptr;
 | 
			
		||||
@ -570,6 +584,10 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
	for (i = 0, j = 0, nfixedargs = 0; i < MOO_OBJ_GET_SIZE(sig); i++)
 | 
			
		||||
	{
 | 
			
		||||
		fmtc = MOO_OBJ_GET_CHAR_VAL(sig, i);
 | 
			
		||||
		if (fmtc == ' ')
 | 
			
		||||
		{
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (fmtc == '>') 
 | 
			
		||||
		{
 | 
			
		||||
			i++;
 | 
			
		||||
@ -598,9 +616,9 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
		j++;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	while (i < MOO_OBJ_GET_SIZE(sig) && MOO_OBJ_GET_CHAR_VAL(sig, i) == ' '); /* skip all spaces after > */
 | 
			
		||||
	fmtc = (i >= MOO_OBJ_GET_SIZE(sig)? FMTC_NULL: MOO_OBJ_GET_CHAR_VAL(sig, i));
 | 
			
		||||
#if defined(USE_LIBFFI)
 | 
			
		||||
/* TODO: handle unsigned */
 | 
			
		||||
	fs = (nfixedargs == j)? ffi_prep_cif(&ffi->cif, FFI_DEFAULT_ABI, j, ffi->fmtc_to_type[0][fmtc], ffi->arg_types):
 | 
			
		||||
	                        ffi_prep_cif_var(&ffi->cif, FFI_DEFAULT_ABI, nfixedargs, j, ffi->fmtc_to_type[0][fmtc], ffi->arg_types);
 | 
			
		||||
	if (fs != FFI_OK)
 | 
			
		||||
@ -617,6 +635,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
	{
 | 
			
		||||
/* TODO: support more types... */
 | 
			
		||||
/* TODO: proper return value conversion */
 | 
			
		||||
/* TODO: handle unsigned */
 | 
			
		||||
		case FMTC_CHAR:
 | 
			
		||||
		{
 | 
			
		||||
		#if defined(USE_DYNCALL)
 | 
			
		||||
@ -747,6 +766,17 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
		case FMTC_BLOB:
 | 
			
		||||
		{
 | 
			
		||||
			/* blob as a return type isn't sufficient as it lacks the size information. 
 | 
			
		||||
			 * blob as an argument is just a pointer and the size can be yet another argument.
 | 
			
		||||
			 * it there a good way to represent this here?... TODO: */
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		case FMTC_POINTER:
 | 
			
		||||
		{
 | 
			
		||||
			void* r;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user