Ticket #2744: enum_with_duplicated_values_v2.patch
File enum_with_duplicated_values_v2.patch, 1.3 KB (added by , 14 years ago) |
---|
-
libs/python/src/object/enum.cpp
(this hunk was shorter than expected) 139 139 dict d; 140 140 d["__slots__"] = tuple(); 141 141 d["values"] = dict(); 142 d["names"] = dict(); 142 143 143 144 object module_name = module_prefix(); 144 145 if (module_name) … … 186 187 187 188 dict d = extract<dict>(this->attr("values"))(); 188 189 d[value] = x; 189 190 190 191 // Set the name field in the new enum instanec 191 192 enum_object* p = downcast<enum_object>(x.ptr()); 192 193 Py_XDECREF(p->name); 193 194 p->name = incref(name.ptr()); 195 196 dict names_dict = extract<dict>(this->attr("names"))(); 197 names_dict[x.attr("name")] = value; 194 198 } 195 199 196 200 void enum_base::export_values() 197 201 { 198 dict d = extract<dict>(this->attr(" values"))();199 list values = d.values();202 dict d = extract<dict>(this->attr("names"))(); 203 list items = d.items(); 200 204 scope current; 201 205 202 for (unsigned i = 0, max = len(values); i < max; ++i) 203 { 204 api::setattr(current, object(values[i].attr("name")), values[i]); 205 } 206 for (unsigned i = 0, max = len(items); i < max; ++i) 207 api::setattr(current, items[i][0], items[i][1]); 206 208 } 207 209 208 210 PyObject* enum_base::to_python(PyTypeObject* type_, long x)