|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60625 - in trunk: boost/python libs/python/doc/v2 libs/python/src libs/python/src/object
From: rwgk_at_[hidden]
Date: 2010-03-15 18:00:31
Author: rwgk
Date: 2010-03-15 18:00:30 EDT (Mon, 15 Mar 2010)
New Revision: 60625
URL: http://svn.boost.org/trac/boost/changeset/60625
Log:
boost/python/object_core.hpp: new .is_none() member function
Text files modified:
trunk/boost/python/object_core.hpp | 11 ++++++++++-
trunk/libs/python/doc/v2/object.html | 12 +++++++++++-
trunk/libs/python/src/exec.cpp | 20 ++++++++------------
trunk/libs/python/src/object/function.cpp | 6 +++---
trunk/libs/python/src/object/pickle_support.cpp | 8 ++++----
5 files changed, 36 insertions(+), 21 deletions(-)
Modified: trunk/boost/python/object_core.hpp
==============================================================================
--- trunk/boost/python/object_core.hpp (original)
+++ trunk/boost/python/object_core.hpp 2010-03-15 18:00:30 EDT (Mon, 15 Mar 2010)
@@ -5,6 +5,8 @@
#ifndef OBJECT_CORE_DWA2002615_HPP
# define OBJECT_CORE_DWA2002615_HPP
+# define BOOST_PYTHON_OBJECT_HAS_IS_NONE // added 2010-03-15 by rwgk
+
# include <boost/python/detail/prefix.hpp>
# include <boost/type.hpp>
@@ -239,7 +241,9 @@
// Underlying object access -- returns a borrowed reference
inline PyObject* ptr() const;
-
+
+ inline bool is_none() const;
+
private:
PyObject* m_ptr;
};
@@ -539,6 +543,11 @@
return m_ptr;
}
+inline bool api::object_base::is_none() const
+{
+ return (m_ptr == Py_None);
+}
+
//
// Converter specialization implementations
//
Modified: trunk/libs/python/doc/v2/object.html
==============================================================================
--- trunk/libs/python/doc/v2/object.html (original)
+++ trunk/libs/python/doc/v2/object.html 2010-03-15 18:00:30 EDT (Mon, 15 Mar 2010)
@@ -835,6 +835,8 @@
object& operator=(object const&);
PyObject* ptr() const;
+
+ bool is_none() const;
};
}}}
</pre>
@@ -895,6 +897,14 @@
<dt><b>Returns:</b> a pointer to the internally-held Python
object.</dt>
</dl>
+
+<pre>
+bool is_none() const;
+</pre>
+
+ <dl class="function-semantics">
+ <dt><b>Returns:</b> result of (ptr() == Py_None)</dt>
+ </dl>
<!-- -->
<h3><a name="proxy-spec"></a>Class template <code>proxy</code></h3>
@@ -1101,7 +1111,7 @@
</pre>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
- 27 May, 2008
+ 15 March, 2010
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
Modified: trunk/libs/python/src/exec.cpp
==============================================================================
--- trunk/libs/python/src/exec.cpp (original)
+++ trunk/libs/python/src/exec.cpp 2010-03-15 18:00:30 EDT (Mon, 15 Mar 2010)
@@ -17,15 +17,14 @@
object BOOST_PYTHON_DECL eval(str string, object global, object local)
{
// Set suitable default values for global and local dicts.
- object none;
- if (global.ptr() == none.ptr())
+ if (global.is_none())
{
if (PyObject *g = PyEval_GetGlobals())
global = object(detail::borrowed_reference(g));
else
global = dict();
}
- if (local.ptr() == none.ptr()) local = global;
+ if (local.is_none()) local = global;
// should be 'char const *' but older python versions don't use 'const' yet.
char *s = python::extract<char *>(string);
PyObject* result = PyRun_String(s, Py_eval_input, global.ptr(), local.ptr());
@@ -36,15 +35,14 @@
object BOOST_PYTHON_DECL exec(str string, object global, object local)
{
// Set suitable default values for global and local dicts.
- object none;
- if (global.ptr() == none.ptr())
+ if (global.is_none())
{
if (PyObject *g = PyEval_GetGlobals())
global = object(detail::borrowed_reference(g));
else
global = dict();
}
- if (local.ptr() == none.ptr()) local = global;
+ if (local.is_none()) local = global;
// should be 'char const *' but older python versions don't use 'const' yet.
char *s = python::extract<char *>(string);
PyObject* result = PyRun_String(s, Py_file_input, global.ptr(), local.ptr());
@@ -55,15 +53,14 @@
object BOOST_PYTHON_DECL exec_statement(str string, object global, object local)
{
// Set suitable default values for global and local dicts.
- object none;
- if (global.ptr() == none.ptr())
+ if (global.is_none())
{
if (PyObject *g = PyEval_GetGlobals())
global = object(detail::borrowed_reference(g));
else
global = dict();
}
- if (local.ptr() == none.ptr()) local = global;
+ if (local.is_none()) local = global;
// should be 'char const *' but older python versions don't use 'const' yet.
char *s = python::extract<char *>(string);
PyObject* result = PyRun_String(s, Py_single_input, global.ptr(), local.ptr());
@@ -77,15 +74,14 @@
object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
{
// Set suitable default values for global and local dicts.
- object none;
- if (global.ptr() == none.ptr())
+ if (global.is_none())
{
if (PyObject *g = PyEval_GetGlobals())
global = object(detail::borrowed_reference(g));
else
global = dict();
}
- if (local.ptr() == none.ptr()) local = global;
+ if (local.is_none()) local = global;
// should be 'char const *' but older python versions don't use 'const' yet.
char *f = python::extract<char *>(filename);
#if PY_VERSION_HEX >= 0x03000000
Modified: trunk/libs/python/src/object/function.cpp
==============================================================================
--- trunk/libs/python/src/object/function.cpp (original)
+++ trunk/libs/python/src/object/function.cpp 2010-03-15 18:00:30 EDT (Mon, 15 Mar 2010)
@@ -144,7 +144,7 @@
if (n_keyword_actual > 0 // Keyword arguments were supplied
|| n_actual < min_arity) // or default keyword values are needed
{
- if (f->m_arg_names.ptr() == Py_None)
+ if (f->m_arg_names.is_none())
{
// this overload doesn't accept keywords
inner_args = handle<>();
@@ -487,7 +487,7 @@
}
// A function is named the first time it is added to a namespace.
- if (new_func->name().ptr() == Py_None)
+ if (new_func->name().is_none())
new_func->m_name = name;
handle<> name_space_name(
@@ -653,7 +653,7 @@
static PyObject* function_get_name(PyObject* op, void*)
{
function* f = downcast<function>(op);
- if (f->name().ptr() == Py_None)
+ if (f->name().is_none())
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_InternFromString("<unnamed Boost.Python function>");
#else
Modified: trunk/libs/python/src/object/pickle_support.cpp
==============================================================================
--- trunk/libs/python/src/object/pickle_support.cpp (original)
+++ trunk/libs/python/src/object/pickle_support.cpp 2010-03-15 18:00:30 EDT (Mon, 15 Mar 2010)
@@ -38,21 +38,21 @@
}
object getinitargs = getattr(instance_obj, "__getinitargs__", none);
tuple initargs;
- if (getinitargs.ptr() != none.ptr()) {
+ if (!getinitargs.is_none()) {
initargs = tuple(getinitargs());
}
result.append(initargs);
object getstate = getattr(instance_obj, "__getstate__", none);
object instance_dict = getattr(instance_obj, "__dict__", none);
long len_instance_dict = 0;
- if (instance_dict.ptr() != none.ptr()) {
+ if (!instance_dict.is_none()) {
len_instance_dict = len(instance_dict);
}
- if (getstate.ptr() != none.ptr()) {
+ if (!getstate.is_none()) {
if (len_instance_dict > 0) {
object getstate_manages_dict = getattr(
instance_obj, "__getstate_manages_dict__", none);
- if (getstate_manages_dict.ptr() == none.ptr()) {
+ if (getstate_manages_dict.is_none()) {
PyErr_SetString(PyExc_RuntimeError,
"Incomplete pickle support"
" (__getstate_manages_dict__ not set)");
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk