[31683] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2946 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 15 18:09:21 2010

Date: Sat, 15 May 2010 15:09:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 15 May 2010     Volume: 11 Number: 2946

Today's topics:
    Re: Debugging question: tracing the origin of an error. <stevem_clipthis_@clubtrout.com>
    Re: Debugging question: tracing the origin of an error. <ben@morrow.me.uk>
    Re: MinGW and Perl 5.12 - Windows 64 bits ActiveState <ben@morrow.me.uk>
    Re: MinGW and Perl 5.12 - Windows 64 bits ActiveState <dilbert1999@gmail.com>
    Re: MinGW and Perl 5.12 - Windows 64 bits ActiveState <dilbert1999@gmail.com>
    Re: perl format statement, how do I begin a line with a <john@castleamber.com>
    Re: perl format statement, how do I begin a line with a <stevem_clipthis_@clubtrout.com>
    Re: Tutorial question - perldoc perlxs - learning how t <dilbert1999@gmail.com>
    Re: Tutorial question - perldoc perlxs - learning how t <dilbert1999@gmail.com>
    Re: Tutorial question - perldoc perlxs - learning how t sln@netherlands.com
    Re: Tutorial question - perldoc perlxs - learning how t <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 15 May 2010 12:24:37 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: Debugging question: tracing the origin of an error.
Message-Id: <tECHn.8177$h57.1152@newsfe22.iad>

On 5/15/2010 5:39 AM, Tad McClellan wrote:
> Steve M<stevem_clipthis_@clubtrout.com>  wrote:
>
>> no one pointed out
>> any obvious no-no's
>
>>     $error =&Caller_error_path( $error,1,0 );
>
>
> You should lose that ampersand.
>
>
>      perldoc -q function
>
>          What's the difference between calling a function as&foo and foo()?
>
>


Hmmmm... Well, I got a comment. :-)

Bear with me being a little thick here, as I'm not sure I see a 
functional problem with the way I'm doing it.

First, I admit that my understanding of prototypes is not as strong as 
it might be since I rarely fiddle with them.

Nevertheless, my understanding is/was that using the '&' makes no 
difference except for passing the current @_ which makes no difference 
(as far as I can tell) if the called function does not address it's own 
@_ in any way.

The docs referenced seem to say the same thing (to me).
They show an example demonstrating the differing behavior, explain a 
usage for the behavior, but do not indicate one should not make a call 
as I have done above.

In the code referenced above, I *am* passing arguments and the docs (and 
Programming Perl) seem to say I'm correct in thinking '&' or not makes 
no difference in that case. Am I????

If the called function performed based on the existence of passed 
value(s), then I can see the point of worrying about it. On the other 
hand I would hope I'd know what a subroutine I was calling did, and I am 
aware of the issue, so.....

In short, is this a style/usage thing? Or am I totally missing some 
other potential problem?



TIA,



\s

-- 
"There is no use in your walking five miles to fish when you can depend 
on being just as unsuccessful near home." M. Twain


------------------------------

Date: Sat, 15 May 2010 22:01:56 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Debugging question: tracing the origin of an error.
Message-Id: <4ne3c7-peu1.ln1@osiris.mauzo.dyndns.org>


Quoth Steve M <stevem_clipthis_@clubtrout.com>:
> On 5/15/2010 5:39 AM, Tad McClellan wrote:
> > Steve M<stevem_clipthis_@clubtrout.com>  wrote:
> >
> >> no one pointed out
> >> any obvious no-no's
> >
> >>     $error =&Caller_error_path( $error,1,0 );
> >
> >
> > You should lose that ampersand.
<snip>
> In short, is this a style/usage thing? Or am I totally missing some 
> other potential problem?

It's mostly a style/usage thing. The biggest potential problem is that
the & calls ignore prototypes; a smaller (but IMHO just as important)
problem is that the & asks for a rather specific and rarely-wanted
feature that you don't need in this case, so anyone reading that code
has to think 'Why is that & there? Why does this call need to override
prototypes?'.

Ben



------------------------------

Date: Sat, 15 May 2010 15:53:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: MinGW and Perl 5.12 - Windows 64 bits ActiveState
Message-Id: <c3p2c7-7is1.ln1@osiris.mauzo.dyndns.org>


