in reply to Re: 64 bit pointer to string
in thread 64 bit pointer to string

sure it fails with openbsd/sparc64:
fatal error: Bad address
so when the ioctl system call wants to write to that area i get the above error.
i tried P with g instead if l, even l! for native length longs... (also p with a \0 terminated string)
i don't really know what pointer types are common on 64 bit and how to adress them from perl...

Replies are listed 'Best First'.
Re: Re: Re: 64 bit pointer to string
by BrowserUk (Patriarch) on Sep 06, 2003 at 08:31 UTC

    I really don't know anything about perl on 64-bit systems, but in the absence of any other responses...

    What do you get if you do

    my $x = 'hello world!'; my $px = pack 'P', $x; print length $px; # Ought to print '8' on a 64-bit system print unpack 'p', $px; # Should print 'Hello world!'

    If that works, then Perl is packing the pointers correctly and you are 'using them wrong'. Sorry for such a vague diagnosis:)

    If that doesn't work, then you maybe have discovered a bug in 64-bit perl and should raise it to p5p.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

      Thanks for helping!
      Your code does the right thing and works. I think Perl5/OpenBSD 64bit does not like this pointer for its IOCTLs ...
      BTW this is the whole code:
      my $tocentry; my $toc=""; my $size=0; for(@tracks) { $toc.=" "; $size+=8; } if($os =~ /BSD/) { my $size_hi=int($size / 256); my $size_lo=$size & 255; if($BIG_ENDIAN) { # in 32bit: $tocentry=pack "CCCCP8l", $CDROM_MSF,0,$size_hi,$siz +e_lo,$toc; $tocentry=pack "CCCCP", $CDROM_MSF,0,$size_hi,$size_lo,$toc; # c +urrent version } else { $tocentry=pack "CCCCP8l", $CDROM_MSF,0,$size_lo,$size_hi,$toc; } ioctl(CD, $CDROMREADTOCENTRY, $tocentry) or die "cannot read track + info [$!] [$device]"; }
      Should I post in p5p?

        I wouldn't run off to p5p just yet...but that's me, you may get better and/or quicker answers there from someone who has a 64-bit system to play with. That said, of you go there, do so via the perl5porters@perl.com list rather than perlbug as what my snippet did prove is that this isn't a perlbug. Your just using it wrong:)

        One thing I notice is that you are attempting to pack a 16-bit numeric value by splitting it into two 8-bit values and using 'CC' and switching the bytes around to account for the endianess of the current system.

        A) I think that you are doing this wrongly.

        B) There is no need for you to do this sort of thing yourself. pack already has that smarts built-in, although it requires you to pass along some clue bats to enable it.

        pack has format specifiers 'n' and 'v' which will pack a 16-bit unsigned value from a number in a perl scalar, in either big-endian or little-endian format respectively.

        Also, you don't show where or how your $BIG_ENDIAN variable is being set, but you should take a look at the Config package which is a part of the standard distribution. In particular

        use Config; print $Config{ byteorder };

        will tell you the order of the bytes on the current system. It will probably return somethng like '12345678' or '78563412' on your system.

        Hope this helps.

        Update: You might also want to check out perlpacktut. It's about the best tutorial i've seen on pack. You may have a local copy, but it is fairly recent addition to the doc set,so the link above may help.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
        If I understand your problem, I can solve it! Of course, the same can be said for you.

      that works on both openbsd/sparc64 and openbsd/alpha (both 64-bit systems, the first being big endian and the second being little endian). on the openbsd/i386 system it prints '4' and 'hello world!' as expected.