Index: libs/python/src/object/enum.cpp =================================================================== --- libs/python/src/object/enum.cpp (revisão 51177) +++ libs/python/src/object/enum.cpp (cópia de trabalho) @@ -14,7 +14,7 @@ #include #include -namespace boost { namespace python { namespace objects { +namespace boost { namespace python { namespace objects { struct enum_object { @@ -43,7 +43,7 @@ char* name = PyString_AsString(self->name); if (name == 0) return 0; - + return PyString_FromFormat("%s.%s.%s", mod, self_->ob_type->tp_name, name); } } @@ -139,15 +139,16 @@ dict d; d["__slots__"] = tuple(); d["values"] = dict(); + d["names"] = dict(); object module_name = module_prefix(); if (module_name) d["__module__"] = module_name; if (doc) d["__doc__"] = doc; - + object result = (object(metatype))(name, make_tuple(base), d); - + scope().attr(name) = result; return result; @@ -167,7 +168,7 @@ converter::registration& converters = const_cast( converter::registry::lookup(id)); - + converters.m_class_object = downcast(this->ptr()); converter::registry::insert(to_python, id); converter::registry::insert(convertible, construct, id); @@ -186,23 +187,24 @@ dict d = extract(this->attr("values"))(); d[value] = x; - + // Set the name field in the new enum instanec enum_object* p = downcast(x.ptr()); Py_XDECREF(p->name); p->name = incref(name.ptr()); + + dict names_dict = extract(this->attr("names"))(); + names_dict[x.attr("name")] = value; } void enum_base::export_values() { - dict d = extract(this->attr("values"))(); - list values = d.values(); + dict d = extract(this->attr("names"))(); + list items = d.items(); scope current; - - for (unsigned i = 0, max = len(values); i < max; ++i) - { - api::setattr(current, object(values[i].attr("name")), values[i]); - } + + for (unsigned i = 0, max = len(items); i < max; ++i) + api::setattr(current, items[i][0], items[i][1]); } PyObject* enum_base::to_python(PyTypeObject* type_, long x)