[mythtv] [patch] mpegtables.cpp assert removal

Daniel Thor Kristjansson danielk at mrl.nyu.edu
Thu Jan 20 09:26:26 EST 2005


On Thu, 20 Jan 2005, Isaac Richards wrote:

]On Thursday 20 January 2005 12:08 am, Daniel Thor Kristjansson wrote:
]> This should of course never be triggered, but assuming my last assert
]> removal patch is applied, this removes the last assert on data in the
]> libs/libmythtv/mpeg directory. The remaining asserts can only be
]> triggered by programmer error. These asserts might help us when we
]> integrate the ATSC and DVB code.
]
]I'd really like to see all asserts removed from, well, everything.  If you're 
]thinking about something that can cause an error enough to write an assert to 
]test for it, you're thinking about it enough to write code to handle it 
]properly.

I can do that with the same scheme I used in the exit removal. Put all 
initilizers that can fail in an bool Init() function instead of in the 
class constructor.

But the asserts that remain in libmythtv/mpeg are in this form:
    ProgramAssociationTable(const PSIPTable &table) : PSIPTable(table)
    {
        assert(0x00==TableID());
    }
The way this is, and should be, used is something like
    if (0x00==psiptable.TableID()
    {
        ProgramAssociationTable pat = ProgramAssociationTable(psiptable);
        // do stuff with pat
    }

It could replaced with...
    ProgramAssociationTable() : errored(true) {}

    bool Init(const PSIPTable &table)
    {
	if (0x00==table.TableID()
        {
           *this = table;
           errored = false;
           return true;
        }
        errored = true;
        return false;
    }

    bool IsErrored()
    {
        return errored;
    }
Which would be used as follows...
    if (0x00==psiptable.TableID())
    {
        ProgramAssociationTable pat;
        bool success = pat.Init(psiptable)
        if (success) // == if (!pat.IsErrored())
        {
            // do stuff with pat
        }
	else
        {
            // handle error that will never happen because we checked
            // that the TableID() == 0 before init.
        }
    }

I'm not sure if this is an improvement... Now the user can ignore the
return value of Init(). Maybe you are thinking of some other error
checking mechanism?

-- Daniel


More information about the mythtv-dev mailing list