annotate erlang/erldc/c_src/erldctesttargets.c @ 34:2682a627168c

- breaking changes: * restrict 'Z' conversions to immutable types * restrict 'p' to mutable types (and handles)
author Tassilo Philipp
date Sun, 12 Apr 2020 19:37:37 +0200
parents 0cfcc391201f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 Copyright (c) 2014 Erik Mackdanz <erikmack@gmail.com>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software for any
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 purpose with or without fee is hereby granted, provided that the above
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 copyright notice and this permission notice appear in all copies.
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 #include <stdlib.h>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 #include <stdio.h>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 char get_next_char(char in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 return in+1;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 unsigned char get_next_char_u(unsigned char in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 /* printf("In c, sum is %d\n",in+1); */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 return in+1;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 int is_false(int in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 return !in;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 unsigned int dual_increment_u(unsigned int in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 in++;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 in++;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 return in;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 short times_three(short in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 return in * 3;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 unsigned short times_three_u(unsigned short in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 return in * 3;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 long add_nineteen(long in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 return in + 19;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 unsigned long add_nineteen_u(unsigned long in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 return in + 19;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 long long subtract_four(long long in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 return in - 4;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 unsigned long long subtract_four_u(unsigned long long in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 return in - 4;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 int add_seven(int in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 return in + 7;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 int add_one(int in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 return in + 1;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 void* coolmalloc(int sz) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 void* ptr = malloc(sz);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 /* printf("I've allocated at addr %p\n",ptr); */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 return ptr;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 void* coolidentity(void* in) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 return in;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 void coolsetstr(void* buf, char* val) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 sprintf(buf,"%s",val);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85 void coolfree(void* ptr) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86 /* printf("The value to free is %s\n", ptr); */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87 free(ptr);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 void noop() {}
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 float calculate_pi(float precision) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 return 21.0 / (7.0 * precision); // closer...
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 double times_pi(double multiplicand) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 return multiplicand * 3.1; // nerd rage!
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
99
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
100 char* interested_reply(char* yourname) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101 int totalmax = 256;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102 char* buf = malloc(totalmax);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 snprintf(buf,totalmax,"Really, %s? My name is Erik.",yourname);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104 return buf;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 char* several_args(long one, char two, char* three, float four) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 char* reply = malloc(100);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109 snprintf(reply, 100,"Your args were %ld, %c, %s, %.1f",
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110 one,two,three,four);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 return reply;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 }