Results 1 to 2 of 2

Thread: Allow enum keys in dictionaries for PHP

  1. #1
    trivian is offline Registered User
    Name: Thorvald Natvig
    Organization: Mumble
    Project: Mumble
    Join Date
    Jun 2008
    Posts
    14

    Allow enum keys in dictionaries for PHP

    Hi,

    My application uses dictionaries with enum keys, and this currently fails to work in PHP. The attached patch fixes this by masking the enum as an integer of the appropriate size. It's not the most elegant solution, but it works

    I'd love if you could look this over, and if acceptable give it the official "Patch #x" title so packagers will start picking it up (unless 3.3.2 is coming real soon?)


    Code:
    --- Ice-3.3.1/php/src/IcePHP/Marshal.cpp        2009-03-20 18:52:15.000000000 +0100
    +++ myIce-3.3.1/php/src/IcePHP/Marshal.cpp      2009-08-23 23:12:55.000000000 +0200
    @@ -378,6 +378,18 @@
             {
                 return new NativeDictionaryMarshaler(dict->keyType(), dict->valueType() TSRMLS_CC);
             }
    +        en = Slice::EnumPtr::dynamicCast(dict->keyType());
    +        if(en)
    +        {
    +            int count = static_cast<long>(en->getEnumerators().size());
    +            Slice::UnitPtr unit = Slice::Unit::createUnit(true, false, false, false);
    +            if(count <= 127)
    +              return new NativeDictionaryMarshaler(unit->builtin(Slice::Builtin::KindByte), dict->valueType() TSRMLS_CC);
    +            else if(count <= 32767)
    +              return new NativeDictionaryMarshaler(unit->builtin(Slice::Builtin::KindShort), dict->valueType() TSRMLS_CC);
    +            else
    +              return new NativeDictionaryMarshaler(unit->builtin(Slice::Builtin::KindInt), dict->valueType() TSRMLS_CC);
    +        }
         }
    
         Slice::ClassDeclPtr cl = Slice::ClassDeclPtr::dynamicCast(type);
    --- Ice-3.3.1/php/src/IcePHP/Profile.cpp        2009-03-20 18:52:15.000000000 +0100
    +++ myIce-3.3.1/php/src/IcePHP/Profile.cpp      2009-08-23 23:13:54.000000000 +0200
    @@ -1348,7 +1348,7 @@
     IcePHP::CodeVisitor::visitDictionary(const Slice::DictionaryPtr& p)
     {
         Slice::TypePtr keyType = p->keyType();
    -    if(!isNativeKey(keyType) && !_suppressWarnings)
    +    if(!isNativeKey(keyType) && !Slice::EnumPtr::dynamicCast(keyType) && !_suppressWarnings)
         {
             //
             // TODO: Generate class.

  2. #2
    puddle is offline Registered User
    Name: Daniel Hoffman
    Organization: webhoff.com.au
    Project: WHM activation modules
    Join Date
    Mar 2009
    Posts
    1
    any news on this making it into the RPM releases soon?

    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. slice2cs enum bug when in another namespace
    By linkman in forum Bug Reports
    Replies: 1
    Last Post: 04-16-2011, 09:22 AM
  2. My first Python code fails with dictionaries
    By Anhur in forum Help Center
    Replies: 2
    Last Post: 10-02-2006, 09:03 AM
  3. Java: going from String to Enum Type
    By nightnday in forum Help Center
    Replies: 2
    Last Post: 03-21-2006, 02:32 PM
  4. java dictionaries
    By xdm in forum Help Center
    Replies: 1
    Last Post: 03-03-2005, 09:03 PM
  5. desing question about dictionaries
    By xdm in forum Help Center
    Replies: 0
    Last Post: 11-23-2004, 12:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •