Ticket #1686 (closed bug: fixed)

Opened 5 years ago

Last modified 4 years ago

Null PMC access in find_method('signature') using Digest/MD5 from rakudo

Reported by: cosimo Owned by:
Priority: normal Milestone:
Component: none Version: 2.5.0
Severity: medium Keywords: find_method signature
Cc: Language: perl6
Patch status: Platform: linux

Description

I'm trying to use Parrot's Digest/MD5.pbc library from Rakudo. Here's the rakudo class I'm trying to use:

class Digest::MD5 {

     pir::load_bytecode('Digest/MD5.pbc');
 
     multi method md5_hex (Str $message) {
 
         my $md5_sum = Q:PIR {
             .local pmc md5sum, md5_sum_get
             md5sum = get_root_global ['parrot'; 'Digest'], '_md5sum'
             $P0 = find_lex '$message'
             $P1 = md5sum($P0)
             md5_sum_get = get_root_global ['parrot'; 'Digest'], '_md5_hex'
             %r = md5_sum_get($P1)
         };
 
         return $md5_sum;
     }
 
     multi method md5_hex (@message) {
         my Str $message = @message.join('');
         return Digest::MD5.md5_hex($message);
     }                                                                                                                                                            
 
}

and here's the test code:

use Test;
use Digest::MD5;

my @cases = (
    "Hello World"  , 'b10a8db164e0754105b7a99be72e3fe5',
    "Hello World\n", 'e59ff97941044f85df5297e1c302d260',
    ["a", "b"],      '187ef4436122d1cc2f40dc2b92f0eba0',
);

for @cases -> $values, $md5 {

    is(
        Digest::MD5.md5_hex($values), $md5,
        "MD5 of '$values' must be '$md5'"
    );

}

done_testing;

The error message is:

t/test.t ... Null PMC access in find_method('signature')
  in 'Digest::MD5::md5_hex' at line 11:lib/Digest/MD5.pm
  in main program body at line 19:t/test.t

My rakudo is:

cosimo@home:~/src/rakudo$ git rev-parse HEAD
f236549628d6455e7e679559daf103df423036fe
cosimo@home:~/src/rakudo$ perl6 -v
This compiler is built with the Parrot Compiler Toolkit, parrot revision 47640.

This exact code worked with older versions of Parrot and Rakudo (like several months old), but now it doesn't.

Can I do something to help with this problem?

Change History

Changed 4 years ago by cosimo

I've been trying to track down what happens here, and I managed to narrow the problem space a little bit. My Digest::MD5.md5_hex function wants to use two parrot library functions:

  • _md5sum()
  • _md5_hex()

Of these ones, only _md5sum() fails, while I can definitely use _md5_hex() just fine. In my total ignorance, I relate find_method('signature') to some sort of process by which parrot has to figure out the signature of the function being called.

So my probably bogus speculation is: since _md5sum() returns a pmc that is a FixedIntegerArray, there's something that breaks when returning that sort of pmc, while for regular strings it works just fine (_md5_hex).

...

Changed 4 years ago by cosimo

Just to not forget about it, the find_method('signature') problem goes away by replacing:

pir::load_bytecode('Digest/MD5.pbc');

with:

pir::load_bytecode('Digest/MD5.pir');

Then the error message becomes Null PMC access in invoke(), for which, because of #1694, you need to apply the following patch:

Index: runtime/parrot/library/Digest/MD5.pir
===================================================================
--- runtime/parrot/library/Digest/MD5.pir       (revision 47873)
+++ runtime/parrot/library/Digest/MD5.pir       (working copy)
@@ -68,6 +68,7 @@
 ###########################################################################
 # Main backend entry point

+.HLL 'parrot'
 .namespace ["Digest"]

 .sub _md5sum

The only remaining problem was that the code didn't "box" the returning string pmc. So I had to replace:

%r = $S0

with:

%r = box $S0

Changed 4 years ago by cosimo

This is still a problem in 2.6.0. Ticket to fix is #1694, that has a patch attached.

Alternative (simpler?) solution would be to just add .HLL 'parrot' to the MD5 library. The Perl6  Digest::MD5 class is broken without this patch.

Thanks,

Changed 4 years ago by plobsing

  • status changed from new to closed
  • resolution set to fixed

Both the .HLL 'parrot' prelude on the MD5 library and the patch on TT #1694 have been applied. This bug is double-fixed! ;-)

I've run the test code successfully. Closing ticket.

Note: See TracTickets for help on using tickets.