This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
First stab T_REFREF docs
[perl5.git] / ext / XS-Typemap / Typemap.xs
CommitLineData
ea035a69
JH
1/*
2 XS code to test the typemap entries
3
4 Copyright (C) 2001 Tim Jenness.
5 All Rights Reserved
6
7*/
8
3c53ff3f
NC
9#define PERL_NO_GET_CONTEXT
10
ea035a69
JH
11#include "EXTERN.h" /* std perl include */
12#include "perl.h" /* std perl include */
13#include "XSUB.h" /* XSUB include */
14
15/* Prototypes for external functions */
16FILE * xsfopen( const char * );
17int xsfclose( FILE * );
18int xsfprintf( FILE *, const char *);
19
20/* Type definitions required for the XS typemaps */
21typedef SV * SVREF; /* T_SVREF */
22typedef int SysRet; /* T_SYSRET */
23typedef int Int; /* T_INT */
24typedef int intRef; /* T_PTRREF */
25typedef int intObj; /* T_PTROBJ */
26typedef int intRefIv; /* T_REF_IV_PTR */
27typedef int intArray; /* T_ARRAY */
604db645
SM
28typedef int intTINT; /* T_INT */
29typedef int intTLONG; /* T_LONG */
ea035a69
JH
30typedef short shortOPQ; /* T_OPAQUE */
31typedef int intOpq; /* T_OPAQUEPTR */
604db645 32typedef unsigned intUnsigned; /* T_U_INT */
ea035a69 33
5abff6f9
TJ
34/* A structure to test T_OPAQUEPTR */
35struct t_opaqueptr {
36 int a;
37 int b;
38 double c;
39};
40
41typedef struct t_opaqueptr astruct;
42
ea035a69 43/* Some static memory for the tests */
052980ee
TJ
44static I32 xst_anint;
45static intRef xst_anintref;
46static intObj xst_anintobj;
47static intRefIv xst_anintrefiv;
48static intOpq xst_anintopq;
ea035a69 49
b64f48ff 50/* A different type to refer to for testing the different
1d2615b4 51 * AV*, HV*, etc typemaps */
b64f48ff
SM
52typedef AV AV_FIXED;
53typedef HV HV_FIXED;
1d2615b4
SM
54typedef CV CV_FIXED;
55typedef SVREF SVREF_FIXED;
b64f48ff 56
ea035a69
JH
57/* Helper functions */
58
59/* T_ARRAY - allocate some memory */
60intArray * intArrayPtr( int nelem ) {
61 intArray * array;
a02a5408 62 Newx(array, nelem, intArray);
ea035a69
JH
63 return array;
64}
65
66
67MODULE = XS::Typemap PACKAGE = XS::Typemap
68
69PROTOTYPES: DISABLE
70
71=head1 TYPEMAPS
72
73Each C type is represented by an entry in the typemap file that
ac23f157
SM
74is responsible for converting perl variables (SV, AV, HV, CV, etc.)
75to and from that type.
ea035a69
JH
76
77=over 4
78
79=item T_SV
80
81This simply passes the C representation of the Perl variable (an SV*)
82in and out of the XS layer. This can be used if the C code wants
83to deal directly with the Perl variable.
84
85=cut
86
87SV *
88T_SV( sv )
89 SV * sv
90 CODE:
91 /* create a new sv for return that is a copy of the input
92 do not simply copy the pointer since the SV will be marked
93 mortal by the INPUT typemap when it is pushed back onto the stack */
94 RETVAL = sv_mortalcopy( sv );
95 /* increment the refcount since the default INPUT typemap mortalizes
96 by default and we don't want to decrement the ref count twice
97 by mistake */
98 SvREFCNT_inc(RETVAL);
99 OUTPUT:
100 RETVAL
101
102=item T_SVREF
103
104Used to pass in and return a reference to an SV.
105
1d2615b4
SM
106Note that this typemap does not decrement the reference count
107when returning the reference to an SV*.
108See also: T_SVREF_REFCOUNT_FIXED
109
ea035a69
JH
110=cut
111
112SVREF
113T_SVREF( svref )
114 SVREF svref
115 CODE:
116 RETVAL = svref;
117 OUTPUT:
118 RETVAL
119
1d2615b4
SM
120=item T_SVREF_FIXED
121
122Used to pass in and return a reference to an SV.
123This is a fixed
124variant of T_SVREF that decrements the refcount appropriately
125when returning a reference to an SV*. Introduced in perl 5.15.4.
126
127=cut
128
129SVREF_FIXED
130T_SVREF_REFCOUNT_FIXED( svref )
131 SVREF_FIXED svref
132 CODE:
133 SvREFCNT_inc(svref);
134 RETVAL = svref;
135 OUTPUT:
136 RETVAL
137
ea035a69
JH
138=item T_AVREF
139
140From the perl level this is a reference to a perl array.
141From the C level this is a pointer to an AV.
142
b64f48ff
SM
143Note that this typemap does not decrement the reference count
144when returning an AV*. See also: T_AVREF_REFCOUNT_FIXED
145
ea035a69
JH
146=cut
147
148AV *
149T_AVREF( av )
150 AV * av
151 CODE:
152 RETVAL = av;
153 OUTPUT:
154 RETVAL
155
b64f48ff
SM
156=item T_AVREF_REFCOUNT_FIXED
157
158From the perl level this is a reference to a perl array.
159From the C level this is a pointer to an AV. This is a fixed
160variant of T_AVREF that decrements the refcount appropriately
161when returning an AV*. Introduced in perl 5.15.4.
162
163=cut
164
165AV_FIXED*
166T_AVREF_REFCOUNT_FIXED( av )
167 AV_FIXED * av
168 CODE:
169 SvREFCNT_inc(av);
170 RETVAL = av;
171 OUTPUT:
172 RETVAL
173
ea035a69
JH
174=item T_HVREF
175
176From the perl level this is a reference to a perl hash.
d1be9408 177From the C level this is a pointer to an HV.
ea035a69 178
b64f48ff
SM
179Note that this typemap does not decrement the reference count
180when returning an HV*. See also: T_HVREF_REFCOUNT_FIXED
181
ea035a69
JH
182=cut
183
184HV *
185T_HVREF( hv )
186 HV * hv
187 CODE:
188 RETVAL = hv;
189 OUTPUT:
190 RETVAL
191
b64f48ff
SM
192=item T_HVREF_REFCOUNT_FIXED
193
194From the perl level this is a reference to a perl hash.
195From the C level this is a pointer to an HV. This is a fixed
196variant of T_HVREF that decrements the refcount appropriately
197when returning an HV*. Introduced in perl 5.15.4.
198
199=cut
200
201HV_FIXED*
202T_HVREF_REFCOUNT_FIXED( hv )
203 HV_FIXED * hv
204 CODE:
205 SvREFCNT_inc(hv);
206 RETVAL = hv;
207 OUTPUT:
208 RETVAL
209
210
ea035a69
JH
211=item T_CVREF
212
213From the perl level this is a reference to a perl subroutine
214(e.g. $sub = sub { 1 };). From the C level this is a pointer
215to a CV.
216
1d2615b4
SM
217Note that this typemap does not decrement the reference count
218when returning an HV*. See also: T_HVREF_REFCOUNT_FIXED
219
ea035a69
JH
220=cut
221
222CV *
223T_CVREF( cv )
224 CV * cv
225 CODE:
226 RETVAL = cv;
227 OUTPUT:
228 RETVAL
229
1d2615b4
SM
230=item T_CVREF_REFCOUNT_FIXED
231
232From the perl level this is a reference to a perl subroutine
233(e.g. $sub = sub { 1 };). From the C level this is a pointer
234to a CV.
235
236This is a fixed
237variant of T_HVREF that decrements the refcount appropriately
238when returning an HV*. Introduced in perl 5.15.4.
239
240=cut
241
242CV_FIXED *
243T_CVREF_REFCOUNT_FIXED( cv )
244 CV_FIXED * cv
245 CODE:
246 SvREFCNT_inc(cv);
247 RETVAL = cv;
248 OUTPUT:
249 RETVAL
ea035a69
JH
250
251=item T_SYSRET
252
253The T_SYSRET typemap is used to process return values from system calls.
254It is only meaningful when passing values from C to perl (there is
255no concept of passing a system return value from Perl to C).
256
257System calls return -1 on error (setting ERRNO with the reason)
258and (usually) 0 on success. If the return value is -1 this typemap
259returns C<undef>. If the return value is not -1, this typemap
260translates a 0 (perl false) to "0 but true" (which
261is perl true) or returns the value itself, to indicate that the
262command succeeded.
263
264The L<POSIX|POSIX> module makes extensive use of this type.
265
266=cut
267
268# Test a successful return
269
270SysRet
271T_SYSRET_pass()
272 CODE:
273 RETVAL = 0;
274 OUTPUT:
275 RETVAL
276
277# Test failure
278
279SysRet
280T_SYSRET_fail()
281 CODE:
282 RETVAL = -1;
283 OUTPUT:
284 RETVAL
285
286=item T_UV
287
288An unsigned integer.
289
290=cut
291
292unsigned int
293T_UV( uv )
294 unsigned int uv
295 CODE:
296 RETVAL = uv;
297 OUTPUT:
298 RETVAL
299
300=item T_IV
301
ac23f157 302A signed integer. This is cast to the required integer type when
d1be9408 303passed to C and converted to an IV when passed back to Perl.
ea035a69
JH
304
305=cut
306
307long
308T_IV( iv )
309 long iv
310 CODE:
311 RETVAL = iv;
312 OUTPUT:
313 RETVAL
314
315=item T_INT
316
317A signed integer. This typemap converts the Perl value to a native
318integer type (the C<int> type on the current platform). When returning
319the value to perl it is processed in the same way as for T_IV.
320
321Its behaviour is identical to using an C<int> type in XS with T_IV.
322
604db645
SM
323=cut
324
325intTINT
326T_INT( i )
327 intTINT i
328 CODE:
329 RETVAL = i;
330 OUTPUT:
331 RETVAL
332
ea035a69
JH
333=item T_ENUM
334
335An enum value. Used to transfer an enum component
336from C. There is no reason to pass an enum value to C since
337it is stored as an IV inside perl.
338
339=cut
340
341# The test should return the value for SVt_PVHV.
342# 11 at the present time but we can't not rely on this
343# for testing purposes.
344
345svtype
346T_ENUM()
347 CODE:
348 RETVAL = SVt_PVHV;
349 OUTPUT:
350 RETVAL
351
352=item T_BOOL
353
354A boolean type. This can be used to pass true and false values to and
355from C.
356
357=cut
358
359bool
360T_BOOL( in )
361 bool in
362 CODE:
363 RETVAL = in;
364 OUTPUT:
365 RETVAL
366
367=item T_U_INT
368
369This is for unsigned integers. It is equivalent to using T_UV
370but explicitly casts the variable to type C<unsigned int>.
371The default type for C<unsigned int> is T_UV.
372
604db645
SM
373=cut
374
375intUnsigned
376T_U_INT( uint )
377 intUnsigned uint
378 CODE:
379 RETVAL = uint;
380 OUTPUT:
381 RETVAL
382
ea035a69
JH
383=item T_SHORT
384
385Short integers. This is equivalent to T_IV but explicitly casts
386the return to type C<short>. The default typemap for C<short>
387is T_IV.
388
604db645
SM
389=cut
390
391short
392T_SHORT( s )
393 short s
394 CODE:
395 RETVAL = s;
396 OUTPUT:
397 RETVAL
398
ea035a69
JH
399=item T_U_SHORT
400
401Unsigned short integers. This is equivalent to T_UV but explicitly
402casts the return to type C<unsigned short>. The default typemap for
403C<unsigned short> is T_UV.
404
405T_U_SHORT is used for type C<U16> in the standard typemap.
406
407=cut
408
409U16
410T_U_SHORT( in )
411 U16 in
412 CODE:
413 RETVAL = in;
414 OUTPUT:
415 RETVAL
416
417
418=item T_LONG
419
420Long integers. This is equivalent to T_IV but explicitly casts
421the return to type C<long>. The default typemap for C<long>
422is T_IV.
423
604db645
SM
424=cut
425
426intTLONG
427T_LONG( in )
428 intTLONG in
429 CODE:
430 RETVAL = in;
431 OUTPUT:
432 RETVAL
433
ea035a69
JH
434=item T_U_LONG
435
436Unsigned long integers. This is equivalent to T_UV but explicitly
437casts the return to type C<unsigned long>. The default typemap for
438C<unsigned long> is T_UV.
439
440T_U_LONG is used for type C<U32> in the standard typemap.
441
442=cut
443
444U32
445T_U_LONG( in )
446 U32 in
447 CODE:
448 RETVAL = in;
449 OUTPUT:
450 RETVAL
451
452=item T_CHAR
453
454Single 8-bit characters.
455
456=cut
457
458char
459T_CHAR( in );
460 char in
461 CODE:
462 RETVAL = in;
463 OUTPUT:
464 RETVAL
465
466
467=item T_U_CHAR
468
469An unsigned byte.
470
471=cut
472
473unsigned char
474T_U_CHAR( in );
475 unsigned char in
476 CODE:
477 RETVAL = in;
478 OUTPUT:
479 RETVAL
480
481
482=item T_FLOAT
483
484A floating point number. This typemap guarantees to return a variable
485cast to a C<float>.
486
487=cut
488
489float
490T_FLOAT( in )
491 float in
492 CODE:
493 RETVAL = in;
494 OUTPUT:
495 RETVAL
496
497=item T_NV
498
499A Perl floating point number. Similar to T_IV and T_UV in that the
500return type is cast to the requested numeric type rather than
501to a specific type.
502
503=cut
504
505NV
506T_NV( in )
507 NV in
508 CODE:
509 RETVAL = in;
510 OUTPUT:
511 RETVAL
512
513=item T_DOUBLE
514
515A double precision floating point number. This typemap guarantees to
516return a variable cast to a C<double>.
517
518=cut
519
520double
521T_DOUBLE( in )
522 double in
523 CODE:
524 RETVAL = in;
525 OUTPUT:
526 RETVAL
527
528=item T_PV
529
530A string (char *).
531
532=cut
533
534char *
535T_PV( in )
536 char * in
537 CODE:
538 RETVAL = in;
539 OUTPUT:
540 RETVAL
541
542=item T_PTR
543
544A memory address (pointer). Typically associated with a C<void *>
545type.
546
547=cut
548
549# Pass in a value. Store the value in some static memory and
550# then return the pointer
551
552void *
553T_PTR_OUT( in )
554 int in;
555 CODE:
052980ee
TJ
556 xst_anint = in;
557 RETVAL = &xst_anint;
ea035a69
JH
558 OUTPUT:
559 RETVAL
560
561# pass in the pointer and return the value
562
563int
564T_PTR_IN( ptr )
565 void * ptr
566 CODE:
567 RETVAL = *(int *)ptr;
568 OUTPUT:
569 RETVAL
570
571=item T_PTRREF
572
573Similar to T_PTR except that the pointer is stored in a scalar and the
574reference to that scalar is returned to the caller. This can be used
575to hide the actual pointer value from the programmer since it is usually
576not required directly from within perl.
577
578The typemap checks that a scalar reference is passed from perl to XS.
579
580=cut
581
582# Similar test to T_PTR
583# Pass in a value. Store the value in some static memory and
584# then return the pointer
585
586intRef *
587T_PTRREF_OUT( in )
588 intRef in;
589 CODE:
052980ee
TJ
590 xst_anintref = in;
591 RETVAL = &xst_anintref;
ea035a69
JH
592 OUTPUT:
593 RETVAL
594
595# pass in the pointer and return the value
596
597intRef
598T_PTRREF_IN( ptr )
599 intRef * ptr
600 CODE:
601 RETVAL = *ptr;
602 OUTPUT:
603 RETVAL
604
605
606
607=item T_PTROBJ
608
609Similar to T_PTRREF except that the reference is blessed into a class.
610This allows the pointer to be used as an object. Most commonly used to
611deal with C structs. The typemap checks that the perl object passed
612into the XS routine is of the correct class (or part of a subclass).
613
614The pointer is blessed into a class that is derived from the name
615of type of the pointer but with all '*' in the name replaced with
616'Ptr'.
617
618=cut
619
620# Similar test to T_PTRREF
621# Pass in a value. Store the value in some static memory and
622# then return the pointer
623
624intObj *
625T_PTROBJ_OUT( in )
626 intObj in;
627 CODE:
052980ee
TJ
628 xst_anintobj = in;
629 RETVAL = &xst_anintobj;
ea035a69
JH
630 OUTPUT:
631 RETVAL
632
633# pass in the pointer and return the value
634
635MODULE = XS::Typemap PACKAGE = intObjPtr
636
637intObj
638T_PTROBJ_IN( ptr )
639 intObj * ptr
640 CODE:
641 RETVAL = *ptr;
642 OUTPUT:
643 RETVAL
644
645MODULE = XS::Typemap PACKAGE = XS::Typemap
646
647=item T_REF_IV_REF
648
649NOT YET
650
651=item T_REF_IV_PTR
652
653Similar to T_PTROBJ in that the pointer is blessed into a scalar object.
654The difference is that when the object is passed back into XS it must be
655of the correct type (inheritance is not supported).
656
657The pointer is blessed into a class that is derived from the name
658of type of the pointer but with all '*' in the name replaced with
659'Ptr'.
660
661=cut
662
663# Similar test to T_PTROBJ
664# Pass in a value. Store the value in some static memory and
665# then return the pointer
666
667intRefIv *
668T_REF_IV_PTR_OUT( in )
669 intRefIv in;
670 CODE:
052980ee
TJ
671 xst_anintrefiv = in;
672 RETVAL = &xst_anintrefiv;
ea035a69
JH
673 OUTPUT:
674 RETVAL
675
676# pass in the pointer and return the value
677
678MODULE = XS::Typemap PACKAGE = intRefIvPtr
679
680intRefIv
681T_REF_IV_PTR_IN( ptr )
682 intRefIv * ptr
683 CODE:
684 RETVAL = *ptr;
685 OUTPUT:
686 RETVAL
687
688
689MODULE = XS::Typemap PACKAGE = XS::Typemap
690
691=item T_PTRDESC
692
693NOT YET
694
695=item T_REFREF
696
d3ba6280
SM
697Similar to T_PTRREF, except the pointer stored in the referenced scalar
698is dereferenced and copied to the output variable. This means that
699T_REFREF is to T_PTRREF as T_OPAQUE is to T_OPAQUEPTR. All clear?
700
701Only the INPUT part of this is implemented (Perl to XSUB) and there
702are no known users in core or on CPAN.
703
704=cut
ea035a69
JH
705
706=item T_REFOBJ
707
708NOT YET
709
710=item T_OPAQUEPTR
711
5abff6f9
TJ
712This can be used to store bytes in the string component of the
713SV. Here the representation of the data is irrelevant to perl and the
714bytes themselves are just stored in the SV. It is assumed that the C
715variable is a pointer (the bytes are copied from that memory
716location). If the pointer is pointing to something that is
717represented by 8 bytes then those 8 bytes are stored in the SV (and
718length() will report a value of 8). This entry is similar to T_OPAQUE.
ea035a69 719
5abff6f9
TJ
720In principal the unpack() command can be used to convert the bytes
721back to a number (if the underlying type is known to be a number).
722
723This entry can be used to store a C structure (the number
724of bytes to be copied is calculated using the C C<sizeof> function)
725and can be used as an alternative to T_PTRREF without having to worry
726about a memory leak (since Perl will clean up the SV).
ea035a69
JH
727
728=cut
729
730intOpq *
731T_OPAQUEPTR_IN( val )
732 intOpq val
733 CODE:
052980ee
TJ
734 xst_anintopq = val;
735 RETVAL = &xst_anintopq;
ea035a69
JH
736 OUTPUT:
737 RETVAL
738
739intOpq
740T_OPAQUEPTR_OUT( ptr )
741 intOpq * ptr
742 CODE:
743 RETVAL = *ptr;
744 OUTPUT:
745 RETVAL
746
aa921f48
TJ
747short
748T_OPAQUEPTR_OUT_short( ptr )
749 shortOPQ * ptr
750 CODE:
751 RETVAL = *ptr;
752 OUTPUT:
753 RETVAL
754
5abff6f9
TJ
755# Test it with a structure
756astruct *
757T_OPAQUEPTR_IN_struct( a,b,c )
758 int a
759 int b
760 double c
761 PREINIT:
762 struct t_opaqueptr test;
763 CODE:
764 test.a = a;
765 test.b = b;
766 test.c = c;
767 RETVAL = &test;
768 OUTPUT:
769 RETVAL
770
771void
772T_OPAQUEPTR_OUT_struct( test )
773 astruct * test
774 PPCODE:
775 XPUSHs(sv_2mortal(newSViv(test->a)));
776 XPUSHs(sv_2mortal(newSViv(test->b)));
777 XPUSHs(sv_2mortal(newSVnv(test->c)));
778
779
ea035a69
JH
780=item T_OPAQUE
781
5abff6f9
TJ
782This can be used to store data from non-pointer types in the string
783part of an SV. It is similar to T_OPAQUEPTR except that the
784typemap retrieves the pointer directly rather than assuming it
ac23f157 785is being supplied. For example, if an integer is imported into
052980ee
TJ
786Perl using T_OPAQUE rather than T_IV the underlying bytes representing
787the integer will be stored in the SV but the actual integer value will not
788be available. i.e. The data is opaque to perl.
ea035a69 789
5abff6f9
TJ
790The data may be retrieved using the C<unpack> function if the
791underlying type of the byte stream is known.
792
793T_OPAQUE supports input and output of simple types.
794T_OPAQUEPTR can be used to pass these bytes back into C if a pointer
795is acceptable.
ea035a69
JH
796
797=cut
798
799shortOPQ
800T_OPAQUE_IN( val )
801 int val
802 CODE:
803 RETVAL = (shortOPQ)val;
804 OUTPUT:
805 RETVAL
806
5abff6f9
TJ
807IV
808T_OPAQUE_OUT( val )
809 shortOPQ val
810 CODE:
811 RETVAL = (IV)val;
812 OUTPUT:
813 RETVAL
814
ea035a69
JH
815=item Implicit array
816
817xsubpp supports a special syntax for returning
818packed C arrays to perl. If the XS return type is given as
819
820 array(type, nelem)
821
822xsubpp will copy the contents of C<nelem * sizeof(type)> bytes from
823RETVAL to an SV and push it onto the stack. This is only really useful
824if the number of items to be returned is known at compile time and you
825don't mind having a string of bytes in your SV. Use T_ARRAY to push a
826variable number of arguments onto the return stack (they won't be
827packed as a single string though).
828
829This is similar to using T_OPAQUEPTR but can be used to process more than
830one element.
831
832=cut
833
834array(int,3)
835T_OPAQUE_array( a,b,c)
836 int a
837 int b
838 int c
839 PREINIT:
3d5d53b8 840 int array[3];
ea035a69
JH
841 CODE:
842 array[0] = a;
843 array[1] = b;
844 array[2] = c;
845 RETVAL = array;
846 OUTPUT:
847 RETVAL
848
849
850=item T_PACKED
851
852NOT YET
853
854=item T_PACKEDARRAY
855
856NOT YET
857
858=item T_DATAUNIT
859
860NOT YET
861
862=item T_CALLBACK
863
864NOT YET
865
866=item T_ARRAY
867
868This is used to convert the perl argument list to a C array
869and for pushing the contents of a C array onto the perl
870argument stack.
871
872The usual calling signature is
873
874 @out = array_func( @in );
875
876Any number of arguments can occur in the list before the array but
877the input and output arrays must be the last elements in the list.
878
879When used to pass a perl list to C the XS writer must provide a
880function (named after the array type but with 'Ptr' substituted for
881'*') to allocate the memory required to hold the list. A pointer
882should be returned. It is up to the XS writer to free the memory on
883exit from the function. The variable C<ix_$var> is set to the number
884of elements in the new array.
885
886When returning a C array to Perl the XS writer must provide an integer
887variable called C<size_$var> containing the number of elements in the
888array. This is used to determine how many elements should be pushed
889onto the return argument stack. This is not required on input since
890Perl knows how many arguments are on the stack when the routine is
891called. Ordinarily this variable would be called C<size_RETVAL>.
892
893Additionally, the type of each element is determined from the type of
894the array. If the array uses type C<intArray *> xsubpp will
895automatically work out that it contains variables of type C<int> and
896use that typemap entry to perform the copy of each element. All
897pointer '*' and 'Array' tags are removed from the name to determine
898the subtype.
899
900=cut
901
902# Test passes in an integer array and returns it along with
903# the number of elements
904# Pass in a dummy value to test offsetting
905
906# Problem is that xsubpp does XSRETURN(1) because we arent
907# using PPCODE. This means that only the first element
908# is returned. KLUGE this by using CLEANUP to return before the
909# end.
ac23f157
SM
910# Note: I read this as: The "T_ARRAY" typemap is really rather broken,
911# at least for OUTPUT. That is apart from the general design
912# weaknesses. --Steffen
ea035a69
JH
913
914intArray *
915T_ARRAY( dummy, array, ... )
4d0439ce 916 int dummy = 0;
ea035a69
JH
917 intArray * array
918 PREINIT:
919 U32 size_RETVAL;
920 CODE:
8876ff82 921 dummy += 0; /* Fix -Wall */
ea035a69
JH
922 size_RETVAL = ix_array;
923 RETVAL = array;
924 OUTPUT:
925 RETVAL
926 CLEANUP:
927 Safefree(array);
928 XSRETURN(size_RETVAL);
929
930
931=item T_STDIO
932
933This is used for passing perl filehandles to and from C using
934C<FILE *> structures.
935
936=cut
937
938FILE *
939T_STDIO_open( file )
940 const char * file
941 CODE:
942 RETVAL = xsfopen( file );
943 OUTPUT:
944 RETVAL
945
946SysRet
c72de6e4
TJ
947T_STDIO_close( f )
948 PerlIO * f
949 PREINIT:
950 FILE * stream;
ea035a69 951 CODE:
c72de6e4
TJ
952 /* Get the FILE* */
953 stream = PerlIO_findFILE( f );
c72de6e4
TJ
954 /* Release the FILE* from the PerlIO system so that we do
955 not close the file twice */
956 PerlIO_releaseFILE(f,stream);
6b54a403
NC
957 /* Must release the file before closing it */
958 RETVAL = xsfclose( stream );
ea035a69
JH
959 OUTPUT:
960 RETVAL
961
962int
963T_STDIO_print( stream, string )
964 FILE * stream
965 const char * string
966 CODE:
967 RETVAL = xsfprintf( stream, string );
968 OUTPUT:
969 RETVAL
970
971
972=item T_IN
973
974NOT YET
975
976=item T_INOUT
977
978This is used for passing perl filehandles to and from C using
979C<PerlIO *> structures. The file handle can used for reading and
980writing.
981
982See L<perliol> for more information on the Perl IO abstraction
983layer. Perl must have been built with C<-Duseperlio>.
984
985=item T_OUT
986
987NOT YET
988
989=back
990
991=cut
992