mirror of
https://github.com/boostorg/python.git
synced 2026-01-23 05:42:30 +00:00
class_<> is now derived from object
[SVN r14594]
This commit is contained in:
@@ -37,7 +37,7 @@ void module_base::setattr(char const* name, handle<> const& x)
|
||||
{
|
||||
// Use function::add_to_namespace to achieve overloading if
|
||||
// appropriate.
|
||||
objects::function::add_to_namespace(m_module, name, x);
|
||||
objects::function::add_to_namespace(python::object(m_module), name, python::object(x));
|
||||
}
|
||||
|
||||
void module_base::add(type_handle const& x)
|
||||
|
||||
@@ -243,9 +243,12 @@ namespace objects
|
||||
// corresponding to the class being created, and the
|
||||
// rest corresponding to its declared bases.
|
||||
//
|
||||
class_base::class_base(
|
||||
char const* name, std::size_t num_types, class_id const* const types)
|
||||
|
||||
namespace
|
||||
{
|
||||
inline object
|
||||
new_class(char const* name, std::size_t num_types, class_id const* const types)
|
||||
{
|
||||
assert(num_types >= 1);
|
||||
|
||||
// Build a tuple of the base Python type objects. If no bases
|
||||
@@ -271,14 +274,20 @@ namespace objects
|
||||
// Call the class metatype to create a new class
|
||||
PyObject* c = PyObject_CallObject(upcast<PyObject>(class_metatype().get()), args.get());
|
||||
assert(PyType_IsSubtype(c->ob_type, &PyType_Type));
|
||||
m_object = type_handle((PyTypeObject*)c);
|
||||
|
||||
return object(python::detail::new_reference(c));
|
||||
}
|
||||
}
|
||||
|
||||
class_base::class_base(
|
||||
char const* name, std::size_t num_types, class_id const* const types)
|
||||
: object(new_class(name, num_types, types))
|
||||
{
|
||||
// Insert the new class object in the registry
|
||||
converter::registration& converters = const_cast<converter::registration&>(
|
||||
converter::registry::lookup(types[0]));
|
||||
|
||||
// Class object is leaked, for now
|
||||
converters.class_object = (PyTypeObject*)incref(m_object.get());
|
||||
converters.class_object = (PyTypeObject*)incref(this->ptr());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
@@ -301,7 +310,7 @@ namespace objects
|
||||
|
||||
void class_base::setattr(char const* name, handle<> const& x)
|
||||
{
|
||||
if (PyObject_SetAttrString(upcast<PyObject>(object().get()), const_cast<char*>(name), x.get()) < 0)
|
||||
if (PyObject_SetAttrString(this->ptr(), const_cast<char*>(name), x.get()) < 0)
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
@@ -317,7 +326,7 @@ namespace objects
|
||||
|
||||
BOOST_PYTHON_DECL type_handle registered_class_object(class_id id)
|
||||
{
|
||||
return objects::query_class(id);
|
||||
return query_class(id);
|
||||
}
|
||||
} // namespace objects
|
||||
|
||||
|
||||
@@ -156,12 +156,12 @@ namespace
|
||||
}
|
||||
|
||||
void function::add_to_namespace(
|
||||
handle<> const& name_space, char const* name_, handle<> const& attribute)
|
||||
object const& name_space, char const* name_, object const& attribute)
|
||||
{
|
||||
str const name(name_);
|
||||
PyObject* const ns = name_space.get();
|
||||
PyObject* const ns = name_space.ptr();
|
||||
|
||||
if (attribute->ob_type == &function_type)
|
||||
if (attribute.ptr()->ob_type == &function_type)
|
||||
{
|
||||
PyObject* dict = 0;
|
||||
|
||||
@@ -175,27 +175,27 @@ void function::add_to_namespace(
|
||||
if (dict == 0)
|
||||
throw_error_already_set();
|
||||
|
||||
handle<> existing( allow_null(PyObject_GetItem(dict, name.ptr())) );
|
||||
handle<> existing( allow_null(::PyObject_GetItem(dict, name.ptr())) );
|
||||
|
||||
if (existing.get())
|
||||
{
|
||||
if (existing->ob_type == &function_type)
|
||||
{
|
||||
static_cast<function*>(attribute.get())->add_overload(
|
||||
static_cast<function*>(attribute.ptr())->add_overload(
|
||||
static_cast<function*>(existing.get()));
|
||||
}
|
||||
}
|
||||
// Binary operators need an additional overload which returns NotImplemented
|
||||
else if (is_binary_operator(name_))
|
||||
{
|
||||
static_cast<function*>(attribute.get())->add_overload(
|
||||
static_cast<function*>(attribute.ptr())->add_overload(
|
||||
not_implemented_function());
|
||||
}
|
||||
}
|
||||
|
||||
// The PyObject_GetAttrString() call above left an active error
|
||||
PyErr_Clear();
|
||||
if (PyObject_SetAttr(ns, name.ptr(), attribute.get()) < 0)
|
||||
if (PyObject_SetAttr(ns, name.ptr(), attribute.ptr()) < 0)
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user