2
0
Эх сурвалжийг харах

Added array index bounds check function.

woollybah 10 жил өмнө
parent
commit
10f60b2100

+ 5 - 0
blitz.mod/blitz_array.c

@@ -302,6 +302,11 @@ BBArray *bbArrayDimensions( BBArray *arr ){
 	return dims;
 }
 
+void * bbArrayIndex( BBArray * arr, int offset, int index) {
+	if (index >= arr->scales[0]) brl_blitz_ArrayBoundsError();
+	return BBARRAYDATA(arr, offset);
+}
+
 BBArray *bbArrayCastFromObject( BBObject *o,const char *type ){
 	BBArray *arr=(BBArray*)o;
 	if( arr==&bbEmptyArray ) return arr;

+ 3 - 0
blitz.mod/blitz_array.h

@@ -17,6 +17,7 @@ extern "C"{
 #define BBARRAYSIZE(q,n) ((2*sizeof(void*)+8)+(n)*sizeof(int)+(q))
 #define BBARRAYDATA(p,n) ((void*)((char*)(p)+(2*sizeof(void*)+8)+(n)*sizeof(int)))
 #endif
+#define BBARRAYDATAINDEX(p,n,i) bbArrayIndex(p,n,i)
 
 struct BBArray{
 	//extends BBObject
@@ -47,6 +48,8 @@ BBArray*	bbArrayDimensions( BBArray *arr );
 
 BBArray*	bbArrayConcat( const char *type,BBArray *x,BBArray *y );
 
+void*	bbArrayIndex( BBArray *, int, int );
+
 #ifdef __cplusplus
 }
 #endif