Assignment of UnManagedStruct in Perl6

[email protected] (Simon Cozens)
Newsgroups perl.perl6.internals
Message-ID <[email protected]>
I'm writing an SQLite extension. I have it working fine in PIR, but the
bridge to Perl 6 is causing problems. Specifically, this Perl 6 code works:

SQLite::pmc_check(SQLite::open("test.db"));
# Returning 0x2d1efa0
# PMC 0xedf1a8 data pointer 0x2d1efa0
# PMC 0xedf1a8 data pointer 0x2d1efa0

But this code does not:

our $db; SQLite::pmc_check($db = SQLite::open("test.db"));
# Returning 0x2d1a850
# PMC 0x263f504 data pointer 0x2d1a850
# PMC 0x263f590 data pointer 0x0

SQLite::open is implemented in PIR, as follows:

.sub open
    .local pmc x
    x = open_wrapper("test.db")
    pmc_check(x)
    .return(x)
.end

pmc_check is a simple C function to tell me what's going on inside my
UnManagedStruct:

void pmc_check(PMC* pmc) {
    printf("PMC %p data pointer %p\n", pmc, pmc->data);
}

The difference is, of course, that it goes through a Perl 6 variable
assignment.

From this I can conclude that my PIR open() code correctly returns an
UnManagedStruct PMC; however, when Perl 6's assignment operator assigns
this to a variable, a new, empty UnManagedStruct PMC is created and no
longer contains the right data.

I have no idea how to fix this, but it looks like the assignment
operator is broken.

Simon
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.