initial merge
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 7 Jun 2007 04:01:58 +0000 (21:01 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 7 Jun 2007 04:01:58 +0000 (21:01 -0700)
1  2 
Cython/Compiler/Code.py
Cython/Compiler/ExprNodes.py
Cython/Compiler/Nodes.py
Cython/Compiler/Parsing.py
Cython/Compiler/PyrexTypes.py
Cython/Compiler/Symtab.py

Simple merge
index bb566a9828223dac86b956e1a95beee22a01be59,0456342bbc16a98e1b784983202ef0e6de1481ef..62b085c31b6f9b923777a8ae75cbaee2211b28be
@@@ -1142,46 -1072,21 +1146,46 @@@ class IndexNode(ExprNode)
      def generate_assignment_code(self, rhs, code):
          self.generate_subexpr_evaluation_code(code)
          if self.type.is_pyobject:
 -            code.putln(
 -                "if (PyObject_SetItem(%s, %s, %s) < 0) %s" % (
 -                    self.base.py_result(),
 -                    self.index.py_result(),
 -                    rhs.py_result(),
 -                    code.error_goto(self.pos)))
 +            if self.index.type.is_int:
 +                code.putln("if (PyList_CheckExact(%s) && 0 <= %s && %s < PyList_GET_SIZE(%s)) {" % (
 +                        self.base.py_result(),
 +                        self.index.result_code,
 +                        self.index.result_code,
 +                        self.base.py_result()))
 +                code.putln("Py_DECREF(PyList_GET_ITEM(%s, %s)); Py_INCREF(%s);" % (
 +                        self.base.py_result(),
 +                        self.index.result_code,
 +                        rhs.py_result()))
 +                code.putln("PyList_SET_ITEM(%s, %s, %s);" % (
 +                        self.base.py_result(),
 +                        self.index.result_code,
 +                        rhs.py_result()))
 +                code.putln("} else {")
 +                self.generate_generic_assignment_code(rhs, code)
 +                code.putln("}")
 +            else:
 +                self.generate_generic_assignment_code(rhs, code)
-             self.generate_subexpr_disposal_code(code)
          else:
              code.putln(
                  "%s = %s;" % (
                      self.result_code, rhs.result_code))
+         self.generate_subexpr_disposal_code(code)
          rhs.generate_disposal_code(code)
      
 +    def generate_generic_assignment_code(self, rhs, code):
 +        self.py_index.generate_result_code(code)
 +        code.putln(
 +            "if (PyObject_SetItem(%s, %s, %s) < 0) %s" % (
 +                self.base.py_result(),
 +                self.py_index.py_result(),
 +                rhs.py_result(),
 +                code.error_goto(self.pos)))
 +        if self.is_temp:
 +            self.py_index.generate_disposal_code(code)
 +    
      def generate_deletion_code(self, code):
          self.generate_subexpr_evaluation_code(code)
 +        self.py_index.generate_evaluation_code(code)
          code.putln(
              "if (PyObject_DelItem(%s, %s) < 0) %s" % (
                  self.base.py_result(),
@@@ -3367,26 -3142,28 +3405,28 @@@ static void __Pyx_UnpackError(void) 
      PyErr_SetString(PyExc_ValueError, "unpack sequence of wrong size");
  }
  
-   PyObject *item;
-   if (!(item = PySequence_GetItem(seq, i))) {
-     if (PyErr_ExceptionMatches(PyExc_IndexError))
-       __Pyx_UnpackError();
-   }
-   return item;
- }
 +static PyObject *__Pyx_UnpackItem(PyObject *seq, Py_ssize_t i) {
 -}
+ static PyObject *__Pyx_UnpackItem(PyObject *iter) {
+     PyObject *item;
+     if (!(item = PyIter_Next(iter))) {
+         if (!PyErr_Occurred())
+             __Pyx_UnpackError();
+     }
+     return item;
  
-   PyObject *item;
-   if (item = PySequence_GetItem(seq, i)) {
-     Py_DECREF(item);
-     __Pyx_UnpackError();
-     return -1;
-   }
-   PyErr_Clear();
-     return 0;
- }
- """
 +static int __Pyx_EndUnpack(PyObject *seq, Py_ssize_t i) {
 -}
+ static int __Pyx_EndUnpack(PyObject *iter) {
+     PyObject *item;
+     if ((item = PyIter_Next(iter))) {
+         Py_DECREF(item);
+         __Pyx_UnpackError();
+         return -1;
+     }
+     else if (!PyErr_Occurred())
+         return 0;
+     else
+         return -1;
+ """]
  
  #------------------------------------------------------------------------------------
  
index 5f8d83f743cb25e6852cf4d73894fad24b42c522,1c816d4bb6dab413a860adb5423e5ae3d8f0899b..298ab1b08ab3c74e833d2c83e2f0e3c464669546
@@@ -2,10 -2,10 +2,10 @@@
  #   Pyrex - Parse tree nodes
  #
  
