fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / nci_test.c
blobf50d6b1fd812d71791928685d81bf097b81d4994
1 /*
2 Copyright (C) 2001-2010, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/nci_test.c - shared library used for testing the Native Call Interface
9 =head1 DESCRIPTION
11 From this code a shared library can be compiled and linked with a command like:
13 cc -shared -fpic nci_test.c -o libnci_test.so -g
15 For non-Unix platforms the above command has to be modified appropriately.
17 The resulting shared library should be copied to a location like:
19 parrot/runtime/parrot/dynext/libnci_test.so
21 At that location the shared library is loadable with the opcode 'loadlib'.
22 The functions in the library are available with the opcode 'dlfunc'.
23 The variables in the library are available with the opcode 'dlvar'.
25 =head2 Functions
27 The name of a test function is usually 'nci_<signature>'. E.g. the function
28 'nci_ip' takes a 'pointer' and returns a 'int'.
30 =over 4
32 =cut
36 #define PARROT_IN_EXTENSION
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include "parrot/parrot.h"
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
47 /* Declarations of structs */
49 typedef struct Nested {
50 int y;
51 } Nested;
53 typedef struct Outer {
54 int x;
55 Nested *nested;
56 } Outer;
58 typedef struct Rect_Like {
59 int x, y;
60 int w, h;
61 } Rect_Like;
63 typedef struct Opaque {
64 int x;
65 } Opaque;
67 /* Function declarations.
69 *** If you add a new test function here,
70 *** please update src/libnci_test.def and src/nci/extra_thunks.nci too. ***
74 PARROT_DYNEXT_EXPORT int call_back(const char *str);
75 PARROT_DYNEXT_EXPORT char nci_c(void);
76 PARROT_DYNEXT_EXPORT char nci_csc(short, char);
77 PARROT_DYNEXT_EXPORT double nci_d(void);
78 PARROT_DYNEXT_EXPORT double nci_dd(double);
79 PARROT_DYNEXT_EXPORT float nci_f(void);
80 PARROT_DYNEXT_EXPORT float nci_fff(float, float);
81 PARROT_DYNEXT_EXPORT int nci_i(void);
82 PARROT_DYNEXT_EXPORT int nci_ib(int *);
83 PARROT_DYNEXT_EXPORT int nci_iiii(int, int, int);
84 PARROT_DYNEXT_EXPORT int nci_ii3(int, int *);
85 PARROT_DYNEXT_EXPORT int nci_ip(void *);
86 PARROT_DYNEXT_EXPORT int nci_isc(short, char);
87 PARROT_DYNEXT_EXPORT int nci_it(void *);
88 PARROT_DYNEXT_EXPORT int nci_i33(int *, int *);
89 PARROT_DYNEXT_EXPORT int nci_i4i(long *, int);
90 PARROT_DYNEXT_EXPORT long nci_l(void);
91 PARROT_DYNEXT_EXPORT int * nci_p(void);
92 PARROT_DYNEXT_EXPORT void * nci_pi(int);
93 PARROT_DYNEXT_EXPORT void * nci_pii(int, int);
94 PARROT_DYNEXT_EXPORT void * nci_piiii(int, int, int, int);
95 PARROT_DYNEXT_EXPORT void nci_pip(int, Rect_Like *);
96 PARROT_DYNEXT_EXPORT void * nci_pp(void *);
97 PARROT_DYNEXT_EXPORT short nci_s(void);
98 PARROT_DYNEXT_EXPORT short nci_ssc(short, char);
99 PARROT_DYNEXT_EXPORT char * nci_t(void);
100 PARROT_DYNEXT_EXPORT char * nci_tb(void *);
101 PARROT_DYNEXT_EXPORT char * nci_tB(void **);
102 PARROT_DYNEXT_EXPORT char * nci_tt(char *);
103 PARROT_DYNEXT_EXPORT void nci_v(void);
104 PARROT_DYNEXT_EXPORT void nci_vP(void *);
105 PARROT_DYNEXT_EXPORT void nci_vpii(Outer *, int, int);
106 PARROT_DYNEXT_EXPORT void nci_vv(void);
107 PARROT_DYNEXT_EXPORT void nci_vVi(Opaque**, int);
108 PARROT_DYNEXT_EXPORT void nci_vp(Opaque*);
109 PARROT_DYNEXT_EXPORT char * nci_ttt(char *, char *);
110 PARROT_DYNEXT_EXPORT void nci_vfff(float, float, float);
111 PARROT_DYNEXT_EXPORT void nci_vV(const char **);
112 PARROT_DYNEXT_EXPORT void nci_vVVV(const char **, const char **, const char **);
114 /* Declarations for callback tests */
116 typedef void (*cb_C1_func)(const char*, void*);
117 PARROT_DYNEXT_EXPORT void nci_cb_C1(cb_C1_func, void*);
119 typedef void (*cb_C2_func)(int, void*);
120 PARROT_DYNEXT_EXPORT void nci_cb_C2(cb_C2_func, void*);
122 typedef void (*cb_C3_func)(void*, void*);
123 PARROT_DYNEXT_EXPORT void nci_cb_C3(cb_C3_func, void*);
125 typedef void (*cb_D1_func)(void*, const char*);
126 PARROT_DYNEXT_EXPORT void nci_cb_D1(cb_D1_func, void*);
128 typedef void (*cb_D2_func)(void*, int);
129 PARROT_DYNEXT_EXPORT void nci_cb_D2(cb_D2_func, void*);
131 typedef void (*cb_D3_func)(void*, void*);
132 PARROT_DYNEXT_EXPORT void nci_cb_D3(cb_D3_func, void*);
134 typedef void (*cb_D4_func)(void*, void*);
135 PARROT_DYNEXT_EXPORT void nci_cb_D4(cb_D4_func, void*);
137 /* Variable definitions */
139 PARROT_DYNEXT_EXPORT int int_cb_D4 = -55555;
140 PARROT_DYNEXT_EXPORT int nci_dlvar_char = 22;
141 PARROT_DYNEXT_EXPORT int nci_dlvar_short = 333;
142 PARROT_DYNEXT_EXPORT int nci_dlvar_int = -4444;
143 PARROT_DYNEXT_EXPORT long nci_dlvar_long = -7777777;
144 PARROT_DYNEXT_EXPORT float nci_dlvar_float = -333.0;
145 PARROT_DYNEXT_EXPORT double nci_dlvar_double = -55555.55555;
146 PARROT_DYNEXT_EXPORT char nci_dlvar_cstring[] = "This is a C-string.\n";
149 /* Function definitions */
153 =item C<PARROT_DYNEXT_EXPORT char nci_c(void)>
155 Returns the value of the variable C<nci_dlvar_char>, which is set to 22 by
156 default.
158 =cut
162 PARROT_DYNEXT_EXPORT
163 PARROT_PURE_FUNCTION
164 char
165 nci_c(void)
167 return nci_dlvar_char;
172 =item C<PARROT_DYNEXT_EXPORT char nci_csc(short l1, char l2)>
174 Multiplies C<l1> and C<l2> together and returns the first byte of the result.
176 =cut
180 PARROT_DYNEXT_EXPORT
181 PARROT_CONST_FUNCTION
182 char
183 nci_csc(short l1, char l2)
185 return l1 * l2;
190 =item C<PARROT_DYNEXT_EXPORT double nci_d(void)>
192 Multiplies the current value of C<nci_dlvar_double> by 10.0, and returns
193 the new value.
195 =cut
199 PARROT_DYNEXT_EXPORT
200 double
201 nci_d(void)
203 nci_dlvar_double *= 10.0;
205 return nci_dlvar_double;
210 =item C<PARROT_DYNEXT_EXPORT double nci_dd(double d)>
212 Returns the value C<d> multiplied by 2.0.
214 =cut
218 PARROT_DYNEXT_EXPORT
219 PARROT_CONST_FUNCTION
220 double
221 nci_dd(double d)
223 return d * 2.0;
228 =item C<PARROT_DYNEXT_EXPORT float nci_f(void)>
230 Multiplies the value C<nci_dlvar_float> by 10.0 and returns the new
231 value.
233 =cut
237 PARROT_DYNEXT_EXPORT
238 float
239 nci_f(void)
241 nci_dlvar_float *= 10.0;
243 return nci_dlvar_float;
248 =item C<PARROT_DYNEXT_EXPORT float nci_fff(float l1, float l2)>
250 Returns the result of C<l1> / C<l2>.
252 =cut
256 PARROT_DYNEXT_EXPORT
257 PARROT_CONST_FUNCTION
258 float
259 nci_fff(float l1, float l2)
261 return l1 / l2;
266 =item C<PARROT_DYNEXT_EXPORT int nci_i(void)>
268 Returns the current value of <nci_dlvar_int>.
270 =cut
274 PARROT_DYNEXT_EXPORT
275 PARROT_PURE_FUNCTION
277 nci_i(void)
279 return nci_dlvar_int;
284 =item C<PARROT_DYNEXT_EXPORT int nci_isc(short l1, char l2)>
286 Returns the int product of C<l1 * l2>.
288 =cut
292 PARROT_DYNEXT_EXPORT
293 PARROT_CONST_FUNCTION
295 nci_isc(short l1, char l2)
297 return l1 * l2;
302 =item C<PARROT_DYNEXT_EXPORT int nci_ip(void *p)>
304 Performs a series of operations on values stored at pointer C<p>.
306 =cut
310 PARROT_DYNEXT_EXPORT
312 nci_ip(void *p)
314 typedef struct _dfi {
315 double d;
316 float f;
317 int i;
318 char *s;
319 } dfi;
320 dfi *sp = (dfi*) p;
321 puts(sp->s);
322 fflush(stdout);
324 return (int) (sp->d + sp->f + sp->i);
329 =item C<PARROT_DYNEXT_EXPORT int nci_it(void *p)>
331 Prints the first two characters in C<p>, in reversed order. Returns 2.
333 =cut
337 PARROT_DYNEXT_EXPORT
339 nci_it(void *p)
341 fprintf(stderr, "%c%c\n", ((char*) p)[1], ((char *) p)[0]);
342 fflush(stderr);
344 return 2;
349 =item C<PARROT_DYNEXT_EXPORT long nci_l(void)>
351 Returns the value of C<nci_dlvar_long>.
353 =cut
357 PARROT_DYNEXT_EXPORT
358 PARROT_PURE_FUNCTION
359 long
360 nci_l(void)
362 return nci_dlvar_long;
367 =item C<PARROT_DYNEXT_EXPORT int * nci_p(void)>
369 Returns the address of C<nci_dlvar_int>.
371 =cut
375 PARROT_DYNEXT_EXPORT
376 PARROT_CONST_FUNCTION
377 int *
378 nci_p(void)
380 return &nci_dlvar_int;
385 =item C<PARROT_DYNEXT_EXPORT char * nci_t(void)>
387 Returns the value of C<nci_dlvar_cstring>.
389 =cut
393 PARROT_DYNEXT_EXPORT
394 PARROT_CONST_FUNCTION
395 char *
396 nci_t(void)
398 return nci_dlvar_cstring;
403 =item C<PARROT_DYNEXT_EXPORT char * nci_tb(void *p)>
405 Returns "xx worked", where "xx" is replaced with the first two character values
406 of C<p>, in reverse order.
408 =cut
412 static char b[] = "xx worked\n";
414 PARROT_DYNEXT_EXPORT
415 char *
416 nci_tb(void *p)
418 b[0] = ((char*) p)[1];
419 b[1] = ((char*) p)[0];
421 return b;
426 =item C<PARROT_DYNEXT_EXPORT char * nci_tt(char *p)>
428 Returns "xx worked", where "xx" is replaced with the first two character values
429 of C<p>, in reverse order.
431 =cut
435 static char s[] = "xx worked\n";
437 PARROT_DYNEXT_EXPORT
438 char *
439 nci_tt(char *p)
441 s[0] = p[1];
442 s[1] = p[0];
444 return s;
449 =item C<PARROT_DYNEXT_EXPORT char * nci_tB(void **p)>
451 Returns "xx done", where "xx" is replaced with the first two character values
452 of C<p>, in reverse order.
454 =cut
458 static char B[] = "xx done\n";
460 PARROT_DYNEXT_EXPORT
461 char *
462 nci_tB(void **p)
464 B[0] = (*(char**) p)[1];
465 B[1] = (*(char**) p)[0];
467 return B;
472 =item C<PARROT_DYNEXT_EXPORT void * nci_pp(void *p)>
474 Returns the value C<p> directly.
476 =cut
480 PARROT_DYNEXT_EXPORT
481 PARROT_CONST_FUNCTION
482 void *
483 nci_pp(void *p)
485 return p;
490 =item C<PARROT_DYNEXT_EXPORT int nci_iiii(int i1, int i2, int i3)>
492 Prints three integers separated by whitespace to C<stderr>.
493 Returns 2.
495 =cut
499 PARROT_DYNEXT_EXPORT
501 nci_iiii(int i1, int i2, int i3)
503 fprintf(stderr, "%d %d %d\n", i1, i2, i3);
504 fflush(stderr);
506 return 2;
511 =item C<PARROT_DYNEXT_EXPORT int nci_i4i(long * l, int i)>
513 Returns the product of C<*l> and C<i>, as an int.
515 =cut
519 PARROT_DYNEXT_EXPORT
520 PARROT_PURE_FUNCTION
522 nci_i4i(long * l, int i)
525 return (int) (*l * i);
530 =item C<PARROT_DYNEXT_EXPORT int nci_ii3(int a, int *bp)>
532 Multiplies C<a> and C<*bp> together and returns the result. Updates C<*bp>
533 to the value 4711.
535 =cut
539 PARROT_DYNEXT_EXPORT
541 nci_ii3(int a, int *bp)
543 int r = a * *bp;
544 *bp = 4711;
546 return r;
551 =item C<PARROT_DYNEXT_EXPORT int call_back(const char *str)>
553 writes the string C<str> to stdout and returns the value 4711.
555 =cut
559 PARROT_DYNEXT_EXPORT
561 call_back(const char *str)
563 puts(str);
564 fflush(stdout);
566 return 4711;
571 =item C<PARROT_DYNEXT_EXPORT void * nci_pi(int test)>
573 Performs one from a series of tests, depending on the value given for C<test>.
575 =cut
579 PARROT_DYNEXT_EXPORT
580 void *
581 nci_pi(int test)
583 switch (test) {
584 case 0:
586 static struct {
587 int i[2];
588 char c;
589 } t = {
590 {42, 100},
593 return &t;
595 case 1:
597 static struct {
598 float f[2];
599 double d;
600 } t = {
601 {42.0, 100.0},
602 47.11
604 return &t;
606 case 2:
608 static struct {
609 char c;
610 int i;
611 } t = {
615 return &t;
617 case 3:
619 static struct {
620 const char *c;
621 int i;
622 } t = {
623 "hello",
626 return &t;
628 case 4:
630 static struct _x {
631 int i;
632 int j;
633 double d;
634 } xx = { 100, 77, 200.0 };
635 static struct {
636 char c;
637 struct _x *x;
638 } t = {
642 return &t;
644 case 5:
646 static struct {
647 int (*f)(const char *);
648 } t = {
649 call_back
651 return &t;
653 case 6:
655 static struct xt {
656 int x;
657 struct yt {
658 int i;
659 int j;
660 } _y;
661 int z;
662 } _x = {
664 { 127, 12345 },
667 return &_x;
669 case 7:
671 static struct xt {
672 char x;
673 struct yt {
674 char i;
675 int j;
676 } _y;
677 char z;
678 } _x = {
680 { 127, 12345 },
683 return &_x;
685 case 8:
687 static struct _z {
688 int i;
689 int j;
690 } zz = { 100, 77 };
691 static struct xt {
692 int x;
693 struct yt {
694 int i;
695 int j;
696 struct _z *z;
697 } _y;
698 } _x = {
700 { 127, 12345, &zz },
702 return &_x;
704 case 9:
706 static int i = 55555;
707 return &i;
709 case 10:
710 return NULL;
711 default:
712 fprintf(stderr, "unknown test number\n");
715 return NULL;
720 =item C<PARROT_DYNEXT_EXPORT short nci_s(void)>
722 Returns the value of C<nci_dlvar_short>.
724 =cut
728 PARROT_DYNEXT_EXPORT
729 PARROT_PURE_FUNCTION
730 short
731 nci_s(void)
733 return nci_dlvar_short;
738 =item C<PARROT_DYNEXT_EXPORT short nci_ssc(short l1, char l2)>
740 Returns the product of C<l1 * l2>.
742 =cut
746 PARROT_DYNEXT_EXPORT
747 PARROT_CONST_FUNCTION
748 short
749 nci_ssc(short l1, char l2)
751 return l1 * l2;
756 =item C<PARROT_DYNEXT_EXPORT void nci_vP(void *pmc)>
758 Prints "ok" if C<PMC> is not null, prints "got null" otherwise.
760 =cut
764 PARROT_DYNEXT_EXPORT
765 void
766 nci_vP(void *pmc)
768 /* TODO:
769 * Disable this test until someone figures a way to check for
770 * PMCNULL without using libparrot.
771 if (!PMC_IS_NULL(pmc))
772 puts("ok");
773 else
775 puts("got null");
781 =back
783 =head2 Functions used for pdd16 tests
785 =over 4
787 =cut
793 =item C<PARROT_DYNEXT_EXPORT void nci_cb_C1(cb_C1_func cb, void* user_data)>
795 Calls C<cb> function with the string "result" and the given C<user_data>.
796 No return value.
798 =cut
802 PARROT_DYNEXT_EXPORT
803 void
804 nci_cb_C1(cb_C1_func cb, void* user_data)
806 const char *result = "succeeded";
807 /* call the cb synchronously */
808 (cb)(result, user_data);
810 return;
815 =item C<PARROT_DYNEXT_EXPORT void nci_cb_C2(cb_C2_func cb, void* user_data)>
817 Calls the function C<cb> with the integer 77 and the given C<user_data>.
818 No return value.
820 =cut
824 PARROT_DYNEXT_EXPORT
825 void
826 nci_cb_C2(cb_C2_func cb, void* user_data)
828 /* call the cb synchronously */
829 (cb)(77, user_data);
831 return;
836 =item C<PARROT_DYNEXT_EXPORT void nci_cb_C3(cb_C3_func cb, void* user_data)>
838 Calls function C<cb> with C<&int_cb_C3> and the givn C<user_data>.
839 No return value.
841 =cut
845 static int int_cb_C3 = 99;
847 PARROT_DYNEXT_EXPORT
848 void
849 nci_cb_C3(cb_C3_func cb, void* user_data)
851 /* call the cb synchronously */
852 (cb)(&int_cb_C3, user_data);
854 return;
859 =item C<PARROT_DYNEXT_EXPORT void nci_cb_D1(cb_D1_func cb, void* user_data)>
861 Calls function C<cb> with data C<user_data> and the string "succeeded".
862 No return value.
864 =cut
868 PARROT_DYNEXT_EXPORT
869 void
870 nci_cb_D1(cb_D1_func cb, void* user_data)
872 const char *result = "succeeded";
873 /* call the cb synchronously */
874 (cb)(user_data, result);
876 return;
881 =item C<PARROT_DYNEXT_EXPORT void nci_cb_D2(cb_D2_func cb, void* user_data)>
883 Calls function C<cb> with data C<user_data> and the integer 88.
884 No return value.
886 =cut
890 PARROT_DYNEXT_EXPORT
891 void
892 nci_cb_D2(cb_D2_func cb, void* user_data)
894 /* call the cb synchronously */
895 (cb)(user_data, 88);
897 return;
902 =item C<PARROT_DYNEXT_EXPORT void nci_cb_D3(cb_D3_func cb, void* user_data)>
904 Calls function C<cb> with data C<user_data> and C<&int_cb_D3>.
905 No return value.
907 =cut
911 static int int_cb_D3 = 111;
913 PARROT_DYNEXT_EXPORT
914 void
915 nci_cb_D3(cb_D3_func cb, void* user_data)
917 /* call the cb synchronously */
918 (cb)(user_data, &int_cb_D3);
920 return;
925 =item C<PARROT_DYNEXT_EXPORT void nci_cb_D4(cb_D4_func times_ten, void*
926 user_data)>
928 Calls function C<times_ten> with data C<user_data> and C<&int_cb_D4> 10 times
929 in a loop, incrementing C<int_cb_D4> after every call.
930 No return value.
932 =cut
936 PARROT_DYNEXT_EXPORT
937 void
938 nci_cb_D4(cb_D4_func times_ten, void* user_data)
940 int cnt;
941 for (cnt = 0; cnt < 9; ++cnt)
943 (times_ten)(user_data, &int_cb_D4);
944 ++int_cb_D4;
947 return;
952 =item C<PARROT_DYNEXT_EXPORT void nci_pip(int count, Rect_Like *rects)>
954 Prints a count integer and the coordinates of 4 rectangles.
956 =cut
960 PARROT_DYNEXT_EXPORT
961 void
962 nci_pip(int count, Rect_Like *rects)
964 int i;
965 printf("Count: %d\n", count);
966 for (i = 0; i < 4; ++i)
967 printf("X: %d\nY: %d\nW: %d\nH: %d\n",
968 rects[i].x, rects[i].y, rects[i].w, rects[i].h);
973 =item C<PARROT_DYNEXT_EXPORT int nci_i33(int *double_me, int *triple_me)>
975 Doubles C<double_me> and triples C<triple_me>. Returns their sum.
977 =cut
981 PARROT_DYNEXT_EXPORT
983 nci_i33(ARGMOD(int *double_me), ARGMOD(int *triple_me))
985 *double_me *= 2;
986 *triple_me *= 3;
988 return (*double_me + *triple_me);
993 =item C<PARROT_DYNEXT_EXPORT void nci_vpii(Outer *my_data, int my_x, int my_y)>
995 Updates data in structure pointer C<my_data> with the given data C<my_x> and
996 C<my_y>.
998 =cut
1002 PARROT_DYNEXT_EXPORT
1003 void
1004 nci_vpii(ARGMOD(Outer *my_data), int my_x, int my_y)
1006 my_data->x = my_x;
1007 my_data->nested->y = my_y;
1012 =item C<PARROT_DYNEXT_EXPORT void * nci_piiii(int alpha, int beta, int gamma,
1013 int delta)>
1015 Stores 4 integer values into an array structure, and returns the address
1016 of that structure.
1018 =cut
1022 static int my_array[4];
1024 PARROT_DYNEXT_EXPORT
1025 void *
1026 nci_piiii(int alpha, int beta, int gamma, int delta)
1028 static struct array_container
1030 int x;
1031 int *array;
1032 } container;
1034 my_array[0] = alpha;
1035 my_array[1] = beta;
1036 my_array[2] = gamma;
1037 my_array[3] = delta;
1039 container.x = 4;
1040 container.array = my_array;
1042 return &container;
1047 =item C<PARROT_DYNEXT_EXPORT void * nci_pii(int fac1, int fac2)>
1049 Returns the address of global variable C<nci_dlvar_int> whose value is set
1050 to the product of C<fac1 * fac2>.
1052 =cut
1056 PARROT_DYNEXT_EXPORT
1057 void *
1058 nci_pii(int fac1, int fac2)
1060 nci_dlvar_int = fac1 * fac2;
1062 return &nci_dlvar_int;
1067 =item C<PARROT_DYNEXT_EXPORT void nci_v(void)>
1069 Multiplies the global variable C<nci_dlvar_int> times 10.
1071 =cut
1075 PARROT_DYNEXT_EXPORT
1076 void
1077 nci_v(void)
1079 nci_dlvar_int *= 10;
1084 =item C<PARROT_DYNEXT_EXPORT void nci_vv(void)>
1086 Multiplies the global variable C<nci_dlvar_int> by 3.
1088 =cut
1092 PARROT_DYNEXT_EXPORT
1093 void
1094 nci_vv(void)
1096 nci_dlvar_int *= 3;
1101 =item C<PARROT_DYNEXT_EXPORT void nci_vVi(Opaque **outOpaque, int x)>
1103 Test an NCI opaque struct out value.
1105 =cut
1109 PARROT_DYNEXT_EXPORT
1110 void
1111 nci_vVi(ARGOUT(Opaque **outOpaque), int x)
1113 static Opaque opaque;
1114 opaque.x = x;
1115 *outOpaque = &opaque;
1120 =item C<PARROT_DYNEXT_EXPORT void nci_vp(Opaque *inOpaque)>
1122 Test that a previously generated opaque struct gets passed back
1123 to an NCI function correctly.
1125 =cut
1129 PARROT_DYNEXT_EXPORT
1130 void
1131 nci_vp(ARGIN(Opaque *inOpaque))
1133 if (inOpaque)
1134 printf("got %d\n", inOpaque->x);
1135 else
1136 printf("got null\n");
1141 =item C<PARROT_DYNEXT_EXPORT char * nci_ttt(char *s1, char *s2)>
1143 Prints and returns "s2, s2, s1"
1145 =cut
1149 PARROT_DYNEXT_EXPORT
1150 char *
1151 nci_ttt(char *s1, char *s2)
1153 char* s = (char*) malloc((2 * strlen(s2)) + strlen(s1) + 5);
1154 sprintf(s, "%s, %s, %s", s2, s2, s1);
1155 printf("%s\n", s);
1156 return s;
1161 =item C<static void validate_float(float f, double checkval)>
1163 Check that a float value f is has an error ratio of less than 0.01
1164 when compared to a double value checkval
1166 =cut
1170 static void
1171 validate_float(float f, double checkval)
1173 int valid;
1174 double error_ratio;
1175 error_ratio = (((double)f) - checkval) / checkval;
1176 valid = error_ratio <= 0.01 && error_ratio >= -0.01;
1177 printf("%i\n", valid);
1182 =item C<PARROT_DYNEXT_EXPORT void nci_vfff(float l1, float l2, float l3)>
1184 Checks that C<[ l1, l2, l3 ]> = C<[ 3456.54, 10.1999, 14245.567 ]> within an
1185 error of 0.01.
1187 =cut
1191 PARROT_DYNEXT_EXPORT
1192 void
1193 nci_vfff(float l1, float l2, float l3)
1195 validate_float(l1, 3456.54);
1196 validate_float(l2, 10.1999);
1197 validate_float(l3, 14245.567);
1203 =item C<PARROT_DYNEXT_EXPORT void nci_vV(const char **ptr)>
1205 Sets C<*ptr> to "Hello bright new world\n".
1207 =cut
1211 PARROT_DYNEXT_EXPORT
1212 void
1213 nci_vV(const char **ptr)
1215 *ptr = "Hello bright new world\n";
1220 =item C<PARROT_DYNEXT_EXPORT void nci_vVVV(const char **ptr1, const char **ptr2,
1221 const char **ptr3)>
1223 Sets C<*ptr1> to "Hello bright new world!\n", C<*ptr2> to "It is a beautiful
1224 day!\n", and C<*ptr3> to "Go suck a lemon.\n".
1226 =cut
1230 PARROT_DYNEXT_EXPORT
1231 void
1232 nci_vVVV(const char **ptr1, const char **ptr2, const char **ptr3)
1234 *ptr1 = "Hello bright new world!\n";
1235 *ptr2 = "It is a beautiful day!\n";
1236 *ptr3 = "Go suck a lemon.\n";
1239 #ifdef TEST
1241 char l2 = 4;
1242 float f2 = 4.0;
1246 =item C<int main(void)>
1248 Calls test functions C<nci_ssc> and C<nci_fff> and prints their results.
1250 =cut
1255 main(void)
1257 short l1 = 3;
1258 float f, f1 = 3.0;
1259 int l = nci_ssc(l1, l2);
1260 printf("%d\n", l);
1261 f = nci_fff(f1, f2);
1262 printf("%f\n", f);
1264 return 0;
1267 #endif
1269 #ifdef __cplusplus
1271 #endif
1275 =back
1277 =head1 SEE ALSO:
1279 F<docs/pdds/pdd16_native_call.pod>
1280 F<config/gen/makefiles/root.in>
1281 F<t/pmc/nci.t>
1283 =cut
1289 * Local variables:
1290 * c-file-style: "parrot"
1291 * End:
1292 * vim: expandtab shiftwidth=4: