[gs-cvs] rev 6956 - trunk/gs/src

lpd at ghostscript.com lpd at ghostscript.com
Wed Aug 2 22:43:28 PDT 2006


Author: lpd
Date: 2006-08-02 22:43:28 -0700 (Wed, 02 Aug 2006)
New Revision: 6956

Modified:
   trunk/gs/src/idict.c
   trunk/gs/src/idict.h
   trunk/gs/src/zdict.c
Log:
Fixes bug: several dictionary operators (known, undef, where) did not cause
a typecheck error if the 'key' argument was a null.


Modified: trunk/gs/src/idict.c
===================================================================
--- trunk/gs/src/idict.c	2006-08-03 05:10:23 UTC (rev 6955)
+++ trunk/gs/src/idict.c	2006-08-03 05:43:28 UTC (rev 6956)
@@ -263,9 +263,7 @@
 /*
  * Look up a key in a dictionary.  Store a pointer to the value slot
  * where found, or to the (value) slot for inserting.
- * Return 1 if found, 0 if not and there is room for a new entry,
- * or e_dictfull if the dictionary is full and the key is missing.
- * The caller is responsible for ensuring key is not a null.
+ * See idict.h for the possible return values.
  */
 int
 dict_find(const ref * pdref, const ref * pkey,
@@ -553,9 +551,17 @@
     ref *pvslot;
     dict *pdict;
     uint index;
+    int code = dict_find(pdref, pkey, &pvslot);
 
-    if (dict_find(pdref, pkey, &pvslot) <= 0)
-	return (e_undefined);
+    switch (code) {
+    case 0:
+    case e_dictfull:
+	return_error(e_undefined);
+    case 1:
+	break;
+    default:			/* other error */
+	return code;
+    }
     /* Remove the entry from the dictionary. */
     pdict = pdref->value.pdict;
     index = pvslot - pdict->values.value.refs;

Modified: trunk/gs/src/idict.h
===================================================================
--- trunk/gs/src/idict.h	2006-08-03 05:10:23 UTC (rev 6955)
+++ trunk/gs/src/idict.h	2006-08-03 05:43:28 UTC (rev 6956)
@@ -124,7 +124,8 @@
 
 /*
  * Remove a key-value pair from a dictionary.
- * Return 0 or e_undefined.
+ * Return any of the same values as dict_put, except for 0 and e_dictfull
+ * which are converted to e_undefined.
  */
 int dict_undef(ref * pdref, const ref * key, dict_stack_t *pds);
 

Modified: trunk/gs/src/zdict.c
===================================================================
--- trunk/gs/src/zdict.c	2006-08-03 05:10:23 UTC (rev 6955)
+++ trunk/gs/src/zdict.c	2006-08-03 05:43:28 UTC (rev 6956)
@@ -197,10 +197,13 @@
 zundef(i_ctx_t *i_ctx_p)
 {
     os_ptr op = osp;
+    int code;
 
     check_type(op[-1], t_dictionary);
     check_dict_write(op[-1]);
-    idict_undef(op - 1, op);	/* ignore undefined error */
+    code = idict_undef(op - 1, op);
+    if (code < 0 && code != e_undefined) /* ignore undefined error */
+	return code;
     pop(2);
     return 0;
 }
@@ -212,10 +215,20 @@
     os_ptr op = osp;
     register os_ptr op1 = op - 1;
     ref *pvalue;
+    int code;
 
     check_type(*op1, t_dictionary);
     check_dict_read(*op1);
-    make_bool(op1, (dict_find(op1, op, &pvalue) > 0 ? 1 : 0));
+    code = dict_find(op1, op, &pvalue);
+    switch (code) {
+    case e_dictfull:
+	code = 0;
+    case 0: case 1:
+	break;
+    default:
+	return code;
+    }
+    make_bool(op1, code);
     pop(1);
     return 0;
 }
@@ -234,10 +247,14 @@
 	const ref *const bot = rsenum.ptr;
 	const ref *pdref = bot + rsenum.size;
 	ref *pvalue;
+	int code;
 
 	while (pdref-- > bot) {
 	    check_dict_read(*pdref);
-	    if (dict_find(pdref, op, &pvalue) > 0) {
+	    code = dict_find(pdref, op, &pvalue);
+	    if (code < 0 && code != e_dictfull)
+		return code;
+	    if (code > 0) {
 		push(1);
 		ref_assign(op - 1, pdref);
 		make_true(op);



More information about the gs-cvs mailing list