Quoth Dilbert <dilbert1999@gmail.com>:
> On 15 mai, 13:37, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth Dilbert <dilbert1...@gmail.com>:
> > > I have tried the command vcvarsall with "amd64", "x64", "ia64",
> > > "x86_amd64" and with "x86_ia64", but no success:
> >
> > > ++ C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC>vcvarsall
> > > amd64
> > > ++ The specified configuration type is missing.  The tools for the
> > > ++ configuration might not be installed.
> > > Well, not surprising at all, because the corresponding sub directories
> > > ("bin\amd64", "bin\ia64", "bin\x86_amd64" and "bin\x86_ia64") simply
> > > do not exist:
> >
> > It looks like you've either downloaded the wrong package,
> 
> I have downloaded it from
> http://msdn.microsoft.com/fr-fr/express/aa975050.aspx
> 
> is this the correct package ?
> is this the latest package?

Unless you have a good reason not to, I'd always download the English
versions. I've no idea if it is the case here, but in the past some MS
products have had language-specific versions which were missing
features.

The English version of VC9 can be downloaded from
http://www.microsoft.com/express/Downloads/ . This isn't the latest
version, but that isn't important: what matters is that it matches the
version used to build your Perl, especially with recent MS compilers
which have a nasty habit of introducing incompatible versions of libc
all the time. I don't know which compiler AS use for their 64bit builds:
I thought it was VC7, but I don't have a 64bit Win32 machine on hand to
check. The free download of VC7 was called 'Visual C++ 2003 Express
Edition', and may or may not still be available; search microsoft.com.

FWIW, all of this mess is why I gave up on ActivePerl a while ago. I'd
recommend getting
http://strawberryperl.com/download/strawberry-perl-5.12.0.1-64bit-v2.msi
which includes the correct compiler as part of the install.

Ben



------------------------------

Date: Sat, 15 May 2010 10:32:19 -0700 (PDT)
From: Dilbert <dilbert1999@gmail.com>
Subject: Re: MinGW and Perl 5.12 - Windows 64 bits ActiveState
Message-Id: <0da50bc6-1215-4819-a2f9-54ea449b1f8f@d12g2000vbr.googlegroups.com>

On 15 mai, 16:53, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Dilbert <dilbert1...@gmail.com>:
> > On 15 mai, 13:37, Ben Morrow <b...@morrow.me.uk> wrote:
> > > Quoth Dilbert <dilbert1...@gmail.com>:
> > > > I have tried the command vcvarsall with "amd64", "x64", "ia64",
> > > > "x86_amd64" and with "x86_ia64", but no success:
>
> > > > ++ C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC>vcvarsall
> > > > amd64
> > > > ++ The specified configuration type is missing. =A0The tools for th=
e
> > > > ++ configuration might not be installed.
> > > > Well, not surprising at all, because the corresponding sub director=
ies
> > > > ("bin\amd64", "bin\ia64", "bin\x86_amd64" and "bin\x86_ia64") simpl=
y
> > > > do not exist:
>
> > > It looks like you've either downloaded the wrong package,
>
> > I have downloaded it from
> >http://msdn.microsoft.com/fr-fr/express/aa975050.aspx
>
> > is this the correct package ?
> > is this the latest package?
>
> Unless you have a good reason not to, I'd always download the English
> versions. I've no idea if it is the case here, but in the past some MS
> products have had language-specific versions which were missing
> features.
>
> The English version of VC9 can be downloaded from
> http://www.microsoft.com/express/Downloads/.

I uninstalled the French version (took me an hour or so)
Then I downloaded and installed the English version from
http://www.microsoft.com/express/Downloads/ (the install went straight
ahead, there was no possibility to choose between 32 bits or 64 bits)

To my disappointment, the English version is also 32 bits only:

