readTempVar :: String
            -> (VARIANT -> IO (Ptr (Ptr b), Ptr (VARIANT)))
            -> VARIANT
            -> (Ptr b -> IO d)
            -> IO d
readTempVar atTy io p f = do
           tg <- readVariantTag p
           (x,v) <- 
              catchComException (io p) 
                 (\ ex -> do
                    hPutStrLn stderr ("VARIANT error: found type " ++ show (tg, atTy))
                    throwIOComException ex)
           x <- readPtr x  -- we always get a ty* back, so dereference it before using.
           f x  `always` (freeVariants 1 (castPtr v) >> free v) 
               -- _don't_ use freeMemVariants, as it ends up
               -- calling freeMemory (==CoTaskMemFree()),
               -- which isn't right ('v' is allocated by malloc()).
readTempVar :: String
            -> (VARIANT -> IO (Ptr (Ptr b), Ptr (VARIANT)))
            -> VARIANT
            -> (Ptr b -> IO d)
            -> IO d
readTempVar atTy io p f = do
           tg <- readVariantTag p
           (x,v) <- 
              catchComException (io p) 
                 (\ ex -> do
                    hPutStrLn stderr ("VARIANT error: found type " ++ show (tg, atTy))
                    throwIOComException ex)
           x <- readPtr x  -- we always get a ty* back, so dereference it before using.
           f x  `always` (freeVariants 1 (castPtr v) >> free v) 
               -- _don't_ use freeMemVariants, as it ends up
               -- calling freeMemory (==CoTaskMemFree()),
               -- which isn't right ('v' is allocated by malloc()).
readTempVar atTy io p f = do
           tg <- readVariantTag p
           (x,v) <- 
              catchComException (io p) 
                 (\ ex -> do
                    hPutStrLn stderr ("VARIANT error: found type " ++ show (tg, atTy))
                    throwIOComException ex)
           x <- readPtr x  -- we always get a ty* back, so dereference it before using.
           f x  `always` (freeVariants 1 (castPtr v) >> free v) 
               -- _don't_ use freeMemVariants, as it ends up
               -- calling freeMemory (==CoTaskMemFree()),
               -- which isn't right ('v' is allocated by malloc()).