[zeromq-dev] [zproject] How to detect fresh = "1" attribute?

Michal Vyskocil michal.vyskocil at gmail.com
Fri Jan 8 19:21:26 CET 2016


Hi Joe, Pieter,

thanks for your opinions. While I am still convinced that declarations
+ comments maps 1:1 to API model, I do agree it won't work for hand
written code without imposing arbitrary rules on comments.

So I've changed the approach and added comment before method
declaration that model might need fresh = "1".

Thanks
Michal

On Mon, Jan 4, 2016 at 12:48 PM, Pieter Hintjens <ph at imatix.com> wrote:
> You can guess the fresh attribute by looking for a const modifier. In
> principle all strings that are not const are fresh. We could specify
> this as a rule, even. It does not apply to other structures though. As
> Joe points out, the model is always going to be more accurate than the
> code.
>
> On Mon, Jan 4, 2016 at 7:23 AM, Joe McIlvain <joe.eli.mac at gmail.com> wrote:
>> This is one example that I think demonstrates that we actually do encode
>> more information in the zproject API models than is found in the C headers.
>> This extra information is necessary for the API to understood to generate
>> well-behaved bindings, but is, as you've found, merely an understood
>> convention in C.
>>
>> It was this kind of property that made me first skeptical of your mkapi.py
>> project.  In general, I think it would be best to view it as a best effort
>> to translate C header to API model, useful so that the initial models for a
>> project moving to using zproject API models does not have to write the bulk
>> of the XML by hand.  However, after this point it's probably best to tweak
>> and continue maintenance using the established zproject workflow, modifying
>> the API model first when you modify your API, allowing the C header to be
>> generated.
>>
>> In general, I think the API models will always encode a bit more information
>> than you can (reliably) extract from the C header, and this is by design
>> (speaking as the one who designed most of the initial structure of the
>> models).  The API models were introduced for that specific reason - if the C
>> headers could reliably provide all of the information needed to generate
>> proper high-level bindings, then we wouldn't need the API models at all.  As
>> it turns out, the API models are a clean way to make explicit and
>> machine-readable the properties that were previously only encoded in highly
>> varied human-language comments.
>>
>> On Sun, Jan 3, 2016 at 12:04 PM, Michal Vyskocil <michal.vyskocil at gmail.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> during the last few weeks I have improved the mkapi.py enough the
>>> generated model is almost 1:1 with the one from czmq (I am testing
>>> zactor.xml right now).
>>>
>>> My biggest problem is how can I detect fresh = "1" attribute. Right
>>> now code adds fresh="1" to each function, which returns non const
>>> pointer. Which is far from true, as czmq usually have functions
>>> returing the low-level objects The question is how to deal with it?
>>>
>>> I see only solution:
>>> Detect phrase "caller is responsible for ..." or so in functions
>>> comment and add fresh="1" only for those functions.
>>>
>>> It is a bit hacky, but at least encourage developers to explicitly
>>> document ownership.
>>>
>>> What do you think?
>>>
>>> --
>>> best regards
>>>      Michal Vyskocil
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev at lists.zeromq.org
>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev



-- 
best regards
     Michal Vyskocil



More information about the zeromq-dev mailing list