Skip to content
New issue

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

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

Already on GitHub? # to your account

Correct argument names of XS preparse() #82

Merged
merged 1 commit into from
Jul 27, 2019

Conversation

ppisar
Copy link
Contributor

@ppisar ppisar commented Jul 25, 2019

preparse C function had prototype:

SV * preparse(SV *dbh, const char *statement, IV ps_return, IV ps_accept, void *foo);

But XS function had a ps_return and ps_accept argument names swapped:

SV *
preparse(dbh, statement, ps_accept, ps_return, foo=Nullch)
SV * dbh

This patch corrects the discrepancy.

preparse C function had prototype:

SV * preparse(SV *dbh, const char *statement, IV ps_return, IV ps_accept, void *foo);

But XS function had a ps_return and ps_accept argument names swapped:

SV *
preparse(dbh, statement, ps_accept, ps_return, foo=Nullch)
    SV *        dbh

This patch corrects the discrepancy.
@timbunce
Copy link
Member

timbunce commented Jul 26, 2019

Hello @ppisar.
Won't this potentially break existing code that calls this function?
Wouldn't it be better to change the prototype to match the code?

@pali
Copy link
Member

pali commented Jul 26, 2019

Hi @timbunce! Look at this change properly as it is tricky. It just rename local variables...

Won't this potentially break existing code that calls this function?

... so answer to your question is that it cannot break anything as names of C variables does not matter for C/XS API.

Also if you rename ps_accept variable to whatever it still would work.

Prior this change, generated C code from XS was:

IV ps_accept = (IV)SvIV(ST(2));
IV ps_return = (IV)SvIV(ST(3));
...
RETVAL = preparse(dbh, statement, ps_accept, ps_return, foo);

And after this change it is:

IV ps_return = (IV)SvIV(ST(2));
IV ps_accept = (IV)SvIV(ST(3));
...
RETVAL = preparse(dbh, statement, ps_return, ps_accept, foo);

So ST(2) is still passed as third argument to preparse function and ST(3) as fourth argument, despite what is name of local variable.

@timbunce
Copy link
Member

It's easy to see that I've not worked on any XS code for too long. Thanks for the clear explanation @pali!

@timbunce timbunce merged commit a0e1755 into perl5-dbi:master Jul 27, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants