[Python API] Fix python api for bytecode
This fixes an issue seen in https://github.com/iree-org/iree/pull/17278. MLIR bytecode can have a zero as the last byte depending on the IR. If this happens by accident parsing will fail. This PR checks if a buffer begins with the magic number from https://mlir.llvm.org/docs/BytecodeFormat/#magic-number and sets zero-termination to false if it does.
However I could not generate MLIR bytecode that ends with a zero other than the one in the PR. Even if I save the IR used in textual format and parse it again, some additional bytes are appended and it is not zero terminated anymore. I think this is because of some behavior in TF.
Still after reading a bit through https://mlir.llvm.org/docs/BytecodeFormat I think the check implemented in this PR is the correct behavior for bytecode.
Ugh, that broken llvm API strikes again. Thanks for the fix. Will review in detail soon, since this has been a trouble area and I need to focus on it
Force pushed because of DCO