mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 06:02:14 +00:00
This commit was manufactured by cvs2svn to create tag
'merged_to_RC_1_34_0'. [SVN r37938]
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
// Copyright David Abrahams 2006. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
@@ -84,8 +84,6 @@
|
||||
(2, 4.25, 'wow')
|
||||
>>> q.f1()
|
||||
(1, 4.25, 'wow')
|
||||
>>> q.f2.__doc__.splitlines()[-3]
|
||||
"f2's docstring"
|
||||
|
||||
>>> X.f.__doc__.splitlines()[:2]
|
||||
["This is X.f's docstring", 'C++ signature:']
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# Copyright (C) 2003 Rational Discovery LLC. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
|
||||
# at http://www.boost.org/LICENSE_1_0.txt)
|
||||
# Copyright (C) 2003 Rational Discovery LLC
|
||||
# Permission to copy, use, modify, sell and distribute this software
|
||||
# is granted provided this copyright notice appears in all
|
||||
# copies. This software is provided "as is" without express or
|
||||
# implied warranty, and with no claim as to its suitability for any
|
||||
# purpose.
|
||||
|
||||
print "running..."
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ void exec_test()
|
||||
// Register the module with the interpreter
|
||||
if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == -1)
|
||||
throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
|
||||
"builtin modules");
|
||||
"builtin modules");
|
||||
// Retrieve the main module
|
||||
python::object main = python::import("__main__");
|
||||
|
||||
|
||||
@@ -1,6 +1,2 @@
|
||||
# Copyright Stefan Seefeld 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
print 'Hello World !'
|
||||
number = 42
|
||||
|
||||
@@ -103,7 +103,6 @@ BOOST_PYTHON_MODULE(keywords)
|
||||
, init<optional<int, double, const std::string &> >()
|
||||
)
|
||||
.def("set", &Bar::set, bar_set())
|
||||
.def("set2", &Bar::set, bar_set("set2's docstring"))
|
||||
.def("seta", &Bar::seta, arg("a"))
|
||||
|
||||
.def("a", &Bar::geta)
|
||||
|
||||
@@ -80,8 +80,6 @@
|
||||
>>> f.set(1,1.0,"1")
|
||||
>>> f.a(), f.b(), f.n()
|
||||
(1, 1.0, '1')
|
||||
>>> f.set2.__doc__.splitlines()[-3]
|
||||
"set2's docstring"
|
||||
'''
|
||||
|
||||
|
||||
|
||||
@@ -26,62 +26,6 @@ std::string x_value(X const& x)
|
||||
return "gotya " + x.s;
|
||||
}
|
||||
|
||||
struct A
|
||||
{
|
||||
int value;
|
||||
A() : value(0){};
|
||||
A(int v) : value(v) {};
|
||||
};
|
||||
|
||||
bool operator==(const A& v1, const A& v2)
|
||||
{
|
||||
return (v1.value == v2.value);
|
||||
}
|
||||
|
||||
struct B
|
||||
{
|
||||
A a;
|
||||
};
|
||||
|
||||
// Converter from A to python int
|
||||
struct AToPython
|
||||
{
|
||||
static PyObject* convert(const A& s)
|
||||
{
|
||||
return boost::python::incref(boost::python::object((int)s.value).ptr());
|
||||
}
|
||||
};
|
||||
|
||||
// Conversion from python int to A
|
||||
struct AFromPython
|
||||
{
|
||||
AFromPython()
|
||||
{
|
||||
boost::python::converter::registry::push_back(
|
||||
&convertible,
|
||||
&construct,
|
||||
boost::python::type_id< A >());
|
||||
}
|
||||
|
||||
static void* convertible(PyObject* obj_ptr)
|
||||
{
|
||||
if (!PyInt_Check(obj_ptr)) return 0;
|
||||
return obj_ptr;
|
||||
}
|
||||
|
||||
static void construct(
|
||||
PyObject* obj_ptr,
|
||||
boost::python::converter::rvalue_from_python_stage1_data* data)
|
||||
{
|
||||
void* storage = (
|
||||
(boost::python::converter::rvalue_from_python_storage< A >*)
|
||||
data)-> storage.bytes;
|
||||
|
||||
new (storage) A((int)PyInt_AsLong(obj_ptr));
|
||||
data->convertible = storage;
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(map_indexing_suite_ext)
|
||||
{
|
||||
class_<X>("X")
|
||||
@@ -114,18 +58,6 @@ BOOST_PYTHON_MODULE(map_indexing_suite_ext)
|
||||
class_<std::map<std::string, boost::shared_ptr<X> > >("TestMap")
|
||||
.def(map_indexing_suite<std::map<std::string, boost::shared_ptr<X> >, true>())
|
||||
;
|
||||
|
||||
to_python_converter< A , AToPython >();
|
||||
AFromPython();
|
||||
|
||||
class_< std::map<int, A> >("AMap")
|
||||
.def(map_indexing_suite<std::map<int, A>, true >())
|
||||
;
|
||||
|
||||
class_< B >("B")
|
||||
.add_property("a", make_getter(&B::a, return_value_policy<return_by_value>()),
|
||||
make_setter(&B::a, return_value_policy<return_by_value>()))
|
||||
;
|
||||
}
|
||||
|
||||
#include "module_tail.cpp"
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
>>> assert "map_indexing_suite_IntMap_entry" in dir()
|
||||
>>> assert "map_indexing_suite_TestMap_entry" in dir()
|
||||
>>> assert "map_indexing_suite_XMap_entry" in dir()
|
||||
>>> assert "map_indexing_suite_AMap_entry" in dir()
|
||||
>>> x = X('hi')
|
||||
>>> x
|
||||
hi
|
||||
@@ -202,18 +201,6 @@ kiwi
|
||||
... dom = el.data()
|
||||
joel kimpo
|
||||
|
||||
#####################################################################
|
||||
# Test custom converter...
|
||||
#####################################################################
|
||||
|
||||
>>> am = AMap()
|
||||
>>> am[3] = 4
|
||||
>>> am[3]
|
||||
4
|
||||
>>> for i in am:
|
||||
... i.data()
|
||||
4
|
||||
|
||||
#####################################################################
|
||||
# END....
|
||||
#####################################################################
|
||||
|
||||
@@ -32,7 +32,7 @@ extern "C" void (*old_translator)(unsigned, EXCEPTION_POINTERS*)
|
||||
#include <boost/python/str.hpp>
|
||||
struct test_failure : std::exception
|
||||
{
|
||||
test_failure(char const* expr, char const* /*function*/, char const* file, unsigned line)
|
||||
test_failure(char const* expr, char const* function, char const* file, unsigned line)
|
||||
: msg(file + boost::python::str(":%s:") % line + ": Boost.Python assertion failure: " + expr)
|
||||
{}
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#include "boost/python.hpp"
|
||||
#include <memory>
|
||||
|
||||
struct vector
|
||||
{
|
||||
virtual ~vector() {}
|
||||
|
||||
vector operator+( const vector& x ) const
|
||||
{ return vector(); }
|
||||
|
||||
vector& operator+=( const vector& x )
|
||||
{ return *this; }
|
||||
|
||||
vector operator-() const
|
||||
{ return *this; }
|
||||
};
|
||||
|
||||
struct dvector : vector
|
||||
{};
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
struct vector_wrapper
|
||||
: vector, wrapper< vector >
|
||||
{
|
||||
vector_wrapper(vector const&) {}
|
||||
vector_wrapper() {}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE( operators_wrapper_ext )
|
||||
{
|
||||
class_< vector_wrapper >( "vector" )
|
||||
.def( self + self )
|
||||
.def( self += self )
|
||||
.def( -self )
|
||||
;
|
||||
|
||||
scope().attr("v") = vector();
|
||||
std::auto_ptr<vector> dp(new dvector);
|
||||
register_ptr_to_python< std::auto_ptr<vector> >();
|
||||
scope().attr("d") = dp;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
from operators_wrapper_ext import *
|
||||
|
||||
class D2(vector): pass
|
||||
d2 = D2()
|
||||
|
||||
for lhs in (v,d,d2):
|
||||
-lhs
|
||||
for rhs in (v,d,d2):
|
||||
lhs + rhs
|
||||
lhs += rhs
|
||||
|
||||
@@ -45,8 +45,6 @@ namespace {
|
||||
}
|
||||
};
|
||||
|
||||
// To support test of "pickling not enabled" error message.
|
||||
struct noop {};
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(pickle1_ext)
|
||||
@@ -56,7 +54,4 @@ BOOST_PYTHON_MODULE(pickle1_ext)
|
||||
.def("greet", &world::greet)
|
||||
.def_pickle(world_pickle_suite())
|
||||
;
|
||||
|
||||
// To support test of "pickling not enabled" error message.
|
||||
class_<noop>("noop");
|
||||
}
|
||||
|
||||
@@ -18,11 +18,6 @@ r'''>>> import pickle1_ext
|
||||
Hello from California!
|
||||
>>> print wl.greet()
|
||||
Hello from California!
|
||||
|
||||
>>> noop = pickle1_ext.noop()
|
||||
>>> try: pickle.dumps(noop)
|
||||
... except RuntimeError, e: print str(e)[:55]
|
||||
Pickling of "pickle1_ext.noop" instances is not enabled
|
||||
'''
|
||||
|
||||
def run(args = None):
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// Copyright Joel de Guzman 2005-2006. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
#include <vector>
|
||||
|
||||
@@ -53,10 +53,5 @@ BOOST_PYTHON_MODULE(vector_indexing_suite_ext)
|
||||
class_<std::vector<bool> >("BoolVec")
|
||||
.def(vector_indexing_suite<std::vector<bool> >())
|
||||
;
|
||||
|
||||
// vector of strings
|
||||
class_<std::vector<std::string> >("StringVec")
|
||||
.def(vector_indexing_suite<std::vector<std::string> >())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -321,14 +321,6 @@ e
|
||||
>>> print_xvec(v)
|
||||
[ a b c d e f g h i j ]
|
||||
|
||||
#####################################################################
|
||||
# vector of strings
|
||||
#####################################################################
|
||||
>>> sv = StringVec()
|
||||
>>> sv.append('a')
|
||||
>>> print sv[0]
|
||||
a
|
||||
|
||||
#####################################################################
|
||||
# END....
|
||||
#####################################################################
|
||||
|
||||
@@ -12,23 +12,23 @@ static void *test=(void *) 78;
|
||||
|
||||
void *get()
|
||||
{
|
||||
return test;
|
||||
return test;
|
||||
}
|
||||
|
||||
void *getnull()
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void use(void *a)
|
||||
{
|
||||
if(a!=test)
|
||||
if(a!=test)
|
||||
throw std::runtime_error(std::string("failed"));
|
||||
}
|
||||
|
||||
int useany(void *a)
|
||||
{
|
||||
return a ? 1 : 0;
|
||||
return a ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace bpl = boost::python;
|
||||
|
||||
BOOST_PYTHON_MODULE(voidptr_ext)
|
||||
{
|
||||
bpl::def("get", &::get, bpl::return_value_policy<bpl::return_opaque_pointer>());
|
||||
bpl::def("getnull", &::getnull, bpl::return_value_policy<bpl::return_opaque_pointer>());
|
||||
bpl::def("use", &::use);
|
||||
bpl::def("useany", &::useany);
|
||||
bpl::def("get", &::get, bpl::return_value_policy<bpl::return_opaque_pointer>());
|
||||
bpl::def("getnull", &::getnull, bpl::return_value_policy<bpl::return_opaque_pointer>());
|
||||
bpl::def("use", &::use);
|
||||
bpl::def("useany", &::useany);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user