bh has asked for the wisdom of the Perl Monks concerning the following question:
I can test the existence of 'foo' in $h1 with XS as follows:my $h1; my $h2; $h2->{'bar'} = 1; $h1->{'foo'} = $h2;
I cannot test for 'bar' because when I get the value of 'foo' (which is another hash reference) it appears not to be the right kind of structure in the following code:void mhash1(key1, h1) char* key1 HV* h1 CODE: I32 klen1 = strlen(key1); if ( hv_exists(h1, key1, klen1) ) { }
The following Perl code results in a segmentation fault:void mhash2(key1, h1, key2) char* key1 char* key2 HV* h1 CODE: I32 klen1 = strlen(key1); I32 klen2 = strlen(key2); if ( hv_exists(h1, key1, klen1) ) { SV** h2r = hv_fetch(h1, key1, klen1, 0); HV* h2 = (HV*)*h2r; if ( hv_exists(h2, key2, klen2) ) { printf("%s\n", "found it!"); } }
Thank you!#!/usr/bin/perl use strict; use warnings; use MyTest; my $h1; my $h2; $h2->{'bar'} = 1; $h1->{'foo'} = $h2; MyTest::mhash2('foo', $h1, 'bar');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing a multi-dimensional hash within an XS routine
by Anonymous Monk on Apr 03, 2016 at 19:08 UTC | |
by bh (Initiate) on Apr 03, 2016 at 21:59 UTC | |
by ikegami (Patriarch) on Apr 04, 2016 at 20:18 UTC |