[CastXML] how to print the exact same declaration as in the header ?

Michka Popoff michkapopoff at gmail.com
Sun Jul 24 17:44:36 EDT 2016


> On 23 Jul 2016, at 21:59, Matt <mattator at gmail.com> wrote:
> 
> I want the C function but pygccxml throws a
> "pygccxml.declarations.scopedef.multiple_declarations_found_t"
> exception because it considers the C++ code I think. In C there should
> be only one result since C doesn't accept overloads.

One may need to double-check the xml file that is generated.
The keep_xml flag can be used to keep the xml file, and pygccxml.utils.loggers.set_level(logging.DEBUG) can
be used to find out where the xml file is written (if you are not specifying the path manually).

I am not sure there is any test for what you want to achieve. Maybe we should
first write a minimal c++/c code example, demonstrating the problem.
There is a test called “unittests/plain_c_tester.py”, which is probably the only C-things
pygccxml supports.

There is a note under version 1.1.0 that handling of “C” functions was added.

I do not know of all the internals of pygccxml, as I did not write that tool
initially. We may need to explore the code to try to solve your problem.
Also, as we switched from gccxml to castxml, specific things like this
may not work out of the box or need further testing.

> Right now, I search for it with "decl =
> global_namespace.free_function(name=row["name"]) " . How can I tell
> pygccxml that I look only for the C versions ?

As said before, I have the feeling that the code in “unittests/plain_c_tester.py”
is showing what can be done with C functions. If we want to do more,
we may need to write more code to support that. But there may be already
some “hidden” features I am not aware of.

> Also, in most projects I know examples are in a top level directory or
> in the source so it's easy to find & use them. In pygccxml they are in
> the doc subfolders thus I wonder if it were doable to move them there
> ?

Never thought of that. I will try to move them, but I need to tweak the
tests that make sure that the examples are working.
Also, some lines in the examples are only there to be able to run
the tests on them; these lines are removed for the much cleaner output
on the documentation webpage: http://pygccxml.readthedocs.io/en/develop/examples.html <http://pygccxml.readthedocs.io/en/develop/examples.html>

Cheers

Michka


> 
> 2016-07-22 16:21 GMT+02:00 Michka Popoff <michkapopoff at gmail.com>:
>> Hi
>> 
>> thanks for the nice comments.
>> 
>> Using print on declarations in pygccxml is a nice way to debug you code,
>> but often you may not want to rely on the __str__ implementation in you real code.
>> 
>> The output of the __str__ method may vary depending on you compiler / platform / code,
>> and I can not guarantee that this will work in a reliable way in all the situations.
>> This is something I may add to the documentation; __str__ is for debugging
>> purposes only.
>> 
>> It is probably better to build the string you want by using the .name, .return_type,
>> .arguments ... attributes. This is often more flexible, and also more performant,
>> as you select only the things that you are interested in.
>> 
>> Cheers
>> 
>> Michka
>> 
>> 
>>> On 22 Jul 2016, at 16:10, Matt <mattator at gmail.com> wrote:
>>> 
>>> I found the code in declarations/free_calldef.py and hacked it
>>> locally, I might copy/paste the code in my script later then.
>>> 
>>> Sorry for the noise
>>> 
>>> 2016-07-22 15:36 GMT+02:00 Matt <mattator at gmail.com>:
>>>> Hi,
>>>> 
>>>> I've just started with pygccxml/castxml and I must admit it's quite
>>>> impressive: doc/examples and worked straightout of the box.
>>>> 
>>>> I want to use pygccxml to generate wrapper functions around glibc
>>>> functions. I can't use LD_PRELOAD or --wrap techniques so I have to
>>>> copy/paste the declarations of these functions which is a pain.
>>>> I am trying to automate this copy/paste via pygccxml.
>>>> 
>>>> So far, I have:
>>>> ==
>>>> func1a = global_namespace.free_function(name="printf")
>>>> print(func1a)
>>>> ==
>>>> which output:
>>>> extern int printf(__restrict__ char const * __format, ...) [free function]
>>>> is very near to what I want:
>>>> extern int printf(__restrict__ char const * __format, ...)
>>>> 
>>>> I have done dir(func1a) to see which members I could use and grepped
>>>> for __str__ to see the magic but miserably fail to find the location.
>>>> How could I output the same declaration as in the header please ?
>>>> 
>>>> 
>>>> Cheers
>>>> 
>>>> Nb: In the list of  programs using pygccxml you could add www.nsnam.org
>>> _______________________________________________
>>> CastXML mailing list
>>> CastXML at public.kitware.com
>>> http://public.kitware.com/mailman/listinfo/castxml
>> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/castxml/attachments/20160724/bd5ba11e/attachment.html>


More information about the CastXML mailing list