Getting Segmentation fault



Hello everyone,

I'm trying to call 'C' routine from perl script. I have static library
(libFile.a) where I can get object code of
this routine and I have linked it with my perl script. This perl script get
compile but after running it I'm getting
segmentation fault. See code below for reference:

=================== C Routine ==================
#include <stdio.h>
#include <string.h>

char * MyMethod(char *data)
{
strcpy(data,"My text from C Code ");
return data;
}
steps to get libFile.a:
cc -c libFile.o libFile.c
ar rcs libFile.a libFile.o

=========================== PerlScript ==============
package Caller;
use Inline C => Config =>
ENABLE => AUTOWRAP,
LIBS => '-L/lib_location -lFile',
INC => '-I/lib_location'
;
use Inline C => <<'END';
char * MyMethod(char *data);
AV* AVstr;
SV* SVstr1;
void DisplayData()
{
AVstr=newAV();
// Call to function defined in library
AVstr = MyMethod(AVstr);
printf("\n SVstr1 data: %s\n",AVstr);
}
END
1;

use strict;
# call to Function
Caller::DisplayData();
1;
Compile: perl -c Script_name
run : perl -w Script_name

Do you have any guess why am I getting Segmentation fault? Is this the right
way to pass parameters and
particularly memory allocation and deallocation?

Thanks in advance.

~~~~~~~~~~~~~~~~~~~~

Thanks and Best regards,

~ Rajnikant

Software Engg.

Persistent Sys. Ltd.

Ph. +91 98222 04088



DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.


Relevant Pages

  • Re: appending to file appends twice!?
    ... > I wrote a Perl script to append Questions and Answers to a text data file. ... > increment as if my routine is called twice. ... so chances are it is being called twice somehow. ...
    (comp.lang.perl.misc)
  • illegal octal digit 8?
    ... In my perl script I use the unix command 'date' to make a time stamp ... My routine then changes the two digit number into the ... Illegal octal digit '8' ...
    (perl.beginners)
  • Problem with HTML::LinkExtor
    ... I've written a perl script which extracts links from websites. ... after finishing and restarting the script the routine ...
    (comp.lang.perl.misc)
  • Re: Process PID
    ... Nevermind, I found $$ ... > I'm looking for a way to get the process ID of the Perl script I'm ... > Is there a getpid() routine in Perl? ...
    (comp.lang.perl)
  • Problem using C module in perl
    ... I am tying use C module in the Perl script using inlineC. ... I want to get the data stored in the SV* to char* ...
    (comp.lang.perl.modules)