[Scipy-svn] r7004 - trunk/scipy/sparse/linalg/dsolve
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat Dec 11 20:19:38 EST 2010
Author: ptvirtan
Date: 2010-12-11 19:19:38 -0600 (Sat, 11 Dec 2010)
New Revision: 7004
Modified:
trunk/scipy/sparse/linalg/dsolve/_superlu_utils.c
Log:
BUG: sparse/superlu: safer pointer to int conversion in _superlu_utils (#1236)
Modified: trunk/scipy/sparse/linalg/dsolve/_superlu_utils.c
===================================================================
--- trunk/scipy/sparse/linalg/dsolve/_superlu_utils.c 2010-12-11 23:47:46 UTC (rev 7003)
+++ trunk/scipy/sparse/linalg/dsolve/_superlu_utils.c 2010-12-12 01:19:38 UTC (rev 7004)
@@ -12,9 +12,9 @@
jmp_buf _superlu_py_jmpbuf;
PyObject *_superlumodule_memory_dict=NULL;
-/* Abort to be used inside the superlu module so that memory allocation
+/* Abort to be used inside the superlu module so that memory allocation
errors don't exit Python and memory allocated internal to SuperLU is freed.
- Calling program should deallocate (using SUPERLU_FREE) all memory that could have
+ Calling program should deallocate (using SUPERLU_FREE) all memory that could have
been allocated. (It's ok to FREE unallocated memory)---will be ignored.
*/
@@ -27,16 +27,14 @@
void *superlu_python_module_malloc(size_t size)
{
PyObject *key=NULL;
- long keyval;
- void *mem_ptr;
+ void *mem_ptr;
if (_superlumodule_memory_dict == NULL) {
_superlumodule_memory_dict = PyDict_New();
}
mem_ptr = malloc(size);
if (mem_ptr == NULL) return NULL;
- keyval = (long) mem_ptr;
- key = PyInt_FromLong(keyval);
+ key = PyLong_FromVoidPtr(mem_ptr);
if (key == NULL) goto fail;
if (PyDict_SetItem(_superlumodule_memory_dict, key, Py_None)) goto fail;
Py_DECREF(key);
@@ -47,31 +45,29 @@
free(mem_ptr);
superlu_python_module_abort("superlu_malloc: Cannot set dictionary key value in malloc.");
return NULL;
-
+
}
void superlu_python_module_free(void *ptr)
{
PyObject *key;
- long keyval;
PyObject *ptype, *pvalue, *ptraceback;
if (ptr == NULL) return;
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
- keyval = (long )ptr;
- key = PyInt_FromLong(keyval);
+ key = PyLong_FromVoidPtr(ptr);
/* This will only free the pointer if it could find it in the dictionary
of already allocated pointers --- thus after abort, the module can free all
- the memory that "might" have been allocated to avoid memory leaks on abort
+ the memory that "might" have been allocated to avoid memory leaks on abort
calls.
- */
+ */
if (_superlumodule_memory_dict && \
!(PyDict_DelItem(_superlumodule_memory_dict, key))) {
free(ptr);
}
Py_DECREF(key);
PyErr_Restore(ptype, pvalue, ptraceback);
- return;
+ return;
}
/*
More information about the Scipy-svn
mailing list