2.7 keyword as hash deprecation warnings for methods written in C

Hello list,

I have taken over maintenance of the LMDB gem, and since I recently upgraded to Ruby 2.7, I decided to run its test suite. I am getting the warning

Using the last argument as keyword parameters is deprecated

—but I’m getting it against methods that are written in C. I can find the *reference* (eg https://docs.ruby-lang.org/en/2.7.0/extension_rdoc.html#label-Method+Definition ), but I have had a hell of a time trying to find anything that looks like a definitive migration guide.

Note that nowhere in the test suite is anything actually calling methods of the autovivified hash form eg `:symbol => value`; they either take the form `symbol: value` or they are not present at all, so I can only assume the warning is being triggered in the C code.

I discovered there is an rb_scan_args_kw but the reference doesn’t explain how to use it. Indeed the behaviour seems inconsistent: it appears to work as expected in one context and then complains in a different but parametrically identical context. So, if anybody is sitting on any examples, could you please direct me to them?

For reference the branch is at https://github.com/doriantaylor/lmdb/tree/reconcile-2.7 .

Thanks,

···

--
Dorian Taylor
Make things. Make sense.

I am not sure if it helps you, but the issue is explained for methods written in Ruby at <https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/>, including migration advice.

  -quintus

···

Am 26. Februar 2020 um 13:53 Uhr -0800 schrieb dorian taylor:

Using the last argument as keyword parameters is deprecated

—but I’m getting it against methods that are written in C. I can find
but I have had a hell of a time trying to find anything that looks
like a definitive migration guide.

--
Blog: https://mg.guelker.eu

ah yes thanks I saw this but unfortunately I am pretty sure my problem is specifically with `rb_scan_args` (or I suppose `rb_scan_args_kw`). I am looking for an example of what to replace `rb_scan_args` with that will silence the warnings.

I will repeat that nowhere in the tests are the methods invoked with keywords as hashes but ruby 2.7 is still pumping out warnings. Indeed, calls that do not even have keyword parameters *at all* are causing keyword deprecation warnings. I can only conclude that the warnings are coming from the C code.

···

On Feb 27, 2020, at 6:48 AM, Marvin Gülker <post+rubytalk@guelker.eu> wrote:

I am not sure if it helps you, but the issue is explained for methods written in Ruby at <https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/>, including migration advice.

--
Dorian Taylor
Make things. Make sense.

I’m just going to update this thread for the record, total cargo cult but the solution I came up with to silence the deprecation warnings looks roughly like this:

#ifdef RB_SCAN_ARGS_LAST_HASH_KEYWORDS
        rb_scan_args_kw(RB_SCAN_ARGS_LAST_HASH_KEYWORDS,
                        argc, argv, "20:", &vkey, &vval, &option_hash);
#else
        rb_scan_args(argc, argv, "20:", &vkey, &vval, &option_hash);
#endif

...supplant with your own argspec of course.

···

--
Dorian Taylor
Make things. Make sense.