From 748c118ea82c167f3b352023ac906d25ca5aa464 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 5 Apr 2001 17:46:24 +0000 Subject: [PATCH] added: from_python std::string type checking [SVN r9727] --- src/conversions.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/conversions.cpp b/src/conversions.cpp index 1bc923b1..4bfe2011 100644 --- a/src/conversions.cpp +++ b/src/conversions.cpp @@ -7,6 +7,7 @@ // producing this work. // // Revision History: +// 05 Apr 01 added: from_python std::string type checking (rwgk) // 12 Mar 01 Python 1.5.2 fixes (Ralf W. Grosse-Kunstleve) // 11 Mar 01 std::string *MAY* include nulls (Alex Martelli) // 04 Mar 01 std::complex<> fixes for MSVC (Dave Abrahams) @@ -250,6 +251,10 @@ PyObject* to_python(const std::string& s) std::string from_python(PyObject* p, boost::python::type) { + if (! PyString_Check(p)) { + PyErr_SetString(PyExc_TypeError, "expected a string"); + throw boost::python::argument_error(); + } return std::string(PyString_AsString(p), PyString_Size(p)); }