File: CallExt.xs

package info (click to toggle)
pdl 1%3A2.007-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,848 kB
  • ctags: 6,321
  • sloc: perl: 32,760; fortran: 13,113; ansic: 9,273; makefile: 81; sh: 32
file content (65 lines) | stat: -rw-r--r-- 1,849 bytes parent folder | download | duplicates (8)
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
59
60
61
62
63
64
65
/*
 * We used to say "THIS FILE WAS GENERATED BY PDL::PP! Do not modify!"
 * but it has been hand-modified since then.
 */
#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 */

/*
 * Call an external C routine loaded dynamically - pass PDL args list
 *
 * Not sure whether should be 'ENABLE' or 'DISABLE' for the PROTOTYPES
 * argument below. We only seem to need the line to stop perl from
 * complaining about the line being missing during build time anyway.
 */

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

PROTOTYPES: DISABLE

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

        symref = (int(*)(int, pdlsimple**)) INT2PTR(void*,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 = INT2PTR(Core*,SvIV( CoreSV ));  /* Core* value */