lua-users home
lua-l archive

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


On Aug 24, 2015 3:49 PM, "Tim Hill" <drtimhill@gmail.com> wrote:
>
>
> > On Aug 24, 2015, at 12:12 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> >
> >> 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
> >
>
> +1 on this. I just walked our 22,000 lines of interface code in the current project, and of the 45 places where lua_pushlstring() was called, only one would ever pass a NULL (and of course was an easy fix). I think a doc fix is all that is needed.
>
> OTOH, adding a (debug version only) assert() might not be a bad thing.
>
> —Tim
>
>

Seems like exactly the kind of thing LUA_APICHECK is ideal for.