Pelagicore / gdbus-codegen-glibmm

Code generator for C++ D-Bus stubs and proxies using Giomm/Glibmm
GNU Lesser General Public License v2.1
23 stars 25 forks source link

Compile error for generated template function in proxy #28

Closed zxtwonder closed 6 years ago

zxtwonder commented 6 years ago

First of all, thank you so much for providing this great utility. There seems to be trivial issue with the generated template function.

Input method schema:

        <method name="SetProperty">
            <arg name="name" type="s" direction="in"/>
            <arg name="value" type="v" direction="in"/>
        </method>

Generated proxy template function (indent as generated):

    template <typename T>
    void SetProperty(
        std::string name,
        T value,
        const Gio::SlotAsyncReady &callback)
    {
        Glib::VariantContainerBase base;
        std::vector<Glib::VariantBase> params;
        Glib::Variant<Glib::ustring> name_param = Glib::Variant<Glib::ustring>::create(arg_name);
        params.push_back(name_param);
        Glib::Variant<Glib::Variant<T> > value_variantValue;
        value_variantValue = Glib::Variant<Glib::Variant<T> >::create(Glib::Variant<T>::create(value_param));
        params.push_back(value_variantValue);
        base = Glib::VariantContainerBase::create_tuple(params);

    m_proxy->call(
        "SetProperty",
        callback,
        base);
}

Comparing the generated template function and other functions, it seems that the function argument naming and the variantValue reference are inconsistent. Is it correct that the template function should be generated as the following?

    template <typename T>
    void SetProperty(
        std::string arg_name,
        T arg_value,
        const Gio::SlotAsyncReady &callback)
    {
        ...
        Glib::Variant<Glib::ustring> name_param = Glib::Variant<Glib::ustring>::create(arg_name);
        ...
        value_variantValue = Glib::Variant<Glib::Variant<T> >::create(Glib::Variant<T>::create(arg_value));
        ...

Related code: https://github.com/Pelagicore/gdbus-codegen-glibmm/blob/35bef0fab90efa2635c037fd6804eddb13063852/codegen_glibmm/codegen.py#L149

zxtwonder commented 6 years ago

After a further look, it seems that the function argument naming is different between .h and .cpp file - .h uses the original argument name specified in XML and .cpp prefixes them with "arg". This seems to be the root cause of the issue. (I haven't looked at the history around when "arg" prefix is added/removed though.)

But I think this inconsistency caused that the template function generated in header files cannot use the same naming schema as other function bodies generated in cpp files. As a result, should I just rename arg_name to name and value_param to value in the example above?

mardy commented 6 years ago

Hi @zxtwonder! Thanks for you bug report, indeed it looks like the generated files are wrong; it's a bit strange that we didn't catch this bug before.

Yes, it looks like a silly naming issue, and your suggestion should work.

zxtwonder commented 6 years ago

Mistakenly closed from my fork. Reopened.