C:\>cl /?
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01
for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Also, the same situation with C:\Program Files (x86)\Microsoft Visual
Studio 10.0\VC>vcvarsall amd64 =3D=3D>The specified configuration type is
missing.  The tools for the configuration might not be installed. =3D=3D>
the corresponding sub directories ("bin\amd64", "bin\ia64", "bin
\x86_amd64" and "bin\x86_ia64") simply do not exist

> This isn't the latest
> version, but that isn't important: what matters is that it matches the
> version used to build your Perl, especially with recent MS compilers
> which have a nasty habit of introducing incompatible versions of libc
> all the time. I don't know which compiler AS use for their 64bit builds:
> I thought it was VC7, but I don't have a 64bit Win32 machine on hand to
> check. The free download of VC7 was called 'Visual C++ 2003 Express
> Edition', and may or may not still be available; search microsoft.com.
>
> FWIW, all of this mess is why I gave up on ActivePerl a while ago. I'd
> recommend getting
> http://strawberryperl.com/download/strawberry-perl-5.12.0.1-64bit-v2.msi
> which includes the correct compiler as part of the install.

I agree.

The recent experience with getting a C-compiler for Perl is what
tipped my scale today from Activestate to Strawberry.

Thanks for your help.


------------------------------

Date: Sat, 15 May 2010 13:18:43 -0700 (PDT)
From: Dilbert <dilbert1999@gmail.com>
Subject: Re: MinGW and Perl 5.12 - Windows 64 bits ActiveState
Message-Id: <3f8e34af-1771-4f55-b863-5753b40605e5@m4g2000vbl.googlegroups.com>

On 15 mai, 09:56, sisyphus <sisyphus...@gmail.com> wrote:
> On May 15, 3:41=A0am, Dilbert <dilbert1...@gmail.com> wrote:
> > Whatever the outcome of my battle with MS VC++ will be, I will be
> > relieved when "ppm install MinGW" works on 64 bit Windows.
>
> According to Jan Dubois, that probably won't be for a couple of months
> (at least). ActivePerl 5.12.0 needs some patching before it will work
> with the MinGW64 compilers. I have patches that enable this (included
> below)- they're a bit of a hack, and quite possibly *not* the way that
> ActiveState will deal with the issues. But they've been working fine
> for me, and you're welcome to give them a try. (I'd be interested to
> hear of any problems you strike if you do use them - feel free to
> email me at my CPAN address.)

[...Can't find your CPAN address...]

> For the MinGW64 compiler, you go tohttp://sourceforge.net/projects/mingw-=
w64/files
> , as you've already discovered. Under "Toolchains targetting Win64"
> grab either one of the "personal builds" or one of the "automated
> builds" that has been built for win64 mingw (not for linux or cygwin)
> - and make sure it's a 64-bit build (as they're also providing a 32-
> bit compiler). The "automated builds" are a cross-compiler with the
> names of the executables prefixed with "x86_64-w64-mingw32-" (ie
> "x86_64-w64-mingw32-gcc.exe", etc.), so it might be simpler if you
> choose the "sezero_20100428" build ("mingw-w64-bin_x86_64-
> mingw_20100428_sezero.zip"). My patches accommodate both types of
> build.
>
> Then just unzip and add the bin folder to the path.
>
> Patch to lib/ExtUtils/MM_Win32.pm (ActivePerl build 1200):
> [...]
> Patch to lib/ActivePerl/Config.pm (ActivePerl build 1200):
> [...]

I have downloaded and unzipped "mingw-w64-bin_x86_64-
mingw_20100515_sezero.zip" (that's "...20100515..." and not "...
20100428...") from http://sourceforge.net/projects/mingw-w64/files.

Then I added the "mingw64\bin" directory to the path.

Now, C:\>perl -V:make reports

C:\Users\CK\Documents\PerlModules\Text-CSV_XS\Text-CSV_XS-0.73>perl -
V:make
Set up gcc environment - 4.4.5 20100513 (prerelease) [svn/rev.159365 -
mingw-w64/oz]
make=3D'dmake';

But there is no dmake.exe anywhere on my Windows Vista 64 bits. =3D=3D> I
quickly google for "dmake" and I find =3D=3D> http://www.oooforum.org/forum=
/viewtopic.phtml?t=3D241
=3D=3D> if you are using windows use this use this link =3D=3D>
http://www.cpan.org/authors/id/GSAR/dmake-4.1pl1-win32.zip

So I download and unzip "dmake-4.1pl1-win32.zip" (it's a 32 bit app,
but that doesn't matter) and add the directory "dmake-4.1pl1-
win32" (that's where dmake.exe lives) to the path (also, please be
aware that "dmake.exe" relies on a file "startup\startup.mk", so you
make sure that this exists)

I also applied the two patches:
  - to lib/ExtUtils/MM_Win32.pm
  - to lib/ActivePerl/Config.pm

Now I want to download and make Text::CSV_XS, but unfortunately there
is an error "gcc.exe: CreateProcess: No such file or directory"

C:\Users\CK\Documents\PerlModules\Text-CSV_XS\Text-CSV_XS-0.73>dmake
cp CSV_XS.pm blib\lib\Text\CSV_XS.pm
C:\Perl64\bin\perl.exe C:\Perl64\lib\ExtUtils\xsubpp  -typemap C:
\Perl64\lib\ExtUtils\typemap  CSV_XS.xs > CSV_XS.xsc && C:\Perl64\bin\
perl.exe -MExtUtils::Command -e "mv" -- CSV_XS.xsc CSV_XS.c
C:/Users/CK/DOCUME~1/PROGRA~2/MINGW6~1/gcc.exe -c       -DNDEBUG -
DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DWIN64 -DCONSERVATIV
E -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -
DUSE_PERLIO -DPERL_MSVCRT_READFIX -DHASATTRIBUTE -fno-strict-aliasin
g -mms-bitfields -O2      -DVERSION=3D\"0.73\"    -DXS_VERSION=3D\"0.73\"
"-IC:\Perl64\lib\CORE"   CSV_XS.c
gcc.exe: CreateProcess: No such file or directory
dmake.exe:  Error code 1, while making 'CSV_XS.o'


------------------------------

Date: Sat, 15 May 2010 10:48:12 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <87iq6pnp37.fsf@castleamber.com>

Steve M <stevem_clipthis_@clubtrout.com> writes:

> On 5/14/2010 2:24 PM, Tad McClellan wrote:
>> John Bokma<john@castleamber.com>  wrote:
>>
>>> posting top not for you thank.
>>
>>
>> one good!
>>
>>
>
> Hmmmm... in the spirit of the endless quibble, shouldn't the
> punctuation operator lead, as in:
>
> !one Good

No, no, there is very little logic in top posting ;-)

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development


