mirror of
https://github.com/ilyakooo0/vty.git
synced 2024-11-25 19:22:08 +03:00
installUnicodeWidthTable: on range population failure, deallocate the custom table
This commit is contained in:
parent
7845acd565
commit
e07f287d07
@ -316,3 +316,18 @@ int vty_custom_table_ready()
|
||||
{
|
||||
return ((custom_table != NULL) && custom_table_ready);
|
||||
}
|
||||
|
||||
// Deallocate the custom width table.
|
||||
//
|
||||
// This does nothing if there is no allocated custom width table, or if
|
||||
// there is one but it is in use (marked ready). This is only useful if
|
||||
// an initial allocation succeeds, but range population fails, after
|
||||
// which point the application may want to deallocate the table to avoid
|
||||
// leaving it in an intermediate state.
|
||||
void vty_deallocate_custom_table()
|
||||
{
|
||||
if ((custom_table != NULL) && (!custom_table_ready)) {
|
||||
free(custom_table);
|
||||
custom_table = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ foreign import ccall unsafe "vty_activate_custom_table"
|
||||
foreign import ccall unsafe "vty_custom_table_ready"
|
||||
c_isCustomTableReady :: IO Int
|
||||
|
||||
foreign import ccall unsafe "vty_deallocate_custom_table"
|
||||
deallocateCustomTable :: IO ()
|
||||
|
||||
-- | Returns True if and only if a custom table has been allocated and
|
||||
-- marked as ready for use. Returns False otherwise.
|
||||
isCustomTableReady :: IO Bool
|
||||
@ -80,7 +83,8 @@ installUnicodeWidthTable table = do
|
||||
(rangeSize r)
|
||||
(rangeColumns r)
|
||||
|
||||
when (result /= 0) $
|
||||
when (result /= 0) $ do
|
||||
deallocateCustomTable
|
||||
error $ "installUnicodeWidthTable: error installing range " <>
|
||||
show r <> ", status " <> show result
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user