Commits

gcewing committed 37554ac

Tests passed

  • Participants
  • Parent commits d726c32
  • Tags 0.9.8.3

Comments (0)

Files changed (10)

 	- Compiling a .pyx file whose name is not a valid module name now
 		reports an error instead of generating invalid C code.
 		[Robert Bradshaw]
+	
+	- Integer indexing optimisation now performed only for signed
+		index types, to avoid change of semantics with index values
+		greater than the maximum positive signed int value. [Robert
+		Bradshaw]
+	
+	- Non-void function declared 'except *' could produce C compiler
+		warning about uninitialised variable. [Lisandro Dalcin]
 
 
 0.9.8.2
-VERSION = 0.9.8.2
+VERSION = 0.9.8.3
 
 version:
 	@echo "Setting version to $(VERSION)"

Pyrex/Compiler/ExprNodes.py

 	
 	def generate_result_code(self, code):
 		if self.type.is_pyobject:
-			if self.index.type.is_int:
+			itype = self.index.type
+			if itype.is_int and itype.signed:
 				code.use_utility_code(getitem_int_utility_code)
 				function = "__Pyx_GetItemInt"
 				index_code = self.index.result()
 					code.error_goto(self.pos)))
 	
 	def generate_setitem_code(self, value_code, code):
-		if self.index.type.is_int:
+		itype = self.index.type
+		if itype.is_int and itype.signed:
 			code.use_utility_code(setitem_int_utility_code)
 			function = "__Pyx_SetItemInt"
 			index_code = self.index.result()

Pyrex/Compiler/Nodes.py

 			code.put_goto(code.return_label)
 			code.put_label(code.error_label)
 			code.put_var_xdecrefs(lenv.temp_entries)
+			default_retval = self.return_type.default_value
 			err_val = self.error_value()
 			exc_check = self.caller_will_check_exceptions()
-			if err_val is not None or exc_check:
+			if err_val or exc_check:
 				code.putln(
 					'__Pyx_AddTraceback("%s");' % 
 						self.entry.qualified_name)
-				if err_val is not None:
+				val = err_val or default_retval
+				if val:
 					code.putln(
 						"%s = %s;" % (
 							Naming.retval_cname, 
-							err_val))
+							val))
 			else:
 				code.use_utility_code(unraisable_exception_utility_code)
 				code.putln(
 					'__Pyx_WriteUnraisable("%s");' % 
 						self.entry.qualified_name)
 				#if not self.return_type.is_void:
-				default_retval = self.return_type.default_value
 				if default_retval:
 					code.putln(
 						"%s = %s;" % (

Tests/10/Reference/intindex.c

   PyObject *__pyx_v_y;
   PyObject *__pyx_v_z;
   int __pyx_v_i;
+  unsigned int __pyx_v_ui;
   int __pyx_r;
   PyObject *__pyx_1 = 0;
   __pyx_v_x = Py_None; Py_INCREF(Py_None);
   /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":7 */
   if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_v_z) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
 
+  /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":9 */
+  __pyx_1 = PyObject_GetItem(__pyx_v_x, ((PyObject *)__pyx_v_ui)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; goto __pyx_L1;}
+  Py_DECREF(__pyx_v_z);
+  __pyx_v_z = __pyx_1;
+  __pyx_1 = 0;
+
+  /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":10 */
+  if (PyObject_SetItem(__pyx_v_x, ((PyObject *)__pyx_v_ui), __pyx_v_z) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
+
   __pyx_r = 0;
   goto __pyx_L0;
   __pyx_L1:;

Tests/10/intindex.c

   PyObject *__pyx_v_y;
   PyObject *__pyx_v_z;
   int __pyx_v_i;
+  unsigned int __pyx_v_ui;
   int __pyx_r;
   PyObject *__pyx_1 = 0;
   __pyx_v_x = Py_None; Py_INCREF(Py_None);
   __pyx_v_y = Py_None; Py_INCREF(Py_None);
   __pyx_v_z = Py_None; Py_INCREF(Py_None);
 
-  /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":4 */
-  __pyx_1 = PyObject_GetItem(__pyx_v_x, __pyx_v_y); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;}
-  Py_DECREF(__pyx_v_z);
-  __pyx_v_z = __pyx_1;
-  __pyx_1 = 0;
-
   /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":5 */
-  __pyx_1 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}
+  __pyx_1 = PyObject_GetItem(__pyx_v_x, __pyx_v_y); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}
   Py_DECREF(__pyx_v_z);
   __pyx_v_z = __pyx_1;
   __pyx_1 = 0;
 
   /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":6 */