------------------------------

Date: Sat, 15 May 2010 12:25:45 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: perl format statement, how do I begin a line with a hash mark?
Message-Id: <tFCHn.8178$h57.206@newsfe22.iad>

On 5/15/2010 8:48 AM, John Bokma wrote:
> Steve M<stevem_clipthis_@clubtrout.com>  writes:
>
>> On 5/14/2010 2:24 PM, Tad McClellan wrote:
>>> John Bokma<john@castleamber.com>   wrote:
>>>
>>>> posting top not for you thank.
>>>
>>>
>>> one good!
>>>
>>>
>>
>> Hmmmm... in the spirit of the endless quibble, shouldn't the
>> punctuation operator lead, as in:
>>
>> !one Good
>
> No, no, there is very little logic in top posting ;-)
>

I stand corrected. :-)

\s

-- 
"There is no use in your walking five miles to fish when you can depend 
on being just as unsuccessful near home." M. Twain


------------------------------

Date: Sat, 15 May 2010 07:41:39 -0700 (PDT)
From: Dilbert <dilbert1999@gmail.com>
Subject: Re: Tutorial question - perldoc perlxs - learning how to write  XS-based code
Message-Id: <bfbb95f5-db4b-4d85-8462-1fcf76535563@v18g2000vbc.googlegroups.com>

On 15 mai, 14:17, Dilbert <dilbert1...@gmail.com> wrote:
> I am thinking about reading "perldoc perlxs"

[answering my own question]
"perldoc perlxstut" seems to be what I want -- stupid me, I didn't see
the obvious :)

I think I will start with "perldoc perlxstut", but if anybody knows of
other good tutorials about writing XS code, I am happy to add them to
my list.


------------------------------

Date: Sat, 15 May 2010 10:39:52 -0700 (PDT)
From: Dilbert <dilbert1999@gmail.com>
Subject: Re: Tutorial question - perldoc perlxs - learning how to write  XS-based code
Message-Id: <b6c51e55-ffbe-43fc-a79b-74758eeb89be@u21g2000vbr.googlegroups.com>

On 15 mai, 17:11, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Dilbert <dilbert1...@gmail.com>:
> > I would now like to get my hands dirty and learn how to
> > communicate between Perl and C from the bottom up using XS-code.

[ snip ]

