Mercurial > pytave
changeset 72:e9834fd34416 pytave-task
Fix lp:368487.
author | David Grundberg <individ@acc.umu.se> |
---|---|
date | Wed, 01 Jul 2009 14:21:47 +0200 |
parents | af96f7e819e2 |
children | 077a44d23b54 6429b33143ea |
files | ChangeLog configure.ac pytave.cc setup.py.in |
diffstat | 4 files changed, 87 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Jul 01 13:08:48 2009 +0200 +++ b/ChangeLog Wed Jul 01 14:21:47 2009 +0200 @@ -1,3 +1,13 @@ +2009-07-01 David Grundberg <individ@acc.umu.se> + + * pytave.cc [HAVE_USELOCALE] (init, func_eval, str_eval): Run + Octave interpreter in C locale. + * configure.ac: Define HAVE_USELOCALE. Substitute @PYTHON@. Added + checks for integer typedefs. Make setup.py executable. Friendly + message on configuration completion. + * setup.py.in: Let setup.py be interpreted by the same version of + Python we configured for. + 2009-06-19 Jaroslav Hajek <highegg@gmail.com> * configure.ac: Support --enable-numpy
--- a/configure.ac Wed Jul 01 13:08:48 2009 +0200 +++ b/configure.ac Wed Jul 01 14:21:47 2009 +0200 @@ -74,12 +74,23 @@ # Checks for libraries. # Checks for header files. +AC_CHECK_HEADERS([locale.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL AC_C_CONST +AC_C_INLINE +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_INT8_T +AC_TYPE_SIZE_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT8_T # Checks for library functions. +AC_CHECK_FUNCS([uselocale], [pytave_have_uselocale=yes], [pytave_have_uselocale=no]) # This needs a more usable, less unusual solution. AS_IF(test "x${prefix}" == "xNONE", @@ -96,12 +107,32 @@ PYTAVE_OCTAVE_RPATH="$OCTAVE_LIBRARYDIR" AC_SUBST(PYTAVE_OCTAVE_RPATH) AC_SUBST(PYTAVE_MODULE_INSTALL_PATH) -AC_SUBST(pytave_enable_numpy) +AC_SUBST(pytave_enable_numpy) # Substitutes for the Jamfile. XXX: Replace lib*.so with OS independent name. AC_SUBST(JAM_LIBOCTAVE, $OCTAVE_LIBRARYDIR/liboctave.so) AC_SUBST(JAM_LIBCRUFT, $OCTAVE_LIBRARYDIR/libcruft.so) AC_SUBST(JAM_LIBOCTINTERP, $OCTAVE_LIBRARYDIR/liboctinterp.so) +# setup.py +AC_SUBST(PYTHON) + # Substitute in these files, copy project-root.jam to VPATH too AC_OUTPUT([Makefile Jamfile setup.py project-root.jam]) + +chmod u+x "setup.py" + +AC_MSG_NOTICE([ +======================================================================== +Pytave now configured with the following setup: + +Dependencies + Octave ............. $OCTAVE_INCLUDEDIR + Python ............. $PYTHON_CPPFLAGS + executable ....... $PYTHON + +Features + NumPy .............. $pytave_enable_numpy + uselocale .......... $pytave_have_uselocale + +========================================================================])
--- a/pytave.cc Wed Jul 01 13:08:48 2009 +0200 +++ b/pytave.cc Wed Jul 01 14:21:47 2009 +0200 @@ -36,6 +36,9 @@ #include <iostream> #include <sstream> #include <sys/types.h> +#ifdef HAVE_USELOCALE +#include <locale.h> +#endif #include "pytavedefs.h" @@ -46,9 +49,16 @@ using namespace boost::python; using namespace std; -namespace pytave { /* {{{ */ +namespace pytave { /* {{{ */ + +#ifdef HAVE_USELOCALE + locale_t c_locale; +#endif void init(bool silent = true) { +#ifdef HAVE_USELOCALE + c_locale = newlocale(LC_ALL, "C", 0); +#endif if (!octave_error_exception::init() || !value_convert_exception::init() @@ -73,8 +83,18 @@ argc = 3; } +#ifdef HAVE_USELOCALE + // Set C locale + locale_t old_locale = uselocale(c_locale); +#endif + octave_main(argc, const_cast<char**>(argv), 1); +#ifdef HAVE_USELOCALE + // Reset locale + uselocale(old_locale); +#endif + // Initialize Python Numeric Array // This is actually a macro that becomes a block expression. If an error @@ -133,7 +153,6 @@ return exceptionmsg.str (); } - boost::python::tuple func_eval(const int nargout, const string &funcname, const boost::python::tuple &arguments) { @@ -147,11 +166,21 @@ // Updating the timestamp makes Octave reread changed files Vlast_prompt_time.stamp(); - + +#ifdef HAVE_USELOCALE + // Set C locale + locale_t old_locale = uselocale(c_locale); +#endif + Py_BEGIN_ALLOW_THREADS retval = feval(funcname, octave_args, (nargout >= 0) ? nargout : 0); Py_END_ALLOW_THREADS +#ifdef HAVE_USELOCALE + // Reset locale + uselocale(old_locale); +#endif + if (error_state != 0) { // error_state values: // -2 error without traceback @@ -190,12 +219,22 @@ // Updating the timestamp makes Octave reread changed files Vlast_prompt_time.stamp(); - + +#ifdef HAVE_USELOCALE + // Set C locale + locale_t old_locale = uselocale(c_locale); +#endif + Py_BEGIN_ALLOW_THREADS retval = eval_string(code, silent, parse_status, (nargout >= 0) ? nargout : 0); Py_END_ALLOW_THREADS +#ifdef HAVE_USELOCALE + // Reset locale + uselocale(old_locale); +#endif + if (parse_status != 0 || error_state != 0) { // error_state values: // -2 error without traceback @@ -301,7 +340,7 @@ octave_call_stack::pop(); } } - + } /* namespace pytave }}} */ BOOST_PYTHON_MODULE(_pytave) { /* {{{ */