lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> what about making backwards compatible change in the future API releases?
> Given that responsible API user will need to check the pointer for NULL
> anyway (at least in the case above), maybe it would be reasonable to embed
> this check in the API and push synthetic empty string in case len is zero
> and the pointer is NULL. Either it will be done inside the API or each and
> every developer will be forced to write additional wrappers on top of
> pushlstring (or write unreliable code)...
> This change does not seem to break anything. Just adding this point to
> the documentation will force people to, well, read documentation in
> some buggy situations like this.

I thought about that. It is not true that "responsible API user will
need to check the pointer for NULL anyway".  I checked all uses of
lua_pushlstring in the standard libraries and some other libraries I
wrote (without knowing that it was wrong to pass NULL): I did not find
a single case that needed that check.  (Even though many places could
call lua_pushlstring with a zero length, none would pass NULL as a
pointer.) To make everybody pay for a check that seems to be rarely
needed is not a good idea. (This is a C API, after all.)

-- Roberto