# New Ticket Created by  Leopold Toetsch 
# Please include the string:  [perl #17524]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=17524 >


This patch hides some internals of keys by using the appropriate key 
functions in packfile.c. Packfile shouldn't know keys internals.

Please apply,
TIA leo

PS If accepted, a similar patch for packout.c will follow.


-- attachment  1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/38314/31186/1338d1/packfile-keys.patch

--- parrot/packfile.c   Tue Aug 20 07:06:07 2002
+++ parrot-leo/packfile.c       Mon Sep 23 15:52:06 2002
@@ -980,43 +980,38 @@
 
     while (components-- > 0) {
         if (tail) {
-            tail->data = pmc_new(interpreter, enum_class_Key);
+            tail->data = key_new(interpreter);
             tail = tail->data;
         }
         else {
-            head = tail = pmc_new(interpreter, enum_class_Key);
+            head = tail = key_new(interpreter);
         }
 
         tail->flags |= PMC_constant_FLAG;
         
         switch (*cursor++) {
         case PARROT_ARG_IC:
-            tail->flags |= KEY_integer_FLAG;
-            tail->cache.int_val = *cursor++;
+            key_set_integer(interpreter, tail, *cursor++);
             break;
         case PARROT_ARG_NC:
-            tail->flags |= KEY_number_FLAG;
-            tail->cache.num_val = pf->const_table->constants[*cursor++]->number;
+            key_set_number(interpreter, tail,
+                    pf->const_table->constants[*cursor++]->number);
             break;
         case PARROT_ARG_SC:
-            tail->flags |= KEY_string_FLAG;
-            tail->cache.string_val = pf->const_table->constants[*cursor++]->string;
+            key_set_string(interpreter, tail,
+                pf->const_table->constants[*cursor++]->string);
             break;
         case PARROT_ARG_I:
-            tail->flags |= KEY_integer_FLAG|KEY_register_FLAG;
-            tail->cache.int_val = *cursor++;
+            key_set_register(interpreter, tail, *cursor++, KEY_integer_FLAG);
             break;
         case PARROT_ARG_N:
-            tail->flags |= KEY_number_FLAG|KEY_register_FLAG;
-            tail->cache.int_val = *cursor++;
+            key_set_register(interpreter, tail, *cursor++, KEY_number_FLAG);
             break;
         case PARROT_ARG_S:
-            tail->flags |= KEY_string_FLAG|KEY_register_FLAG;
-            tail->cache.int_val = *cursor++;
+            key_set_register(interpreter, tail, *cursor++, KEY_string_FLAG);
             break;
         case PARROT_ARG_P:
-            tail->flags |= KEY_pmc_FLAG|KEY_register_FLAG;
-            tail->cache.int_val = *cursor++;
+            key_set_register(interpreter, tail, *cursor++, KEY_pmc_FLAG);
             break;
         default:
             return 0;
--- parrot/key.c        Sat Aug 24 09:24:16 2002
+++ parrot-leo/key.c    Mon Sep 23 15:47:59 2002
@@ -76,6 +76,17 @@
     return;
 }
 
+void
+key_set_register(struct Parrot_Interp *interpreter, PMC *key, INTVAL value,
+        INTVAL flag)
+{
+    key->flags &= ~KEY_type_FLAGS;
+    key->flags |= KEY_register_FLAG | flag;
+    key->cache.int_val = value;
+
+    return;
+}
+
 
 void
 key_set_number(struct Parrot_Interp *interpreter, PMC *key, FLOATVAL value)
--- parrot/include/parrot/key.h Tue Aug 20 07:06:08 2002
+++ parrot-leo/include/parrot/key.h     Mon Sep 23 15:48:47 2002
@@ -37,6 +37,8 @@
 
 void key_set_integer(struct Parrot_Interp *interpreter, PMC *key, INTVAL value);
 void key_set_number(struct Parrot_Interp *interpreter, PMC *key, FLOATVAL value);
+void key_set_register(struct Parrot_Interp *interpreter, PMC *key, INTVAL value,
+        INTVAL flag);
 void key_set_string(struct Parrot_Interp *interpreter, PMC *key, STRING *value);
 void key_set_pmc(struct Parrot_Interp *interpreter, PMC *key, PMC *value);
 

Reply via email to