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

  • From: Michael Whapples <mwhapples@xxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Thu, 29 Jul 2010 23:19:23 +0100

Hello,
While I agree that the idea of setting the buffer ratio in python is not normal, if we can find that default which is acceptable to over 90% of users, then the majority don't need to be concerned with buffer sizes and only at most 10% have to do something not normal.

Anyway, its just occurred to me, why are we talking about setting buffer sizes not being normal, lets look at it from another angle. This default value idea offers out of the box working but gives the user of the bindings the option to configure should they desire. The other thing is it doesn't break existing software either.

Michael Whapples
On 29/07/10 19:14, James Teh wrote:
On 27/07/2010 8:32 PM, Michael Whapples wrote:
I don't
like the suggestion of try with one ratio, if translation fails retry
with a larger ratio until it succeeds, is there a situation where
translation may fail for another reason and how would such a system of
setting the ratio catch that?
If translation fails outright, it will return an error, which will be converted into an exception. It shouldn't only translate part of the text and then return success unless outlen was too small. Nevertheless, I still think retrying like this is very nasty.

Setting the ratio to 8 times seems a bit drastic, and it would need to
be higher if using 32-bit unicode, most of the time I doubt you would be
going anywhere near that sort of ratio. I get the feeling the answer for
what ratio is needed actually depends on what sort of translation is
being done (IE. You are much more likely to need 8 times if only
translating a character or two but you are probably going to be fine
with 2 or 4 when doing longer strings of text).
For a screen reader, I don't think you can necessarily make assumptions about the text you are displaying. Someone might be reading a document which is partially in a foreign language, for example.

So may be the answer is
have the ratio at a level which should be fine for over 90% of uses
I'd probably default this to 2, which is what we use at present.
but
make the ratio value configurable so that the few who need something
different can set it appropriately (IE. an application doing lots of
small translations may have the line
louis.bufferRatio = 8
I think this is probably the best approach. I'm not "happy" with it - a Python programmer shouldn't have to be concerned with buffer lengths - but I don't really see a better way. If people are happy with this, I'll implement it ASAP, as this is a major problem for NVDA.

An alternative is to always allocate a static buffer with a maximum size of 1 kb or something, but this seems pretty ugly and arbitrary to me.

Jamie


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

Other related posts: