Browse Source

ivory backend: fix some pack size calculations

Pat Hickey 10 years ago
parent
commit
354dc5bc5c
2 changed files with 4 additions and 4 deletions
  1. 1 1
      src/Gidl/Backend/Ivory/Interface.hs
  2. 3 3
      src/Gidl/Backend/Ivory/Unpack.hs

+ 1 - 1
src/Gidl/Backend/Ivory/Interface.hs

@@ -146,7 +146,7 @@ schemaDoc interfaceName (Schema schemaName schema) = stack
                          , indent 2 $ stack
                              [ text "ident <- local (ival (" <+> ppr h <+> text ":: Uint32))"
                              , text "packInto arr o (constRef ident)"
-                             , text "packInto arr (o + sizeOf (Proxy :: Proxy (Stored Uint32))) m"
+                             , text "packInto arr (o + fromInteger (packSize (packRep :: PackRep (Stored Uint32)))) m"
                              , text "offs += required_size"
                              ]
                          , text "return sufficient_space"

+ 3 - 3
src/Gidl/Backend/Ivory/Unpack.hs

@@ -28,11 +28,11 @@ unpackModule modulepath =
     , "                   -> Ivory ('Effects r b (Scope s0)) ()"
     , "unpackWithCallback arr offs k = do"
     , "  o <- deref offs"
-    , "  let sufficient_remaining = ((o + sizeOf (Proxy :: Proxy a)) <?"
-    , "                               sizeOf (Proxy :: Proxy (Array n (Stored Uint8))))"
+    , "  let sufficient_remaining = ((o + fromIntegral (packSize (packRep :: PackRep a))) <?"
+    , "                               arrayLen arr)"
     , "  when sufficient_remaining $ do"
     , "    v <- local izero"
     , "    unpackFrom arr o v"
+    , "    offs += fromInteger (packSize (packRep :: PackRep a))"
     , "    k (constRef v)"
-    , "    offs += undefined"
     ]