- import os, string, sys, time
+ import string, sys
  
  import Code
 -from Errors import error, InternalError
 +from Errors import error, warning, InternalError
  import Naming
  import PyrexTypes
  from PyrexTypes import py_object_type, error_type, CTypedefType
@@@ -3363,24 -1932,18 +2133,22 @@@ class ForFromStatNode(StatNode)
                  ExprNodes.CloneNode(c_loopvar_node).coerce_to_pyobject(env)
          self.bound1.allocate_temps(env)
          self.bound2.allocate_temps(env)
-         if self.py_loopvar_node:
 +        if self.step is not None:
 +            self.step.allocate_temps(env)
+         if self.is_py_target:
              self.py_loopvar_node.allocate_temps(env)
-         self.target.allocate_target_temps(env)
-         self.target.release_target_temp(env)
-         if self.py_loopvar_node:
-             self.py_loopvar_node.release_temp(env)
+             self.target.allocate_target_temps(env, self.py_loopvar_node)
+             #self.target.release_target_temp(env)
+             #self.py_loopvar_node.release_temp(env)
          self.body.analyse_expressions(env)
-         if self.py_loopvar_node:
+         if self.is_py_target:
              c_loopvar_node.release_temp(env)
          if self.else_clause:
              self.else_clause.analyse_expressions(env)
          self.bound1.release_temp(env)
          self.bound2.release_temp(env)
-         #env.recycle_pending_temps() # TEMPORARY
 +        if self.step is not None:
 +            self.step.release_temp(env)
              
      def generate_execution_code(self, code):
          old_loop_labels = code.new_loop_labels()
@@@ -3804,36 -2370,13 +2580,16 @@@ utility_function_predeclarations = 
  """
  typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
  typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
- static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t); /*proto*/
- static int __Pyx_EndUnpack(PyObject *, Py_ssize_t); /*proto*/
- static int __Pyx_PrintItem(PyObject *); /*proto*/
- static int __Pyx_PrintNewline(void); /*proto*/
- static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
- static void __Pyx_ReRaise(void); /*proto*/
- static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
- static PyObject *__Pyx_GetExcValue(void); /*proto*/
- static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
- static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
- static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds,\
-  char *kwd_list[], Py_ssize_t nargs, PyObject **args2, PyObject **kwds2); /*proto*/
- static void __Pyx_WriteUnraisable(char *name); /*proto*/
- static void __Pyx_AddTraceback(char *funcname); /*proto*/
- static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/
- static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
- static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
- static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
- static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
- static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
 +
 +#DEFINE __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
 +#DEFINE __Pyx_PyObject_IsTrue(x) ({PyObject *_x = (x); _x == Py_True ? 1 : (_x) == Py_False ? 0 : PyObject_IsTrue(_x)})
  """
  
- get_name_predeclaration = \
- "static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/"
#get_name_predeclaration = \
#"static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/"
  
- get_name_interned_predeclaration = \
- "static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/"
#get_name_interned_predeclaration = \
#"static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/"
  
  #------------------------------------------------------------------------------------
  
@@@ -3913,38 -2461,33 +2674,33 @@@ static void __Pyx_Raise(PyObject *type
          Py_INCREF(type);
          Py_DECREF(tmp);
      }
 -    if (PyString_Check(type)) {
 -        if (PyErr_Warn(PyExc_DeprecationWarning,
 -                "raising a string exception is deprecated"))
 -            goto raise_error;
 -    }
 +    if (PyString_Check(type))
 +        ;
 +/*    else if (PyClass_Check(type)) */
      else if (PyType_Check(type) || PyClass_Check(type))
          ; /*PyErr_NormalizeException(&type, &value, &tb);*/
-     else if (PyInstance_Check(type)) {
+     else {
          /* Raising an instance.  The value should be a dummy. */
          if (value != Py_None) {
              PyErr_SetString(PyExc_TypeError,
-               "instance exception may not have a separate value");
+                 "instance exception may not have a separate value");
              goto raise_error;
          }
-         else {
-             /* Normalize to raise <class>, <instance> */
-             Py_DECREF(value);
-             value = type;
+         /* Normalize to raise <class>, <instance> */
+         Py_DECREF(value);
+         value = type;
+         if (PyInstance_Check(type))
              type = (PyObject*) ((PyInstanceObject*)type)->in_class;
-             Py_INCREF(type);
-         }
+         else
+             type = (PyObject*) type->ob_type;
+         Py_INCREF(type);
      }
