| Subject: | Allocating a char* and returning to Perl from a C function |
|---|---|
| From: | pfca@xxxxxxxxxxxxxxx (Paulo Filipe Andrade) |
| Date: | Wed, 30 Jul 2008 17:59:44 +0100 |
| Newsgroups: | perl.inline |
Hello,
I have a C function that I need to call from Perl.
It goes a little something like this:
char *work(char *inString){
char *stringToReturn = (char *)malloc(2*sizeof(inString));
while(*inString){
// do some work on stringToReturn
inString++;
}
return stringToReturn;
}
The thing is, since I can't free stringToReturn, I need to have it
garbage collected in the perl side.
I have tried creating an SV * with the newSVpv* methods, passing in
the stringToReturn and then freeing it, but I am always getting
segmentation faults.
This should be pretty simple, but I just can't get it to work. Thank you for your time. Paulo F. Andrade pauloandrade@xxxxxxxxxx |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Inline Java Integer question, Jason Stelzer |
|---|---|
| Next by Date: | Re: Allocating a char* and returning to Perl from a C function, Sisyphus |
| Previous by Thread: | Inline Java and the Business Objects SDK, Mike Vanole |
| Next by Thread: | Re: Allocating a char* and returning to Perl from a C function, Sisyphus |
| Indexes: | [Date] [Thread] [Top] [All Lists] |