[liblouis-liblouisxml] Re: Python bindings and output buffer size for lou_translate*

  • From: "John J. Boyer" <john.boyer@xxxxxxxxxxxxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Tue, 27 Jul 2010 04:00:42 -0500

I don't know much about Python, but couldn't the calling program provide 
the buffers and buffer sizes? inlen and outlen are supposed to be 
independent.

John

On Tue, Jul 27, 2010 at 12:48:04PM +1000, James Teh wrote:
> Hi all,
> 
> For lou_translate* in the Python bindings, we've made an assumption that 
> outlen should be 2 * inlen. However, this assumption is very wrong if 
> there are characters in the input which aren't defined in the specified 
> tables. In the case of undefined characters, the output is "'\xnnnn'" 
> for 16 bit unicode characters, which means that 1 input char becomes 8 
> chars in the output. Assuming that no one does anything ridiculous in 
> tables, this means that an outlen which is 8 * inlen should cover the 
> worst case scenario. I'd like to change the Python bindings to do this 
> and suggest that perhaps the documentation should be updated with a 
> similar guideline.
> 
> Note that this does not cover 32 bit unicode characters. I guess it's 
> possible that the bindings might be used on a 32 bit system. In this 
> case, the worst case scenario will be outlen = 12 * inlen.
> 
> An alternative is to keep checking whether translation wasn't completed 
> (i.e. inlen is less than its original value) and then increase outlen if 
> so, probably multiplying outlen by 2 each time. However, although this 
> is probably rare, it increases code complexity and is quite expensive, 
> since you have to keep re-translating the string in its entirety until 
> it completes.
> 
> What do people think?
> 
> Jamie
> 
> -- 
> James Teh
> Vice President
> NV Access Inc, ABN 61773362390
> Email: jamie@xxxxxxxxxxxx
> Web site: http://www.nvaccess.org/
> For a description of the software and to download it go to
> http://www.jjb-software.com

-- 
John J. Boyer; President, Chief Software Developer
Abilitiessoft, Inc.
http://www.abilitiessoft.com
Madison, Wisconsin USA
Developing software for people with disabilities

For a description of the software and to download it go to
http://www.jjb-software.com

Other related posts: