File: CallExt.xs

package info (click to toggle)
pdl 2.005-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,200 kB
  • ctags: 3,301
  • sloc: perl: 14,876; ansic: 7,223; fortran: 3,417; makefile: 54; sh: 16
file content (58 lines) | stat: -rw-r--r-- 1,535 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

/*
 * THIS FILE WAS GENERATED BY PDL::PP! Do not modify!
 */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "pdl.h"
#include "pdlcore.h"
#include "pdlsimple.h"

static Core* PDL; /* Structure hold core C functions */
SV* CoreSV;       /* Get's pointer to perl var holding core structure */


MODULE = PDL::CallExt PACKAGE = PDL::CallExt

# Call an external C routine loaded dynamically - pass PDL args list

void
_callext_int(...)
     PPCODE:
        int (*symref)(int npdl, pdlsimple **x);
        int npdl = items-1;
        pdlsimple **x;
	pdl *t;
        int i;

        symref = (int(*)(int, pdlsimple**)) SvIV(ST(0));

        New( 42, x, npdl, pdlsimple* ); /* Ptr array */
        for(i=0; i<npdl; i++) {
           t = PDL->SvPDLV(ST(i+1));
	   PDL->make_physical(t); 
	   PDL->make_physdims(t); 
	   New(42, x[i], 1, pdlsimple); /* Each ptr */
	   x[i]->datatype = t->datatype;
	   x[i]->data     = t->data;
	   x[i]->nvals    = t->nvals;
	   x[i]->dims     = t->dims;
	   x[i]->ndims    = t->ndims;
	}
		   
        i = (*symref)(npdl, x); 
        if (i==0)
           barf("Error calling external routine");
	   
        for(i=0; i<npdl; i++) /* Free stuff */
	   Safefree(x[i]);
	Safefree(x);
	   
BOOT:
   /* Get pointer to structure of core shared C routines */
   CoreSV = perl_get_sv("PDL::SHARE",FALSE);  /* SV* value */
   if (CoreSV==NULL)
     croak("This module requires use of PDL::Core first");
   PDL = (Core*) (void*) SvIV( CoreSV );  /* Core* value */