Perl Module using XS

PERL

    Next

  • 1. need Net::AIMTOC help
    Hello all, Hoping someone here has some experience with the Net::AIMTOC module, which have just started to play with. Below is the complete working test sample i made, with the exception being the three ----insert somethign here------ lines. I know that the module works to the point of signing on. Since I keep the same screenname up on my AIM, when I run this module, it gets logged off of AIM, saying someone else signed on with same name. However, the IM never seems to get sent. Was hoping someone had some experience with this module and coudl shed some light for me. Thanks! Daniel #!/usr/bin/perl use warnings; use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Net::AIMTOC; my $q = new CGI; my $aim = Net::AIMTOC->new; my $screenname = "----insert screenname here------"; my $password = "----insert password here------"; my $buddy = "----insert screenname to IM here------"; my $msg = "Hello World\n"; my $out; $aim->connect; $aim->sign_on( $screenname, $password ); my $msgObj = $aim->recv_from_aol; $out = $msgObj->getMsg . "<br>"; $aim->send_im_to_aol( $buddy, $msg ); $msgObj = $aim->recv_from_aol; $out .= $msgObj->getMsg; $aim->disconnect; print $q->header(); print $out; exit 0;
  • 2. GD graph, Several Colors per Bar?
    Hi. I'm struggling with a GD::Graph -problem. I want to create a graph with bars by adding(+) the execution time from each little job within my nightbatch. lets say my nightbatch took 20 minutes. on day1 job1 took 2 min job2 took 10 min job3 took 8 min and on day2 job1 took 10 min job2 took 10 min job3 took 5 min If i create the graph by using the 20 or 25-minutes -value on Y-axis. Ill never get the trends for my smaller jobs in a good way. Y-axis (minutes) 25 |job3| <-red 20 |job2| <-blue 15 |job2| <-blue 10 |job1| <-green 5 |job1| <-green ----day2--------- X axis date I'm pretty lousy at explaining things, but perhaps there's someone out there that understands and has got a suggestion on how to solve this? Regards!

Perl Module using XS

Postby Rajan S » Mon, 05 May 2008 06:09:58 GMT

Hello "XS  Gurus":
I am trying to develop a perl extension using XS that would execute a DB2's 
'.sqc' generated c executable.( equivalent of Oracle's pro*c generated 
executable). The 'C' executable executes fine by itself.  I am having a hard 
time getting the perl module work.
I added in the '.xs' file the Xsubb for the function that is declared in the 
'C' program.
In the Makefile.PL, I added the object files generated from the 'C' program 
and also the path where the object file can be fouind.
Still, the make process does not succeed in building the 'C' function into 
the Perl module.
Could anyone show pointers as to what i am missing
thanks
Rajan


use 5.008008;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
        NAME              => 'RajanT',
        VERSION_FROM      => 'lib/RajanT.pm', # finds $VERSION
        PREREQ_PM         => {}, # e.g., Module::Name => 1.1
        ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
        (ABSTRACT_FROM  => 'lib/RajanT.pm', # retrieve abstract from module
        AUTHOR         => 'Abishek Rajan < XXXX@XXXXX.COM >') : ()),
        LIBS              => [''], # e.g., '-lm'
        DEFINE            => '', # e.g., '-DHAVE_SOMETHING'
        INC               => '-I. -I/home/db2inst2', # e.g., 
'-I. -I/usr/include/other'
        MYEXTLIB => 'rlib/libmylib$(LIB_EXT)',
                # Un-comment this if you add C files to link with later:
                OBJECT            => '$(example2.o)', # link all the C files 
too
);
if  (eval {require ExtUtils::Constant; 1}) {
# If you edit these definitions to change the constants used by this module,
# you will need to use the generated const-c.inc and const-xs.inc
# files to replace their "fallback" counterparts before distributing your
# changes.
my @names = (qw(TESTVAL));
ExtUtils::Constant::WriteConstants(
NAME         => 'RajanT',
NAMES        => \@names,
DEFAULT_TYPE => 'IV',
C_FILE       => 'const-c.inc',
XS_FILE      => 'const-xs.inc',
);
}
else {
use File::Copy;
use File::Spec;
foreach my $file ('const-c.inc', 'const-xs.inc') {
my $fallback = File::Spec->catfile('fallback', $file);
copy ($fallback, $file) or die "Can't copy $fallback to $file: $!";
}
}

