Commits

Barry Warsaw committed 12dc638 Draft

hashCode(): throw a TypeError so lists cannot be used as keys in
dictionaries. This fixes PR#119, but is controversial because I'm not
sure this won't have unintended side-effects.

Make ivars `list' and `length' protected instead of public, so that
they are not accessible from Python. Controversial because I'm not
sure this won't have unintended side-effects. There should be a
better way to hide selective attributes from Python.

some code reformatting

  • Participants
  • Parent commits ca72c05

Comments (0)

Files changed (1)

org/python/core/PyList.java

 // Copyright Š Corporation for National Research Initiatives
 package org.python.core;
+
 import java.util.Vector;
 
-class ListFunctions extends PyBuiltinFunctionSet {
-    /*public PyObject __call__() {
-      switch(index) {
-      case 4:
-      return __builtin__.globals();
-      default:
-      throw argCountError(0);
-      }
-      }    
-      public PyObject __call__(PyObject arg1) {
-      switch(index) {
-      case 0:
-      return Py.newString(__builtin__.chr(Py.py2int(arg1, "chr(): 1st arg can't be coerced to int")));
-      case 1:
-      return Py.newInteger(__builtin__.len(arg1));
-      case 2:
-      return __builtin__.range(Py.py2int(arg1, "range(): 1st arg can't be coerced to int"));
-      case 3:
-      return Py.newInteger(__builtin__.ord(Py.py2char(arg1, "ord(): 1st arg can't be coerced to char")));
-      case 5:
-      return __builtin__.hash(arg1);
-      case 7:
-      return __builtin__.list(arg1);
-      case 8:
-      return __builtin__.tuple(arg1);
-      default:
-      throw argCountError(1);
-      }
-      }*/
+
+class ListFunctions extends PyBuiltinFunctionSet
+{
+//     public PyObject __call__() {
+//         switch(index) {
+//         case 4:
+//             return __builtin__.globals();
+//         default:
+//             throw argCountError(0);
+//         }
+//     }
+//     public PyObject __call__(PyObject arg1) {
+//         switch(index) {
+//         case 0:
+//             return Py.newString(__builtin__.chr(
+//                 Py.py2int(arg1, "chr(): 1st arg can't be coerced to int")));
+//         case 1:
+//             return Py.newInteger(__builtin__.len(arg1));
+//         case 2:
+//             return __builtin__.range(
+//                 Py.py2int(arg1, "range(): 1st arg can't be coerced to int"));
+//         case 3:
+//             return Py.newInteger(__builtin__.ord(
+//                 Py.py2char(arg1, "ord(): 1st arg can't be coerced to char")));
+//         case 5:
+//             return __builtin__.hash(arg1);
+//         case 7:
+//             return __builtin__.list(arg1);
+//         case 8:
+//             return __builtin__.tuple(arg1);
+//         default:
+//             throw argCountError(1);
+//         }
+//     }
+
     public PyObject __call__(PyObject arg1, PyObject arg2) {
         switch(index) {
         case 0:
             throw argCountError(2);
         }
     }
-    /*public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) {
-      switch(index) {
-      case 2:
-      return __builtin__.range(
-      Py.py2int(arg1, "range(): 1st arg can't be coerced to int"),
-      Py.py2int(arg2, "range(): 2nd arg can't be coerced to int"),
-      Py.py2int(arg3, "range(): 3rd arg can't be coerced to int"));
-      default:
-      throw argCountError(3);
-      }
-      }*/
+
+//     public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) {
+//         switch(index) {
+//         case 2:
+//             return __builtin__.range(
+//                 Py.py2int(arg1, "range(): 1st arg can't be coerced to int"),
+//                 Py.py2int(arg2, "range(): 2nd arg can't be coerced to int"),
+//                 Py.py2int(arg3, "range(): 3rd arg can't be coerced to int"));
+//         default:
+//             throw argCountError(3);
+//         }
+//     }
 }
 
 
-public class PyList extends PySequence implements InitModule {
+
+public class PyList extends PySequence implements InitModule
+{
     public void initModule(PyObject dict) {
-        //dict.__setitem__("append", new ListFunctions().init("append", 0, 2, true) );
+//         dict.__setitem__("append",
+//                          new ListFunctions().init("append", 0, 2, true) );
     }
     
-    public PyObject[] list;
-    public int length;
+    protected PyObject[] list;
+    protected int length;
     
     public PyList() {
         this(Py.EmptyObjects);
             resize(newLength);
             System.arraycopy(list, stop, list, stop+(newLength-length),
                              length-stop);
-        } /*else if (newLength < length) {
-            System.arraycopy(list, stop, list, stop+(newLength-length), length-stop);
-            this.length = newLength;
-            }*/
+        }
+//         else if (newLength < length) {
+//             System.arraycopy(list, stop, list, stop+(newLength-length),
+//                              length-stop);
+//             this.length = newLength;
+//         }
 
         PyObject[] otherList = null;
+
         if (value instanceof PyTuple)
             otherList = ((PyTuple)value).list;
         if (value instanceof PyList) {
             if (otherList == list)
                 otherList = (PyObject[])otherList.clone();;
         }
-
         if (otherList != null) {
             System.arraycopy(otherList, 0, list, start, n);
         }
        This function will almost certainly go away with the builtin sorting
        provided by JDK 1.2 */
 
-
     /* New quicksort implementation for arrays of object pointers.
        Thanks to discussions with Tim Peters. */
 
-
     /* Comparison function.  Takes care of calling a user-supplied
        comparison function (any callable Python object).  Calls the
        standard comparison function, cmpobject(), if the user-supplied
     protected PyClass getPyClass() {
         return __class__;
     }
+
+    public int hashCode() {
+        throw Py.TypeError("unhashable type");
+    }
 }