-     else {
-         /* Not something you can raise.  You get an exception
-            anyway, just not what you specified :-) */
-         PyErr_Format(PyExc_TypeError,
-                  "exceptions must be strings, classes, or "
-                  "instances, not %s", type->ob_type->tp_name);
-         goto raise_error;
 -    PyErr_Restore(type, value, tb);
 -    return;
 -raise_error:
 -    Py_XDECREF(value);
++    if (PyString_Check(type)) {
++        if (PyErr_Warn(PyExc_DeprecationWarning,
++                "raising a string exception is deprecated"))
++            goto raise_error;
 +    }
-     PyErr_Restore(type, value, tb);
-     return;
- raise_error:
-     Py_XDECREF(value);
++    else if (PyType_Check(type) || PyClass_Check(type))
      Py_XDECREF(type);
      Py_XDECREF(tb);
      return;
@@@ -4065,11 -2615,15 +2828,11 @@@ static int __Pyx_GetStarArgs
  bad:
      Py_XDECREF(args1);
      Py_XDECREF(kwds1);
 -    if (*args2) {
 -        Py_XDECREF(*args2);
 -    }
 -    if (*kwds2) {
 -        Py_XDECREF(*kwds2);
 -    }
 +    Py_XDECREF(*args2);
 +    Py_XDECREF(*kwds2);
      return -1;
  }
- """
+ """]
  
  #------------------------------------------------------------------------------------
  
@@@ -4084,8 -2640,8 +2849,12 @@@ static void __Pyx_WriteUnraisable(char 
      if (!ctx)
          ctx = Py_None;
      PyErr_WriteUnraisable(ctx);
--}
- """
 -"""]
++    if (*args2) {
++        Py_XDECREF(*args2);
++    }
++    if (*kwds2) {
++        Py_XDECREF(*kwds2);
++    }
  
  #------------------------------------------------------------------------------------
  
index d819ccebbc0a1b56313569f0fb7412b03bdda33b,22bb490e10ea04ab7eff8dd4374fa01167e501d8..0e7c392a4ca0f2fc5eedea73ae4020e9ccce969d
@@@ -1894,7 -1774,7 +1888,7 @@@ def p_module(s, pxd, full_module_name)
      if s.sy <> 'EOF':
          s.error("Syntax error in statement [%s,%s]" % (
              repr(s.sy), repr(s.systring)))
-     return Nodes.ModuleNode(pos, doc = doc, body = body, full_module_name = full_module_name)
 -    return ModuleNode(pos, doc = doc, body = body)
++    return ModuleNode(pos, doc = doc, body = body, full_module_name = full_module_name)
  
  #----------------------------------------------
  #
index fba2f78bfec583b59ce1d33e90a2db04fab658e5,e0e359470001331ec7e8cc77bf0f019a4b544990..64fdcd579745483e512776a2d7e6fcb1289efccb
@@@ -341,20 -333,9 +336,23 @@@ class CIntType(CNumericType)
      def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0):
          CNumericType.__init__(self, rank, signed, pymemberdef_typecode)
          self.is_returncode = is_returncode
+     
+     def assignable_from_resolved_type(self, src_type):
+         return src_type.is_int or src_type.is_enum or src_type is error_type
 +        
 +
 +class CBIntType(CIntType):
 +
 +    # TODO: this should be a macro "(__ ? Py_True : Py_False)"
 +    #       and no error checking should be needed (just an incref). 
 +    to_py_function = "__Pyx_PyBool_FromLong"
 +    from_py_function = "__Pyx_PyObject_IsTrue"
 +    
 +
 +class CPySSizeTType(CIntType):
 +
 +    to_py_function = "PyInt_FromSsize_t"
 +    from_py_function = "PyInt_AsSsize_t"
  
  
  class CUIntType(CIntType):
@@@ -742,9 -704,6 +747,8 @@@ c_short_type =    CIntType(1, 1, "T_SHO
  c_int_type =      CIntType(2, 1, "T_INT")
  c_long_type =     CIntType(3, 1, "T_LONG")
  c_longlong_type = CLongLongType(4, 1, "T_LONGLONG")
 +c_py_ssize_t_type = CPySSizeTType(5, 1)
 +c_bint_type =      CBIntType(2, 1, "T_INT")
  
  c_uchar_type =     CIntType(0, 0, "T_UBYTE")
  c_ushort_type =    CIntType(1, 0, "T_USHORT")
index 9c114657be4b361199f756d881fcd1831131a892,3ac9218c9a7f8e5894d9b37a5dcd61db3e9ac58e..6d8b177f7bba6582e6a149677293d3f336bd5d06
@@@ -639,16 -571,10 +645,18 @@@ class ModuleScope(Scope)
          # None if previously declared as something else.
          entry = self.lookup_here(name)
          if entry:
+             if entry.is_pyglobal and entry.as_module is scope:
+                 return entry # Already declared as the same module
              if not (entry.is_pyglobal and not entry.as_module):
 -                error(pos, "'%s' redeclared" % name)
 +                # SAGE -- I put this here so Pyrex
 +                # cimport's work across directories.
 +                # Currently it tries to multiply define
 +                # every module appearing in an import list.
 +                # It shouldn't be an error for a module
 +                # name to appear again, and indeed the generated
 +                # code compiles fine. 
 +                return entry
 +                warning(pos, "'%s' redeclared  " % name, 0)
                  return None
          else:
              entry = self.declare_var(name, py_object_type, pos)