Changeset 2845 for inundation/pymetis


Ignore:
Timestamp:
May 11, 2006, 3:10:59 PM (19 years ago)
Author:
jack
Message:

Added (hopefully) safe downcasting of the long array passed to pymetis.

Location:
inundation/pymetis
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/pymetis/pymetis/metis.c

    r2842 r2845  
    4242 */
    4343static PyObject * metis_partMeshNodal(PyObject * self, PyObject * args){
     44  int i;
    4445  int ne;
    4546  int nn;
     
    5657
    5758  /* These are all of the metis idxtype */
     59  idxtype * elem_c_arr;
    5860  idxtype * epart;
    5961  idxtype * npart;
     
    6163    return NULL;
    6264
    63   elem_arr = (PyArrayObject *) PyArray_ContiguousFromObject(elements, PyArray_INT, 1, 1);
     65  elem_arr = (PyArrayObject *) PyArray_ContiguousFromObject(elements, PyArray_NOTYPE, 1, 1);
    6466
    6567  if(!elem_arr)
    6668    return NULL;
     69
     70  /* x86_64 will create arrays of longs and they need to be
     71   * converted to arrays of idxtype for metis to work on them.
     72   */
     73  if(elem_arr->descr->type_num == PyArray_LONG){
     74    elem_c_arr = (idxtype *)malloc(*(elem_arr->dimensions) * sizeof(idxtype));
     75    if(!elem_c_arr)
     76        return NULL;
     77    for(i = 0 ; i < *(elem_arr->dimensions) ; i++){
     78      elem_c_arr[i] = (idxtype)(((long *)elem_arr->data)[i]);
     79      if(elem_c_arr[i] != ((long *)elem_arr->data)[i]) /* i.e. downcast failed */
     80        return null;
     81    }
     82  }else
     83    elem_c_arr = (idxtype *)elem_arr->data;
    6784
    6885  epart = (idxtype *)malloc(ne * sizeof(idxtype));
     
    7794    return NULL;
    7895  }
    79   bridge_partMeshNodal(&ne, &nn, (idxtype *)elem_arr->data, &etype, &numflag, &nparts, &edgecut, epart, npart);
     96  bridge_partMeshNodal(&ne, &nn, elem_c_arr, &etype, &numflag, &nparts, &edgecut, epart, npart);
    8097
    8198  dims[0] = ne;
  • inundation/pymetis/test_metis.py

    r2842 r2845  
     1#!/usr/bin/env python
    12from os import sep
    23from sys import path
Note: See TracChangeset for help on using the changeset viewer.