Re: patch full of dark magic

"David E. Wheeler" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.sybase.devel
Message-ID <[email protected]>
On Aug 7, 2010, at 2:07 AM, Cosimo Streppone wrote:

> Hi DBI Win32 hackers,
> 
> David E. Wheeler wrote:
> 
>> I *think* it works the way it does because on Win32 it's not really a fork, but a thread, and when you exit in a child thread, it exits the parent, too. Correct?
> 
> Sounds reasonable?
> Alexandr's patch works fine for me. Passes all tests.
> That's fantastic!

Does my patch work, as well?

> However, I'd be willing to spend a couple hours if someone can
> guide me into compiling a debugging version with MSVC, and
> trying to find out why this segfaults.
> 
> My really *ignorant* wild guess is that "exit" just avoids the
> troubles bits of DESTROY() that are causing segfaults
> without actually solving the problem.

So the issue is that it segfaults when you exit in DESTROY (which is called during global destruction)? If so, this simple script should segfault for you:

    package Foo;
    sub DESTROY { exit; }
    my $foo = bless {}, 'Foo';

Or perhaps it's only in the child, in which case this would segfault:

    package Foo;
    sub DESTROY { exit; }
    my $foo = bless {}, 'Foo';

    my $pid fork();
    if ($pid) {
        # parent.
        wait;
    } else {
        # child.
    }


>> If so, then the attached patch should work just as well. Alexandr, can you give it a try?
>> 
>> [win32-destroy.patch]
> 
> Yours fails for me with the following output:
> 
> ok 18 - Should start active
> 
> not ok 19 - Child should be inactive on DESTROY#   Failed test 'Child should be inactive on DESTROY'
> 
> #   at ./t/16destroy.t line 104.
> ok 19 - Child should be inactive on DESTROY
> ok 20 - Should be active in DESTROY

Oops. Try "unless" to "if" in this bit, please:

            fail 'Child should be inactive on DESTROY'
                if $self->FETCH('Active');

Thanks!

David
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.