sub MY::postamble {
'
$(MYEXTLIB): rlib/Makefile
        cd rlib && $(MAKE) $(PASSTHRU)
';




Re: Perl Module using XS

Postby Ilya Zakharevich » Wed, 07 May 2008 09:31:22 GMT

[A complimentary Cc of this posting was sent to
Rajan S
< XXXX@XXXXX.COM >], who wrote in article <L%4Tj.31191$ XXXX@XXXXX.COM >:

A way to ask meaningful (meaning sufficiently complete) questions?

Hope this helps,
Ilya

Re: Perl Module using XS

Postby Sherman Pendley » Thu, 08 May 2008 00:20:43 GMT

"Rajan S" < XXXX@XXXXX.COM > writes:


...


DBI. Connecting to Oracle from Perl is a problem that was solved a long,
long time ago.

sherm--

-- 
My blog:  http://www.**--****.com/ 
Cocoa programming in Perl:  http://www.**--****.com/ 

Similar Threads:

1.Using Module::Build to XS

Hi,

I have volunterred to maintain the LSF::Base and LSF::Batch modules on
CPAN , I am in the process of rewriting the module's Makefile.PL
(which uses the ExtUtils::MakeMaker) to use the Module::Build's
Build.PL process. Unfortunately I have not been very successful in
writing the Build.PL to do all the complies. Also I have not been able
to gather any information regarding the use of Module::Build to do XS
complies. Any inputs on where I can get this information would be
really helpful.

I have tried to write the Build.PL by using the following code snippet
but this was not able to create the shared object for Dynaloader to
load.

my $builder = Module::Build->new(
    module_name         => 'LSF::Base',
    ...
    c_source             => 'lib/',
    include_dirs        => [ $lsf_includedir ] ,
    extra_linker_flags  => $libs,
    extra_compiler_flags => '-DPERL_POLLUTE',
    create_makefile_pl   => 'traditional'
);


Also any inputs on the Module::Build's equivalent of the below
Mafile.PL will be greatly appreciated.

WriteMakefile(
    'NAME'         => 'LSF::Base',
    'VERSION_FROM' => 'Base.pm',
    'LIBS'         => [$libs ],
    'DEFINE'       => '-DPERL_POLLUTE',
    'OBJECT'       => '$(O_FILES)',
    'INC'	       => "-I$lsf_includedir"
);

If this is a RTFM please do scream at me

Thanks
Raga

2.need template for an XS module using two or mor classes

Hi,

  I created with the tool "h2xs" a template for a perl package called

	"perlmsgque"

  in this package I want to add a "MqS" and a "MqSException" class.

  both class's should use an individual "*.xs" file called MqS.xs
  and MqSException.xs.

  I'm not able to get anything useful working with the current perl
  documentation.

  it seems that multiple packages into a single module is not
  covered

  one package per module is possible but multiple ....
  
  error message I get: Base class package "MqS" is empty

  even if MqS is filled ..


mfg

  Andreas Otto



3.Problem using more than 1 module in Windows (XS) - please help

Hi all
	I have a problem that I am running into while using Perl XS to build
an interface to my C++ library. This is on a windows machine with perl
5.6.1. I was able to use PerlXS to expose out different 'c++
classes' that my API supports. I wrote the .XS files for each of
these objects and now I am able to make a simple test.pl file and use
these objects from Perl. The problem comes when I try to use more than
1 object (module) in a single .pl file. Here would an example

========== working example perl script  ================

use lib "C:/Documents and Settings/myusername/Desktop/perl
experiment/api";
use MyDataReader;
my $dr = new MyDataReader("hsd_demo_pre");
$dr->execQuery("select * from bug");
print "fields: " . $dr->getFieldCount() . "\n";


================== perl script giving problem =============
use lib "C:/Documents and Settings/myusername/Desktop/perl
experiment/api";
use MyDataReader;

use MyAdmin;   # Adding this line gives problems


my $dr = new MyDataReader("hsd_demo_pre");
$dr->execQuery("select * from bug");
print "fields: " . $dr->getFieldCount() . "\n";


========= Error Message ==================

C:\Documents and Settings\myusername\Desktop\perl experiment\api>perl
test.pl
Can't load 'C:\Documents and Settings\ myusername \Desktop\perl
experiment\api/5.6.1
/MyAdmin.dll' for module MyAdmin: load_file:Attempt to access invalid
address at C
:/Perl/lib/DynaLoader.pm line 206.
Compilation failed in require at test.pl line 11.
BEGIN failed--compilation aborted at test.pl line 11.


So the problem shows up when I use more than one 'use' statements
in a perl script. Its important to note here that I can use the
'MyAdmin' module by itself just fine. So its not aproblem with that
module. The problem is only when I try to use more than 1 module in a
single perl script.

==================== Makefile.PL ===================
use ExtUtils::MakeMaker;
$CC = 'cl';
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile( 'NAME' => 'MyDataReader',
               'VERSION' => '0.10',
               'DEFINE'	=> '-TP -EHsc',     # e.g., '-DHAVE_SOMETHING'
               'CC' => $CC,
               'LDDLFLAGS' => '-nologo -libpath:"C:\Perl\lib\CORE"
-machine:x86',
			   'LIBC' => 'msvcrtd.lib',
			   'LDLOADLIBS' => 'oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrtd.lib',
			   'CCFLAGS' => '-nologo -O1 -MDd -DNDEBUG -DWIN32 -D_CONSOLE
-DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX',
               'LD' => '$(CC)',
               'XSOPT' => '-C++',
			   'OPTIMIZE' => '-O1 -MDd -DNDEBUG',
               'PERM_RW' => '664',
               'PERM_RWX' => '775',
               'TYPEMAPS' => ['perlobject.map']    ,
			    'INC'      => "-Iinclude",
          	'MYEXTLIB' => 'lib\myexternalapi.lib'
		       );

========== end =========

4.Perl XS Module Build Error

Hi,

I am trying to rebuild our XS module using the newly installed Perl
5.8.4 with Dynamic Loading and 64-bit Integers enabled.  During the XS
make process, I ran into the following error message.  Can someone
explain to me what the error is about?

=========================================
LD_RUN_PATH="" g++  -shared -L/usr/local/lib HSDAdmin.o  -o
blib/arch/auto/HSDAdmin/HSDAdmin.so   ../../libhsd.a
/nfs/site/proj/vt/dev/hsd/vendor/freetds/0.62.3.bn1/lib/i386_linux24/libsybdb.a
/nfs/site/proj/vt/dev/hsd/vendor/freetds/0.62.3.bn1/lib/i386_linux24/libtds.a
/nfs/site/proj/vt/dev/hsd/vendor/boost/1.30.0/lib/i386_linux24/libboost_regex.a
../../libhsd.a(libhsd_a-HSDAdmin.o): In function
`HSDAdmin::getLUVal(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::list<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >&)':
/users/pptran/hsd/build/api/../../api/src/HSDAdmin.cpp:1118: multiple
definition of `HSDAdmin::getLUVal(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::list<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >&)'
HSDAdmin.o:/users/pptran/hsd/build/api/5.8.4/HSDAdmin/HSDAdmin.xs:70:
first defined here
/usr/intel/pkgs/gcc/3.1/bin/gld: Warning: size of symbol
`HSDAdmin::getLUVal(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::list<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >&)' changed from
2470 to 3226 in ../../libhsd.a(libhsd_a-HSDAdmin.o)
../../libhsd.a(libhsd_a-HSDAdmin.o): In function
`HSDAdmin::getSMParentValue(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::list<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >&)':
/users/pptran/hsd/build/api/../../api/src/HSDAdmin.cpp:1196: multiple
definition of `HSDAdmin::getSMParentValue(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::list<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >&)'
HSDAdmin.o:/users/pptran/hsd/build/api/5.8.4/HSDAdmin/HSDAdmin.xs:149:
first defined here
/usr/intel/pkgs/gcc/3.1/bin/gld: Warning: size of symbol
`HSDAdmin::getSMParentValue(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::list<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >&)' changed from 2470 to 3110 in
../../libhsd.a(libhsd_a-HSDAdmin.o)
collect2: ld returned 1 exit status
make[1]: *** [blib/arch/auto/HSDAdmin/HSDAdmin.so] Error 1
make[1]: Leaving directory
`/fs37/home.directory.1/pptran/hsd/build/api/5.8.4/HSDAdmin'
make: *** [all-local] Error 2
=============================================

Again, thanks in advance!

Phuong P Tran

5.Leaking memory in Perl XS Module

Hi Everyone,

I've been staring at this for hours now and I can't work out where I'm
leaking memory in a perl XS module I'm working on. Basically, I need to take
a tree of C structures:

    typedef struct _SGraph {
        char *name;
        int size;
        Graph list[];
    } * Graph;

with a given head pointer and iterate through the graph and produce Perl
hashes which look like { name => "__root__", parent => undef, list = [ {
name => "child" }, parent => (ref to parent), list = ... } ]. I've got the
algorithm working a number of different ways but each one leaks memory. I'm
sending the current implementation along with this post, sorry for the long
post, this is the shortest example that demonstrates the issue.

Thanks,
Shaun

SV *RvFromRv_noinc(SV *ptRv)
{
   return(newRV_noinc(SvRV(ptRv)));
}

HV *MakeHash(Graph ptGraph, SV *ptParent)
{
   static HV *ptGraphStash = NULL;
   HV *ptHash;
   SV *ptSubHash;
   AV *ptArray;
   int i;
   SV *ptResult;

   if (ptGraphStash == NULL)
   {
      ptGraphStash = gv_stashpv("OGDL::Graph", 0);
      if (!ptGraphStash)
         ptGraphStash = (HV *) -1;
   }

   ptHash = (HV *) newHV();

   if (!ptParent)
      /* Storing &PL_sv_undef does not work */
      hv_fetch(ptHash, "parent", 6, 1);
   else
      /* Store the reference to our parent */
      hv_store(ptHash, "parent", 6, RvFromRv(ptParent), 0);

   hv_store(ptHash, "name", 4, newSVpv(ptGraph->name, 0), 0);

   ptResult = newRV_noinc((SV *) ptHash);

   ptArray = newAV();
   av_extend(ptArray, ptGraph->size);
   for (i = 0; i < ptGraph->size; i++)
   {
      ptSubHash = MakeHash(ptGraph->nodes[i], ptResult);
      av_push(ptArray, RvFromRv_noinc((SV *) ptSubHash));
   }

   hv_store(ptHash, "list", 4, newRV_noinc((SV *) ptArray), 0);

   if (ptGraphStash && (ptGraphStash != (HV *) -1))
      sv_bless(ptResult, ptGraphStash);

   return(ptResult);
}

MODULE = OGDL::NativeParser      PACKAGE = OGDL::NativeParser

SV *GraphFile(char *sFile)
{
   SV *ptResult = NULL;
...
    ptResult = MakeHash(*ptParser->g, NULL);

    return(ptResult);
}

SV *
load(file)
      char *file
   PREINIT:
      Graph ptGraph = NULL;
   CODE:
      /* Create perl hashes to return */
      RETVAL = GraphFile(file);
   OUTPUT:
      RETVAL



6. building C DLL for calling from Perl using (*.XS)

7. Loading external module from XS file?

8. Modules for XS.



Return to PERL

 

Who is online

Users browsing this forum: No registered users and 11 guest