Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt5cpp model arguments in DefaultAPI methods should be pointers or passed by reference. #1475

Open
baverbud opened this issue Oct 30, 2015 · 2 comments

Comments

@baverbud
Copy link

The qt5cpp generator creates a method signature like this in SWGDefaultAPI:

void profileRoutePost(SWGProfile_route_body body, QString* token);

In C/CPP, this will cause 'body' to be copied. There is no proper copy constructor created for the models however, so pointers are re-used instead of new members being allocated.

When profileRoutePost returns, it will destroy the new copy of body and free the pointers. When the application eventually frees the original SWGProfile_route_body in the calling code, it will try to free the same pointers again, causing a segmentation fault due to a double free.

Performance wise, it's also really inefficient to be copying these objects unless that's really needed. Either passing by reference or pointer would fix the segfault and the unneeded copy.

@eppjo
Copy link

eppjo commented Nov 23, 2018

I recognized the same issue. Is there any workaround for version 2.3.1? I would prefer also the "by reference" option.

@eppjo
Copy link

eppjo commented Nov 29, 2018

Maybe I found a solution by patching the mustache files api-header.mustache and api-body.mustache.

api-header.mustache before:
{{#operations}}{{#operation}}void {{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});

api-header.mustache patched
{{#operations}}{{#operation}}void {{nickname}}({{#allParams}}{{^isBodyParam}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/isBodyParam}}{{/allParams}}{{#bodyParam}}{{{dataType}}}& {{paramName}}{{/bodyParam}});

Same for api-body.mustache:
{{classname}}::{{nickname}}({{#allParams}}{{^isBodyParam}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/isBodyParam}}{{/allParams}}{{#bodyParam}}{{{dataType}}}& {{paramName}}{{/bodyParam}}) {

Could this be a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants