summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/dist/ExtUtils-ParseXS/t/XSMore.xs
blob: b48cfa2f021a7ee5c3b20c4c9ae9806aa6f6472e (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

typedef IV MyType;
typedef IV MyType2;
typedef IV MyType3;
typedef IV MyType4;
typedef IV MyType5;
typedef IV MyType6;


=for testing

This parts are ignored.

=cut

/* Old perls (pre 5.8.9 or so) did not have PERL_UNUSED_ARG in XSUB.h.
 * This is normally covered by ppport.h. */
#ifndef PERL_UNUSED_ARG
#  if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */
#    include <note.h>
#    define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x))
#  else
#    define PERL_UNUSED_ARG(x) ((void)x)
#  endif
#endif
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(x) ((void)x)
#endif

/* Newx was introduced in 5.8.8, would also be in ppport.h */
#ifndef Newx
#  define Newx(v,n,t)                    New(0,v,n,t)
#endif


STATIC void
outlist(int* a, int* b){
	*a = 'a';
	*b = 'b';
}

STATIC bool
outlist_bool(const char *a, const char *b, char **c)
{
   dTHX;
   STRLEN lena = strlen(a);
   STRLEN lenb = strlen(b);
   STRLEN lenc = lena + lenb;
   Newx(*c, lenc+1, char);
   strcpy(*c, a);
   strcat(*c, b);
   SAVEFREEPV(*c);

   return TRUE;
}

STATIC int
outlist_int(const char *a, const char *b, char **c)
{
   dTHX;
   STRLEN lena = strlen(a);
   STRLEN lenb = strlen(b);
   STRLEN lenc = lena + lenb;
   Newx(*c, lenc+1, char);
   strcpy(*c, a);
   strcat(*c, b);
   SAVEFREEPV(*c);

   return 11;
}

STATIC int
len(const char* const s, int const l){
	PERL_UNUSED_ARG(s);
	return l;
}

MODULE = XSMore         PACKAGE = XSMore

=for testing

This parts are also ignored.

=cut

PROTOTYPES: ENABLE

VERSIONCHECK: DISABLE

REQUIRE: 2.20

SCOPE: DISABLE

FALLBACK: TRUE

BOOT:
	sv_setiv(get_sv("XSMore::boot_ok", TRUE), 100);


TYPEMAP: <<END
MyType	T_IV
END

TYPEMAP: <<"  FOO BAR BAZ";
MyType2	T_FOOOO

OUTPUT
T_FOOOO
	sv_setiv($arg, (IV)$var);
  FOO BAR BAZ

TYPEMAP: <<'END'
MyType3	T_BAAR
MyType4	T_BAAR

OUTPUT
T_BAAR
	sv_setiv($arg, (IV)$var);

INPUT
T_BAAR
	$var = ($type)SvIV($arg)
END

TYPEMAP: <<END
MyType5 T_WITHSEMICOLON

INPUT

T_WITHSEMICOLON
    $var = ($type)SvIV($arg); 
END

TYPEMAP: <<SEMICOLONHERE;
MyType6	T_IV
SEMICOLONHERE

MyType
typemaptest1()
  CODE:
    RETVAL = 42;
  OUTPUT:
    RETVAL

MyType2
typemaptest2()
  CODE:
    RETVAL = 42;
  OUTPUT:
    RETVAL

MyType3
typemaptest3(foo, bar, baz)
    MyType4 foo
    MyType5 bar
    MyType5 baz
  CODE:
    PERL_UNUSED_VAR(bar);
    PERL_UNUSED_VAR(baz);
    RETVAL = foo;
  OUTPUT:
    RETVAL

MyType6
typemaptest6(foo)
    MyType6 foo
  CODE:
    RETVAL = foo;
  OUTPUT:
    RETVAL

void
prototype_ssa()
PROTOTYPE: $$@
CODE:
	NOOP;

void
attr_method(self, ...)
ATTRS: method
CODE:
	NOOP;

#define RET_1 1
#define RET_2 2

int
return_1()
CASE: ix == 1
	ALIAS:
		return_1 = RET_1
		return_2 = RET_2
	CODE:
		RETVAL = ix;
	OUTPUT:
		RETVAL
CASE: ix == 2
	CODE:
		RETVAL = ix;
	OUTPUT:
		RETVAL

int
arg_init(x)
	int x = SvIV($arg);
CODE:
	RETVAL = x;
OUTPUT:
	RETVAL

int
myabs(...)
OVERLOAD: abs
CODE:
	PERL_UNUSED_VAR(items);
	RETVAL = 42;
OUTPUT:
	RETVAL

void
hook(IN AV* av)
INIT:
	av_push(av, newSVpv("INIT", 0));
CODE:
	av_push(av, newSVpv("CODE", 0));
POSTCALL:
	av_push(av, newSVpv("POSTCALL", 0));
CLEANUP:
	av_push(av, newSVpv("CLEANUP", 0));


void
outlist(OUTLIST int a, OUTLIST int b)

bool
outlist_bool(const char *a, const char *b, OUTLIST char *c)

int
outlist_int(const char *a, const char *b, OUTLIST char *c)

int
len(char* s, int length(s))

INCLUDE_COMMAND: $^X -Ilib -It/lib -MIncludeTester -e IncludeTester::print_xs

#if 1

INCLUDE: XSInclude.xsh

#else

# for testing #else directive

#endif

MODULE=XSMore PACKAGE=XSMore::More

void
dummy()
PROTOTYPE: $$$$$
CODE:
  NOOP;

void
should_not_have_prototype()
OVERLOAD: +
CODE:
  NOOP;