> > For example, if I wrote a C-function
> > =A0 first_test(int i, double d, char* s)
> > that returns a list -- three values:
> > =A0* the first value is i - 1234
> > =A0* the second value is d / 4.2
> > =A0* the third value is a string "<".s.">".
>
> You don't. You write an XSUB, which is then converted into a C function
> by xsubpp.
>
> > My first beginner questions would be like:
> > =A0- How do parameters get passed into the C-function ?
>
> The generated bits handle pulling the parameters off the perl stack and
> putting them in C locals.
>
> > =A0- What happens if Perl gives a string, but the C-function expects a
> > double ?
> > =A0- What happens if Perl gives a double, but the C-function expects a
> > string ?
>
> Since xsubpp knows the types the function is expecting, it will
> auto-convert in the usual way. (This includes, for example, calling
> stingification on an overloaded object.) This process can be controlled
> using a 'typemap' (see perlxs), or you can write your XSUB to take SV *
> parameters instead and extract the value you want by hand.
>
> > =A0- How can a C-function return a list of values ?
>
> By using the supplied macros to push the list onto the perl stack.
>
> > =A0- Do I need to allocate (malloc ?) memory to return values ?
>
> Yes, but you should do so through the perl API.
>
> > =A0- Who is reponsible for garbage collections of the allocated memory =
?
>
> You are responsible for getting refcounts right. Perl will
> garbage-collect any SVs that go out of scope; you are responsible for
> writing a DESTROY method (or using magic) to make sure any other memory
> you've allocated gets freed. Perl doesn't have any system like Apache's
> pools, where you can allocate stuff and forget about it; nor does it
> have a true garbage collector.
>
> > =A0- Can I pass / return more complicated data structures (hashes of
> > hashes, lists of lists, etc...) ?
>
> Yes. It's a little awkward until you get used to it, but the perl API
> matches the operations you would perform in Perl pretty well. The most
> annoying part is having to do things one at a time: instead of writing
>
> =A0 =A0 return [1, 2, {a =3D> "b"}];
>
> you have to write something like (this is from memory, so might be
> incorrect)
>
> =A0 =A0 AV *av, HV *hv;
>
> =A0 =A0 av =3D newAV();
> =A0 =A0 RETVAL =3D newRV_noinc(av);
>
> =A0 =A0 av_push(av, newSViv(1));
> =A0 =A0 av_push(av, newSViv(2));
>
> =A0 =A0 hv =3D newHV();
> =A0 =A0 av_push(av, newRV_noinc(hv));
>
> =A0 =A0 hv_stores(hv, "a", newSVpvs("b"));
>
> Every line there performs an allocation, all of which will be freed when
> the SV in RETVAL goes out of scope. (RETVAL is a special local variable
> which is the simplest way of returning a scalar result from an XSUB.)
>
> > Many questions, but I don't expect an immediate answer. What I really
> > want to know is: what would be the best tutorial for me ?
>
> perlxstut would be a good place to start. After that you need to read
> perlxs, perlapi and perlguts, even if you don't understand it all right
> away.

Thanks for all your help, this is much appreciated and will get me
started on my journey.


------------------------------

Date: Sat, 15 May 2010 09:09:38 -0700
From: sln@netherlands.com
Subject: Re: Tutorial question - perldoc perlxs - learning how to write XS-based  code
Message-Id: <22htu5h9oam6e0clvqa9ni00o87n6idv11@4ax.com>

On Sat, 15 May 2010 05:17:47 -0700 (PDT), Dilbert <dilbert1999@gmail.com> wrote:

>I have been using swig http://www.swig.org/ to incorporate simple C
>subroutines into my Perl programs. That works fine, no complaint at
>all.
>
>However, I would now like to get my hands dirty and learn how to
>communicate between Perl and C from the bottom up using XS-code.
>
>I am thinking about reading "perldoc perlxs", but before I embark on
>that adventure, I would ask for your oppinion:
>
> - Would you recommed reading "perldoc perlxs" ?
> - Are there any other tutorials ?
>
>For example, if I wrote a C-function
>
>  first_test(int i, double d, char* s)
>
>that returns a list -- three values:
>
> * the first value is i - 1234
> * the second value is d / 4.2
> * the third value is a string "<".s.">".
>
>My first beginner questions would be like:
>
> - How do parameters get passed into the C-function ?
> - What happens if Perl gives a string, but the C-function expects a
>double ?
> - What happens if Perl gives a double, but the C-function expects a
>string ?
> - How can a C-function return a list of values ?
> - Do I need to allocate (malloc ?) memory to return values ?
> - Who is reponsible for garbage collections of the allocated memory ?
> - Can I pass / return more complicated data structures (hashes of
>hashes, lists of lists, etc...) ?
>
>Many questions, but I don't expect an immediate answer. What I really
>want to know is: what would be the best tutorial for me ?

 I would imagine Perl is written in C, where there is no stateless types.