-  if (PyObject_SetItem(__pyx_v_x, __pyx_v_y, __pyx_v_z) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; goto __pyx_L1;}
+  __pyx_1 = __Pyx_GetItemInt(__pyx_v_x, __pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; goto __pyx_L1;}
+  Py_DECREF(__pyx_v_z);
+  __pyx_v_z = __pyx_1;
+  __pyx_1 = 0;
 
   /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":7 */
-  if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_v_z) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
+  if (PyObject_SetItem(__pyx_v_x, __pyx_v_y, __pyx_v_z) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
+
+  /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":8 */
+  if (__Pyx_SetItemInt(__pyx_v_x, __pyx_v_i, __pyx_v_z) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
+
+  /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":9 */
+  __pyx_1 = PyObject_GetItem(__pyx_v_x, ((PyObject *)__pyx_v_ui)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; goto __pyx_L1;}
+  Py_DECREF(__pyx_v_z);
+  __pyx_v_z = __pyx_1;
+  __pyx_1 = 0;
+
+  /* "/Local/Projects/D/Pyrex/Source/Tests/10/intindex.pyx":10 */
+  if (PyObject_SetItem(__pyx_v_x, ((PyObject *)__pyx_v_ui), __pyx_v_z) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
 
   __pyx_r = 0;
   goto __pyx_L0;

Tests/10/intindex.pyx

 cdef int f() except -1:
 	cdef object x, y, z
 	cdef int i
+	cdef unsigned int ui
 	z = x[y]
 	z = x[i]
 	x[y] = z
 	x[i] = z
+	z = x[ui]
+	x[ui] = z

Tests/Bugs/other/Reference/dalcin1.c

+/* Generated by Pyrex 0.9.8.2 on Sun Jun  8 16:28:46 2008 */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "structmember.h"
+#ifndef PY_LONG_LONG
+  #define PY_LONG_LONG LONG_LONG
+#endif
+#if PY_VERSION_HEX < 0x02050000
+  typedef int Py_ssize_t;
+  #define PY_SSIZE_T_MAX INT_MAX
+  #define PY_SSIZE_T_MIN INT_MIN
+  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
+  #define PyInt_AsSsize_t(o)	PyInt_AsLong(o)
+#endif
+#ifndef WIN32
+  #ifndef __stdcall
+    #define __stdcall
+  #endif
+  #ifndef __cdecl
+    #define __cdecl
+  #endif
+#endif
+#ifdef __cplusplus
+#define __PYX_EXTERN_C extern "C"
+#else
+#define __PYX_EXTERN_C extern
+#endif
+#include <math.h>
+
+
+typedef struct {PyObject **p; int i; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static int __pyx_lineno;
+static char *__pyx_filename;
+static char **__pyx_f;
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+static void __Pyx_AddTraceback(char *funcname); /*proto*/
+
+/* Declarations from dalcin1 */
+
+
+/* Declarations from implementation of dalcin1 */
+
+static int __pyx_f_7dalcin1_obj2int(PyObject *); /*proto*/
+
+
+
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+  {0, 0, 0, 0}
+};
+
+
+
+/* Implementation of dalcin1 */
+
+static int __pyx_f_7dalcin1_obj2int(PyObject *__pyx_v_ob) {
+  int __pyx_r;
+  int __pyx_1;
+  Py_INCREF(__pyx_v_ob);
+  __pyx_1 = PyInt_AsLong(__pyx_v_ob); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;}
+  __pyx_r = __pyx_1;
+  goto __pyx_L0;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1:;
+  __Pyx_AddTraceback("dalcin1.obj2int");
+  __pyx_r = 0;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_ob);
+  return __pyx_r;
+}
+
+static struct PyMethodDef __pyx_methods[] = {
+  {0, 0, 0, 0}
+};
+
+static void __pyx_init_filenames(void); /*proto*/
+
+PyMODINIT_FUNC initdalcin1(void); /*proto*/
+PyMODINIT_FUNC initdalcin1(void) {
+  __pyx_init_filenames();
+  __pyx_m = Py_InitModule4("dalcin1", __pyx_methods, 0, 0, PYTHON_API_VERSION);
+  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
+  Py_INCREF(__pyx_m);
+  __pyx_b = PyImport_AddModule("__builtin__");
+  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
+  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
+  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
+  return;
+  __pyx_L1:;
+  __Pyx_AddTraceback("dalcin1");
+}
+
+static char *__pyx_filenames[] = {
+  "dalcin1.pyx",
+};
+
+/* Runtime support code */
+
+static void __pyx_init_filenames(void) {
+  __pyx_f = __pyx_filenames;
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+	while (t->p) {
+		*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+		if (!*t->p)
+			return -1;
+		if (t->i)
+			PyString_InternInPlace(t->p);
+		++t;
+	}
+	return 0;
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+
+static void __Pyx_AddTraceback(char *funcname) {
+	PyObject *py_srcfile = 0;
+	PyObject *py_funcname = 0;
+	PyObject *py_globals = 0;
+	PyObject *empty_tuple = 0;
+	PyObject *empty_string = 0;
+	PyCodeObject *py_code = 0;
+	PyFrameObject *py_frame = 0;
+	
+	py_srcfile = PyString_FromString(__pyx_filename);
+	if (!py_srcfile) goto bad;
+	py_funcname = PyString_FromString(funcname);
+	if (!py_funcname) goto bad;
+	py_globals = PyModule_GetDict(__pyx_m);
+	if (!py_globals) goto bad;
+	empty_tuple = PyTuple_New(0);
+	if (!empty_tuple) goto bad;
+	empty_string = PyString_FromString("");
+	if (!empty_string) goto bad;
+	py_code = PyCode_New(
+		0,            /*int argcount,*/
+		0,            /*int nlocals,*/
+		0,            /*int stacksize,*/
+		0,            /*int flags,*/
+		empty_string, /*PyObject *code,*/
+		empty_tuple,  /*PyObject *consts,*/
+		empty_tuple,  /*PyObject *names,*/
+		empty_tuple,  /*PyObject *varnames,*/
+		empty_tuple,  /*PyObject *freevars,*/
+		empty_tuple,  /*PyObject *cellvars,*/
+		py_srcfile,   /*PyObject *filename,*/
+		py_funcname,  /*PyObject *name,*/
+		__pyx_lineno,   /*int firstlineno,*/
+		empty_string  /*PyObject *lnotab*/
+	);
+	if (!py_code) goto bad;
+	py_frame = PyFrame_New(
+		PyThreadState_Get(), /*PyThreadState *tstate,*/
+		py_code,             /*PyCodeObject *code,*/
+		py_globals,          /*PyObject *globals,*/
+		0                    /*PyObject *locals*/
+	);
+	if (!py_frame) goto bad;
+	py_frame->f_lineno = __pyx_lineno;
+	PyTraceBack_Here(py_frame);
+bad:
+	Py_XDECREF(py_srcfile);
+	Py_XDECREF(py_funcname);
+	Py_XDECREF(empty_tuple);
+	Py_XDECREF(empty_string);
+	Py_XDECREF(py_code);
+	Py_XDECREF(py_frame);
+}

Tests/Bugs/other/dalcin1.c

+/* Generated by Pyrex */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "structmember.h"
+#ifndef PY_LONG_LONG
+  #define PY_LONG_LONG LONG_LONG
+#endif
+#if PY_VERSION_HEX < 0x02050000
+  typedef int Py_ssize_t;
+  #define PY_SSIZE_T_MAX INT_MAX
+  #define PY_SSIZE_T_MIN INT_MIN
+  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
+  #define PyInt_AsSsize_t(o)	PyInt_AsLong(o)
+#endif
+#ifndef WIN32
+  #ifndef __stdcall
+    #define __stdcall
+  #endif
+  #ifndef __cdecl
+    #define __cdecl
+  #endif
+#endif
+#ifdef __cplusplus
+#define __PYX_EXTERN_C extern "C"
+#else
+#define __PYX_EXTERN_C extern
+#endif
+#include <math.h>
+
+
+typedef struct {PyObject **p; int i; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static int __pyx_lineno;
+static char *__pyx_filename;
+static char **__pyx_f;
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+static void __Pyx_AddTraceback(char *funcname); /*proto*/
+
+/* Declarations from dalcin1 */
+
+
+/* Declarations from implementation of dalcin1 */
+
+static int __pyx_f_7dalcin1_obj2int(PyObject *); /*proto*/
+
+
+
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+  {0, 0, 0, 0}
+};
+
+
+
+/* Implementation of dalcin1 */
+
+static int __pyx_f_7dalcin1_obj2int(PyObject *__pyx_v_ob) {
+  int __pyx_r;
+  int __pyx_1;
+  Py_INCREF(__pyx_v_ob);
+  __pyx_1 = PyInt_AsLong(__pyx_v_ob); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;}
+  __pyx_r = __pyx_1;
+  goto __pyx_L0;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1:;
+  __Pyx_AddTraceback("dalcin1.obj2int");
+  __pyx_r = 0;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_ob);
+  return __pyx_r;
+}
+
+static struct PyMethodDef __pyx_methods[] = {
+  {0, 0, 0, 0}
+};
+
+static void __pyx_init_filenames(void); /*proto*/
+
+PyMODINIT_FUNC initdalcin1(void); /*proto*/
+PyMODINIT_FUNC initdalcin1(void) {
+  __pyx_init_filenames();
+  __pyx_m = Py_InitModule4("dalcin1", __pyx_methods, 0, 0, PYTHON_API_VERSION);
+  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
+  Py_INCREF(__pyx_m);
+  __pyx_b = PyImport_AddModule("__builtin__");
+  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
+  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
+  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
+  return;
+  __pyx_L1:;
+  __Pyx_AddTraceback("dalcin1");
+}
+
+static char *__pyx_filenames[] = {
+  "dalcin1.pyx",
+};
+
+/* Runtime support code */
+
+static void __pyx_init_filenames(void) {
+  __pyx_f = __pyx_filenames;
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+	while (t->p) {
+		*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+		if (!*t->p)
+			return -1;
+		if (t->i)
+			PyString_InternInPlace(t->p);
+		++t;
+	}
+	return 0;
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+
+static void __Pyx_AddTraceback(char *funcname) {
+	PyObject *py_srcfile = 0;
+	PyObject *py_funcname = 0;
+	PyObject *py_globals = 0;
+	PyObject *empty_tuple = 0;
+	PyObject *empty_string = 0;
+	PyCodeObject *py_code = 0;
+	PyFrameObject *py_frame = 0;
+	
+	py_srcfile = PyString_FromString(__pyx_filename);
+	if (!py_srcfile) goto bad;
+	py_funcname = PyString_FromString(funcname);
+	if (!py_funcname) goto bad;
+	py_globals = PyModule_GetDict(__pyx_m);
+	if (!py_globals) goto bad;
+	empty_tuple = PyTuple_New(0);
+	if (!empty_tuple) goto bad;
+	empty_string = PyString_FromString("");
+	if (!empty_string) goto bad;
+	py_code = PyCode_New(
+		0,            /*int argcount,*/
+		0,            /*int nlocals,*/
+		0,            /*int stacksize,*/
+		0,            /*int flags,*/
+		empty_string, /*PyObject *code,*/
+		empty_tuple,  /*PyObject *consts,*/
+		empty_tuple,  /*PyObject *names,*/
+		empty_tuple,  /*PyObject *varnames,*/
+		empty_tuple,  /*PyObject *freevars,*/
+		empty_tuple,  /*PyObject *cellvars,*/
+		py_srcfile,   /*PyObject *filename,*/
+		py_funcname,  /*PyObject *name,*/
+		__pyx_lineno,   /*int firstlineno,*/
+		empty_string  /*PyObject *lnotab*/
+	);
+	if (!py_code) goto bad;
+	py_frame = PyFrame_New(
+		PyThreadState_Get(), /*PyThreadState *tstate,*/
+		py_code,             /*PyCodeObject *code,*/
+		py_globals,          /*PyObject *globals,*/
+		0                    /*PyObject *locals*/
+	);
+	if (!py_frame) goto bad;
+	py_frame->f_lineno = __pyx_lineno;
+	PyTraceBack_Here(py_frame);
+bad:
+	Py_XDECREF(py_srcfile);
+	Py_XDECREF(py_funcname);
+	Py_XDECREF(empty_tuple);
+	Py_XDECREF(empty_string);
+	Py_XDECREF(py_code);
+	Py_XDECREF(py_frame);
+}

Tests/Bugs/other/dalcin1.pyx

+cdef int obj2int(object ob) except *:
+	return ob