Ticket #2744: enum_with_duplicated_values.patch

File enum_with_duplicated_values.patch, 1.4 KB (added by hugo.lima@…, 14 years ago)

Patch to fix the problem

  • libs/python/src/object/enum.cpp

     
    185185    (*this).attr(name_) = x;
    186186
    187187    dict d = extract<dict>(this->attr("values"))();
    188     d[value] = x;
    189    
     188    if (d.has_key(value))
     189    {
     190        extract<tuple> checker(d[value]);
     191        if (!checker.check())
     192        {
     193            list v;
     194            v.append(d[value]);
     195            d[value] = v;
     196        }
     197        list result(d[value]);
     198        result.append(x);
     199        d[value] = tuple(result);
     200    }
     201    else
     202        d[value] = x;
     203
    190204    // Set the name field in the new enum instanec
    191205    enum_object* p = downcast<enum_object>(x.ptr());
    192206    Py_XDECREF(p->name);
     
    198212    dict d = extract<dict>(this->attr("values"))();
    199213    list values = d.values();
    200214    scope current;
    201215   
    202216    for (unsigned i = 0, max = len(values); i < max; ++i)
    203217    {
    204         api::setattr(current, object(values[i].attr("name")), values[i]);
     218        extract<tuple> checker(values[i]);
     219        if (checker.check()) {
     220            tuple t(checker());
     221            for (unsigned j = 0, maxj = len(t); j < maxj; ++j)
     222                api::setattr(current, object(t[j].attr("name")), t[j]);
     223        }
     224        else
     225        {
     226            api::setattr(current, object(values[i].attr("name")), values[i]);
     227        }
    205228    }
    206229 }
    207230