Home Patches

Allow enum keys in dictionaries for PHP

triviantrivian Member Thorvald NatvigOrganization: MumbleProject: Mumble
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?)

--- 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.

Comments

  • puddlepuddle Member Daniel HoffmanOrganization: webhoff.com.auProject: WHM activation modules
    any news on this making it into the RPM releases soon?

    Thanks
Sign In or Register to comment.