2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-23 17:52:17 +00:00

Roll back most of Dave Hawkes' changes for the time being.

[SVN r14501]
This commit is contained in:
Dave Abrahams
2002-07-17 18:36:14 +00:00
parent 6ac5735d14
commit f9a67b34b2
8 changed files with 19 additions and 341 deletions

View File

@@ -14,7 +14,6 @@
# include <boost/python/type_id.hpp>
# include <boost/python/detail/wrap_function.hpp>
# include <boost/python/detail/member_function_cast.hpp>
# include <boost/python/detail/module_base.hpp>
# include <boost/python/object/class_converters.hpp>
# include <boost/type_traits/ice.hpp>
# include <boost/type_traits/same_traits.hpp>
@@ -87,12 +86,12 @@ class class_ : public objects::class_base
public:
// Automatically derive the class name - only works on some
// compilers because type_info::name is sometimes mangled (gcc)
class_(base const& parent_class = empty_class_base());
class_();
// Construct with the class name. [ Would have used a default
// argument but gcc-2.95.2 choked on typeid(T).name() as a default
// parameter value]
class_(char const* name, base const& parent_class = empty_class_base());
class_(char const* name);
// Wrap a member function or a non-member function which can take
@@ -196,22 +195,6 @@ class class_ : public objects::class_base
self& setattr(char const* name, handle<> const&);
// add to module
self& add(module &m)
{
// redundant
// m.add(*this);
return *this;
}
// add to current module
self& add()
{
// redundant
// boost::python::add(*this);
return *this;
}
private: // types
typedef objects::class_id class_id;
@@ -248,7 +231,7 @@ class class_ : public objects::class_base
// implementations
//
template <class T, class X1, class X2, class X3>
inline class_<T,X1,X2,X3>::class_(base const& parent_class)
inline class_<T,X1,X2,X3>::class_()
: base(typeid(T).name(), id_vector::size, id_vector().ids)
{
// register converters
@@ -258,16 +241,10 @@ inline class_<T,X1,X2,X3>::class_(base const& parent_class)
mpl::bool_t<is_copyable>()
, objects::select_holder<T,held_type>((held_type*)0).get()
, this->object());
// get the context to add the class to
handle<> parent(parent_class.object() ? handle<>(parent_class.object()) :
base::get_class_context_object(typeid(T).name(), object()));
// add the class to the current module
boost::python::detail::module_base::add(object(), parent);
}
template <class T, class X1, class X2, class X3>
inline class_<T,X1,X2,X3>::class_(char const* name, base const& parent_class)
inline class_<T,X1,X2,X3>::class_(char const* name)
: base(name, id_vector::size, id_vector().ids)
{
// register converters
@@ -277,14 +254,9 @@ inline class_<T,X1,X2,X3>::class_(char const* name, base const& parent_class)
mpl::bool_t<is_copyable>()
, objects::select_holder<T,held_type>((held_type*)0).get()
, this->object());
// get the context to add the class to
handle<> parent(parent_class.object() ? handle<>(parent_class.object()) :
base::get_class_context_object(name, object()));
// add the class to the current module
boost::python::detail::module_base::add(object(), parent);
}
template <class T, class X1, class X2, class X3>
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, handle<> const& fget)
{

View File

@@ -10,8 +10,6 @@
namespace boost { namespace python { namespace detail {
class module_info;
class BOOST_PYTHON_DECL module_base
{
public:
@@ -23,22 +21,14 @@ class BOOST_PYTHON_DECL module_base
void setattr(const char* name, PyObject*);
void setattr(const char* name, handle<> const&);
void add(type_handle const&); // just use the type's name
static module_info* get_module_info();
static void set_module_info(module_info& mi);
static handle<> get_prior_module();
static void set_prior_module(handle<> const& m);
static void add(type_handle const& class_obj, handle<> const& context);
// Return a reference to the Python module object being built
inline handle<> object() const;
protected:
module_base(handle<> const &m) : m_module(m) {}
void add_class(type_handle const& class_obj);
void add_class(type_handle const& class_obj, handle<> const& context);
private:
static module_info*& get_module_info_ref();
handle<> m_module;
static PyMethodDef initial_methods[1];
};
@@ -51,12 +41,6 @@ inline handle<> module_base::object() const
return m_module;
}
inline void module_base::add(type_handle const& class_obj, handle<> const& context)
{
module_base mb(get_prior_module());
mb.add_class(class_obj, context);
}
}}} // namespace boost::python::detail
#endif // MODULE_BASE_DWA2002227_HPP

View File

@@ -8,23 +8,13 @@
# ifndef BOOST_PYTHON_MODULE_INIT
# define PRE_INIT_FUNC(name) \
void init_module_base_##name() \
{ \
boost::python::detail::module_info mi(#name); \
boost::python::detail::module_base::set_module_info(mi); \
boost::python::module(); \
init_module_##name(); \
}
# if defined(_WIN32) || defined(__CYGWIN__)
# define BOOST_PYTHON_MODULE_INIT(name) \
void init_module_##name(); \
PRE_INIT_FUNC(name) \
extern "C" __declspec(dllexport) void init##name() \
{ \
boost::python::handle_exception(&init_module_base_##name); \
boost::python::handle_exception(&init_module_##name); \
} \
void init_module_##name()
@@ -32,14 +22,13 @@ void init_module_##name()
# include <boost/python/detail/aix_init_module.hpp>
# define BOOST_PYTHON_MODULE_INIT(name) \
PRE_INIT_FUNC(name) \
void init_module_##name(); \
extern "C" \
{ \
extern PyObject* _PyImport_LoadDynamicModule(char*, char*, FILE *); \
void init##name() \
{ \
boost::python::detail::aix_init_module(_PyImport_LoadDynamicModule, &init_module_base_##name); \
boost::python::detail::aix_init_module(_PyImport_LoadDynamicModule, &init_module_##name); \
} \
} \
void init_module_##name()
@@ -47,11 +36,10 @@ void init_module_##name()
# else
# define BOOST_PYTHON_MODULE_INIT(name) \
PRE_INIT_FUNC(name) \
void init_module_##name(); \
extern "C" void init##name() \
{ \
boost::python::handle_exception(&init_module_base_##name); \
boost::python::handle_exception(&init_module_##name); \
} \
void init_module_##name()

View File

@@ -13,7 +13,6 @@
# include <boost/python/class_fwd.hpp>
# include <boost/python/detail/module_base.hpp>
# include <boost/python/detail/module_init.hpp>
# include <boost/python/detail/module_info.hpp>
namespace boost { namespace python {
@@ -22,7 +21,7 @@ class module : public detail::module_base
public:
typedef detail::module_base base;
module(const char* name = "")
module(const char* name)
: base(name) {}
// Add elements to the module
@@ -34,8 +33,7 @@ class module : public detail::module_base
template <class T1, class T2 , class T3, class T4>
module& add(class_<T1,T2,T3,T4> const& c)
{
// redundant
// this->add_class(c.object());
this->add_class(c.object());
return *this;
}
@@ -53,14 +51,6 @@ class module : public detail::module_base
this->setattr(name, boost::python::make_function(fn, handler));
return *this;
}
static module get_prior_module()
{
return module(module_base::get_prior_module());
}
private:
module(handle<> const& m) : base(m) {}
};
//
@@ -90,19 +80,6 @@ inline module& module::add(PyTypeObject* x)
return *this;
}
template <class Fn>
inline void def(char const* name, Fn fn)
{
module::get_prior_module().def(name, fn);
}
template <class Fn, class ResultHandler>
inline void def(char const* name, Fn fn, ResultHandler handler)
{
module::get_prior_module().def(name, fn, handler);
}
}} // namespace boost::python
#endif // MODULE_DWA20011221_HPP

View File

@@ -39,12 +39,7 @@ struct BOOST_PYTHON_DECL class_base : private noncopyable
void add_property(char const* name, handle<> const& fget);
void add_property(char const* name, handle<> const& fget, handle<> const& fset);
void setattr(char const* name, handle<> const&);
static handle<> get_class_context_object(const char* name, type_handle const& class_obj);
protected:
static class_base const& empty_class_base();
private:
// construct an empty base class
class_base();
type_handle m_object;
};