Debian Codegraph @

t/ffi/record.c

raw
1 #include <string.h>
2 #include "libtest.h"
3
4 typedef struct {
5 char name[16];
6 int32_t value;
7 } foo_record_t;
8
9 EXTERN const char *
10 foo_get_name(foo_record_t *self)
11 {
12 static char ret[16];
13 if(self == NULL)
14 return NULL;
15 /*
16 * TODO: we need to copy the name because the record
17 * could fall out of scope before we start processing
18 * the return values in ffi_platypus_call.h. If we
19 * can rework that code to delay until after the SV*
20 * is created for the return value then we wouldn't
21 * need to do this.
22 */
23 memcpy(ret, self->name, 16);
24 return ret;
25 }
26
27 EXTERN const char *
28 foo_value_get_name(foo_record_t self)
29 {
30 static char name[16];
31 strcpy(name, self.name);
32 return name;
33 }
34
35 EXTERN int32_t
36 foo_get_value(foo_record_t *self)
37 {
38 if(self == NULL)
39 return 0;
40 return self->value;
41 }
42
43 EXTERN int32_t
44 foo_value_get_value(foo_record_t self)
45 {
46 return self.value;
47 }
48
49 EXTERN foo_record_t *
50 foo_create(const char *name, int32_t value)
51 {
52 static foo_record_t self;
53 int i;
54
55 for(i=0; i<16; i++)
56 self.name[i] = '\0';
57
58 strcpy(self.name, name);
59 self.value = value;
60
61 return &self;
62 }
63
64 EXTERN foo_record_t
65 foo_value_create(const char *name, int32_t value)
66 {
67 foo_record_t self;
68 int i;
69
70 for(i=0; i<16; i++)
71 self.name[i] = '\0';
72
73 strcpy(self.name, name);
74 self.value = value;
75
76 return self;
77 }