ditto +1, just have to make a point of it in the docs
On Dec 2, 2010, at 9:23 PM, Eric Balsa wrote: > I'm +1 for making stuff non-null and returning a pointer straight into > the MBuf like you propose. > > The only problem I see is that plugin writers will get direct access > to the MBuf and one could cast and change data directly (but these are > getters!). Before, you were operating on a copy of that data. However, > I think the benefits (plugins without mallocs) outweigh the > babysitting of developers who should know better than to cast away > const. > > --Eric > > On Thu, Dec 2, 2010 at 4:47 PM, Leif Hedstrom <zw...@apache.org> wrote: >> Hi, >> >> here's an idea, that could optimize memory allocation pressure significantly >> (I think) when writing plugins. Here's the deal; A few plugin APIs will make >> copies of the strings from the internal marshal buffers, before returning >> them, with the only purpose of making them NULL terminated. The odd thing, >> to me at least, is that all these APIs already take an argument (an int*), >> which gets set with the length of the string. >> >> I think it'd make much more sense to consistently make all APIs that deals >> with strings like this not be NULL terminated. This would require no API >> changes, just that the "semantics" would change. And I think the requirement >> to 'release' strings could then go away entirely (since they are just const >> char* pointers into the marshal buffers). >> >> Below are a few APIs that would change their "behavior", in that they no >> longer would gurantee NULL terminated strings (which is something most APIs >> don't anyways). >> >> Thoughts on this? >> >> -- leif >> >> const char * TSUrlSchemeGet(TSMBuffer bufp, TSMLoc obj, int *length); >> const char *TSUrlUserGet(TSMBuffer bufp, TSMLoc obj, int *length); >> const char *TSUrlPasswordGet(TSMBuffer bufp, TSMLoc obj, int *length); >> const char *TSUrlHostGet(TSMBuffer bufp, TSMLoc obj, int *length); >> const char *TSUrlPathGet(TSMBuffer bufp, TSMLoc obj, int *length); >> const char *TSUrlHttpParamsGet(TSMBuffer bufp, TSMLoc obj, int *length); >> const char *TSUrlHttpQueryGet(TSMBuffer bufp, TSMLoc obj, int *length); >> const char *TSUrlHttpFragmentGet(TSMBuffer bufp, TSMLoc obj, int *length); >> >> const char *TSMimeHdrFieldNameGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, >> int *length); >> const char *TSHttpHdrMethodGet(TSMBuffer bufp, TSMLoc obj, int *length); >> const char *TSHttpHdrReasonGet(TSMBuffer bufp, TSMLoc obj, int *length); >> >> TSReturnCode TSMimeHdrFieldValueStringGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc >> field, int idx, const char **value_ptr, int *value_len_ptr); >> >> >>