Commit b4189be2 authored by Simon van der Linden's avatar Simon van der Linden
Browse files

Don't set a default constructor for structures.

Update tests accordingly.

The reason for this change is that setting __new__ in the metaclass doesn't let
one overrides it afterwards, in a subclass (in my experience, at least, even
though it seems weird).

https://bugzilla.gnome.org/show_bug.cgi?id=603536
parent 4db68b95
......@@ -61,6 +61,13 @@ def Constructor(info):
class MetaClassHelper(object):
def _setup_constructors(cls):
for method_info in cls.__info__.get_methods():
if method_info.is_constructor():
name = method_info.get_name()
constructor = classmethod(Constructor(method_info))
setattr(cls, name, constructor)
def _setup_methods(cls):
for method_info in cls.__info__.get_methods():
name = method_info.get_name()
......@@ -87,13 +94,6 @@ class MetaClassHelper(object):
class GObjectMeta(gobject.GObjectMeta, MetaClassHelper):
def _setup_constructors(cls):
for method_info in cls.__info__.get_methods():
if method_info.is_constructor():
name = method_info.get_name()
constructor = classmethod(Constructor(method_info))
setattr(cls, name, constructor)
def __init__(cls, name, bases, dict_):
super(GObjectMeta, cls).__init__(name, bases, dict_)
......@@ -114,27 +114,6 @@ class GObjectMeta(gobject.GObjectMeta, MetaClassHelper):
class StructMeta(type, MetaClassHelper):
def _setup_constructors(cls):
constructor_infos = []
default_constructor_info = None
for method_info in cls.__info__.get_methods():
if method_info.is_constructor():
name = method_info.get_name()
constructor = classmethod(Function(method_info))
setattr(cls, name, constructor)
constructor_infos.append(method_info)
if name == "new":
default_constructor_info = method_info
if default_constructor_info is None and constructor_infos:
default_constructor_info = constructor_infos[0]
if default_constructor_info is not None:
cls.__new__ = staticmethod(Function(default_constructor_info))
def __init__(cls, name, bases, dict_):
super(StructMeta, cls).__init__(name, bases, dict_)
......
......@@ -3023,39 +3023,6 @@ test_gi__pointer_struct_inout (TestGIPointerStruct **struct_)
}
TestGIBoxedWithoutConstructorStruct *
test_gi_boxed_without_constructor_struct_copy (TestGIBoxedWithoutConstructorStruct *struct_)
{
TestGIBoxedWithoutConstructorStruct *new_struct;
new_struct = g_slice_new (TestGIBoxedWithoutConstructorStruct);
*new_struct = *struct_;
return new_struct;
}
static void
test_gi_boxed_without_constructor_struct_free (TestGIBoxedWithoutConstructorStruct *struct_)
{
g_slice_free (TestGIBoxedWithoutConstructorStruct, struct_);
}
GType
test_gi_boxed_without_constructor_struct_get_type (void)
{
static GType type = 0;
if (type == 0) {
type = g_boxed_type_register_static ("TestGIBoxedWithoutConstructorStruct",
(GBoxedCopyFunc) test_gi_boxed_without_constructor_struct_copy,
(GBoxedFreeFunc) test_gi_boxed_without_constructor_struct_free);
}
return type;
}
TestGIBoxedStruct *
test_gi_boxed_struct_copy (TestGIBoxedStruct *struct_)
{
......
......@@ -542,13 +542,6 @@ void test_gi__pointer_struct_out (TestGIPointerStruct **struct_);
void test_gi__pointer_struct_inout (TestGIPointerStruct **struct_);
typedef struct {
glong long_;
} TestGIBoxedWithoutConstructorStruct;
GType test_gi_boxed_without_constructor_struct_get_type (void) G_GNUC_CONST;
typedef struct {
glong long_;
} TestGIBoxedStruct;
......
......@@ -1246,29 +1246,28 @@ class TestStructure(unittest.TestCase):
del in_struct
del out_struct
def test_boxed_without_constructor_struct(self):
self.assertTrue(issubclass(TestGI.BoxedWithoutConstructorStruct, gobject.GBoxed))
def test_boxed_struct(self):
self.assertTrue(issubclass(TestGI.BoxedStruct, gobject.GBoxed))
struct = TestGI.BoxedWithoutConstructorStruct()
struct = TestGI.BoxedStruct()
self.assertTrue(isinstance(struct, TestGI.BoxedStruct))
self.assertTrue(isinstance(struct, TestGI.BoxedWithoutConstructorStruct))
del struct
new_struct = struct.copy()
self.assertTrue(isinstance(new_struct, TestGI.BoxedWithoutConstructorStruct))
def test_boxed_struct_new(self):
struct = TestGI.BoxedStruct.new()
self.assertTrue(isinstance(struct, TestGI.BoxedStruct))
del struct
del new_struct
def test_boxed_struct(self):
def test_boxed_struct_copy(self):
struct = TestGI.BoxedStruct()
self.assertTrue(isinstance(struct, TestGI.BoxedStruct))
new_struct = struct.copy()
self.assertTrue(isinstance(new_struct, TestGI.BoxedStruct))
del struct
del new_struct
del struct
def test_boxed_struct_return(self):
struct = TestGI.boxed_struct_return()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment