Changeset 78


Ignore:
Timestamp:
Sep 30, 2005 2:12:07 PM (15 years ago)
Author:
cxsong
Message:
  1. fixed the return value, within PyRpUnits?.cc. it used to look for a i return value of 1 as a successful conversion, not it looks for return value of 0 for successful conversion.
  2. fixed the case where user requests a conversion with units="off" and expects a double back, now they really get a double back.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/python/PyRpUnits.cc

    r73 r78  
    428428    char* to = NULL;
    429429    char* units = NULL;
    430     char* tmpRetStr = NULL;
     430    // char* tmpRetStr = NULL;
    431431    std::string fromVal_S = "";
    432432    std::string to_S = "";
     
    436436    std::string retStr = "";
    437437    PyObject* retVal = NULL;
     438    PyObject* tmpPyStr = NULL;
    438439
    439440    static char *kwlist[] = {"fromVal", "to", "units", NULL};
     
    464465    retStr = RpUnits::convert(fromVal_S,to_S,unitsVal,&result);
    465466
    466     if ( (!retStr.empty()) && (result == 1) ) {
     467    if ( (!retStr.empty()) && (result == 0) ) {
    467468        if (unitsVal) {
    468469            retVal = PyString_FromString(retStr.c_str());   
    469470        }
    470471        else {
    471             // convert to an integer and return that if
     472            // convert to a double and return that if
    472473            // the units were turned off
    473             tmpRetStr = (char*) calloc(retStr.length(), sizeof(char));
    474             if (tmpRetStr) {
    475                 strncpy(tmpRetStr,retStr.c_str(),retStr.length());
    476                 retVal = PyInt_FromString(tmpRetStr, NULL, 0);
    477                 free(tmpRetStr);
    478                 tmpRetStr = NULL;
    479             }
     474            tmpPyStr = PyString_FromString(retStr.c_str());
     475            if (tmpPyStr) {
     476                Py_INCREF(tmpPyStr);
     477                retVal = PyFloat_FromString(tmpPyStr,NULL);
     478                Py_DECREF(tmpPyStr);
     479            }
    480480        }
    481481    }
Note: See TracChangeset for help on using the changeset viewer.