rev 234 - trunk/src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: bcollins
Date: 2004-03-31 11:38:50 -0500 (Wed, 31 Mar 2004)
New Revision: 234

Modified:
   trunk/src/builtins.c
Log:
Make use of some new macros.

Also fix segv when doing dict.__getitem__(notlist).


Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c	2004-03-31 16:37:59 UTC (rev 233)
+++ trunk/src/builtins.c	2004-03-31 16:38:50 UTC (rev 234)
@@ -458,6 +458,9 @@
 	int i, index1 = 0, index2 = 0, index3 = 0, slice1_empty=FALSE, slice2_empty=FALSE;
 	int exp_len, self_len, slice_len = list_len(ist, slice);
 	char* self_str = NULL;
+
+	CHECK_TYPE_EXC(self, OBJ(SEQ_PROTO), "sequence");
+
 	if (seq_type == SEQ_TYPE_STRING) {
 		self_len = (int) pr_strlen(self);
 		self_str = strch(self);
@@ -467,10 +470,8 @@
 	if (slice_item1 == SLICEPARAM_EMPTY || slice_item1 == OBJ(NONE)) 
 		slice1_empty=TRUE;
 	else {
-		if (!has_proto_QUES(ist, slice_item1, OBJ(INT_PROTO))) {
-			raise_exception(ist, OBJ(TYPE_EXC), "sequence slice index must be an integer");
-			return NULL;
-		}
+		CHECK_TYPE_EXC(slice_item1, OBJ(INT_PROTO), "integer");
+
 		index1 = (int)(slice_item1->data.i64);
 		if (index1 < 0) index1 += self_len;						
 		if (index1 < 0 || index1 >= self_len) {			
@@ -488,10 +489,8 @@
 		slice_item3 = list_item(ist, slice,2);
 		if (slice_item3 == SLICEPARAM_EMPTY || slice_item3 == OBJ(NONE)) index3 = 1;
 		else {
-			if (!has_proto_QUES(ist, slice_item3, OBJ(INT_PROTO))) {
-				raise_exception(ist, OBJ(TYPE_EXC), "sequence slice index must be an integer");
-				return NULL;
-			}
+			CHECK_TYPE_EXC(slice_item3, OBJ(INT_PROTO), "integer");
+
 			index3 = (int)(slice_item3->data.i64);
 			if (index3 == 0) {
 				raise_exception(ist, OBJ(INDEX_EXC), "Slice step cannot be zero");		
@@ -503,10 +502,8 @@
 	if (slice_item2 == SLICEPARAM_EMPTY || slice_item2 == OBJ(NONE))
 		slice2_empty=TRUE;
 	else {
-		if (!has_proto_QUES(ist, slice_item2, OBJ(INT_PROTO))) {
-			raise_exception(ist, OBJ(TYPE_EXC), "sequence slice index must be an integer");
-			return NULL;
-		}
+		CHECK_TYPE_EXC(slice_item2, OBJ(INT_PROTO), "integer");
+
 		index2 = (int)(slice_item2->data.i64);
 		if (index2 < 0) index2 += self_len;						
 		if (index2 < 0 || index2 > self_len) {			
@@ -1223,6 +1220,9 @@
 
 DEF(Dict, __getitem__, FORM_RPARAM) {
 	obj_p res;
+
+	CHECK_TYPE_EXC(parms[1], OBJ(SEQ_PROTO), "list");
+
 	if (list_len(ist, parms[1]) > 1) {
 		raise_exception(ist, OBJ(INTERPRETER_EXC), "slice not allowed in dictionary indexing");	
 		return NULL;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.