From 384519ce247e5281414fc14891d808c5f031d2e6 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Wed, 11 May 2016 15:14:19 -0500 Subject: [PATCH] Use udunits package for units conversions PyFrame_GetLineNumber is not present in python 2.6. We have to use PyCode_Addr2Line instead to get the line number. refs #231 --- trick_source/trick_swig/units_attach.i | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/trick_source/trick_swig/units_attach.i b/trick_source/trick_swig/units_attach.i index b2c78297..806b66d5 100644 --- a/trick_source/trick_swig/units_attach.i +++ b/trick_source/trick_swig/units_attach.i @@ -33,7 +33,11 @@ PyObject * attach_units(PyObject * in_units_obj , PyObject * in_object) { int line_no = 0 ; if (NULL != tstate && NULL != tstate->frame) { file_name = PyString_AsString(tstate->frame->f_code->co_filename); +#if (PY_MAJOR_VERSION == 2 ) && (PY_MINOR_VERSION <= 6) + line_no = PyCode_Addr2Line(tstate->frame->f_code, tstate->frame->f_lasti) ; +#else line_no = PyFrame_GetLineNumber(tstate->frame) ; +#endif } std::cout << "\033[33mUnits converted from [" << in_units << "] to [" << new_units << "] " << file_name << ":" << line_no << "\033[0m" << std::endl ;