Every thing is a strict type: ptr, int (32/16/8), char, struct, enum,union and
(...), etc. This is done to partition (format) memory, stack or otherwise.
Passing/returning data/value to/from functions follow ANSI C standards.
Some of your questions are on this level. For the answers to these questions,
you should learn C before you attempt xs interface.

-sln


------------------------------

Date: Sat, 15 May 2010 16:11:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Tutorial question - perldoc perlxs - learning how to write XS-based  code
Message-Id: <k6q2c7-5ns1.ln1@osiris.mauzo.dyndns.org>


Quoth Dilbert <dilbert1999@gmail.com>:
> I have been using swig http://www.swig.org/ to incorporate simple C
> subroutines into my Perl programs. That works fine, no complaint at
> all.
> 
> However, I would now like to get my hands dirty and learn how to
> communicate between Perl and C from the bottom up using XS-code.
> 
> I am thinking about reading "perldoc perlxs", but before I embark on
> that adventure, I would ask for your oppinion:
> 
>  - Would you recommed reading "perldoc perlxs" ?
>  - Are there any other tutorials ?
> 
> For example, if I wrote a C-function
> 
>   first_test(int i, double d, char* s)
> 
> that returns a list -- three values:
> 
>  * the first value is i - 1234
>  * the second value is d / 4.2
>  * the third value is a string "<".s.">".

You don't. You write an XSUB, which is then converted into a C function
by xsubpp.

> My first beginner questions would be like:
> 
>  - How do parameters get passed into the C-function ?

The generated bits handle pulling the parameters off the perl stack and
putting them in C locals.

>  - What happens if Perl gives a string, but the C-function expects a
> double ?
>  - What happens if Perl gives a double, but the C-function expects a
> string ?

Since xsubpp knows the types the function is expecting, it will
auto-convert in the usual way. (This includes, for example, calling
stingification on an overloaded object.) This process can be controlled
using a 'typemap' (see perlxs), or you can write your XSUB to take SV *
parameters instead and extract the value you want by hand.

>  - How can a C-function return a list of values ?

By using the supplied macros to push the list onto the perl stack.

>  - Do I need to allocate (malloc ?) memory to return values ?

Yes, but you should do so through the perl API.

>  - Who is reponsible for garbage collections of the allocated memory ?

You are responsible for getting refcounts right. Perl will
garbage-collect any SVs that go out of scope; you are responsible for
writing a DESTROY method (or using magic) to make sure any other memory
you've allocated gets freed. Perl doesn't have any system like Apache's
pools, where you can allocate stuff and forget about it; nor does it
have a true garbage collector.

>  - Can I pass / return more complicated data structures (hashes of
> hashes, lists of lists, etc...) ?

Yes. It's a little awkward until you get used to it, but the perl API
matches the operations you would perform in Perl pretty well. The most
annoying part is having to do things one at a time: instead of writing

    return [1, 2, {a => "b"}];

you have to write something like (this is from memory, so might be
incorrect)

    AV *av, HV *hv;

    av = newAV();
    RETVAL = newRV_noinc(av);

    av_push(av, newSViv(1));
    av_push(av, newSViv(2));

    hv = newHV();
    av_push(av, newRV_noinc(hv));

    hv_stores(hv, "a", newSVpvs("b"));

Every line there performs an allocation, all of which will be freed when
the SV in RETVAL goes out of scope. (RETVAL is a special local variable
which is the simplest way of returning a scalar result from an XSUB.)

> Many questions, but I don't expect an immediate answer. What I really
> want to know is: what would be the best tutorial for me ?

perlxstut would be a good place to start. After that you need to read
perlxs, perlapi and perlguts, even if you don't understand it all right
away.

Ben



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2946
***************************************


home help back first fref pref prev next nref lref last post