File: hello.c

package info (click to toggle)
pybindgen 0.20.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: python: 15,981; cpp: 1,889; ansic: 617; makefile: 86; sh: 4
file content (103 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download | duplicates (8)
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
#include "hello.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Bool hello_print_message(const char *message)
{
    printf("Hello: %s\n", message);
    return 0;
}

double hello_sum(double x, double y)
{
    return x + y;
}


struct _HelloFoo
{
    int refcount;
    char *data;
};

HelloFoo*
hello_foo_new(void)
{
    HelloFoo *foo;
    foo = (HelloFoo *) malloc(sizeof(HelloFoo));
    foo->refcount = 1;
    foo->data = NULL;
    return foo;
}

HelloFoo*
hello_foo_new_from_data(const char *data)
{
    HelloFoo* foo;

    foo = hello_foo_new();
    hello_foo_set_data(foo, data);
    return foo;
}

HelloFoo*
hello_foo_new_with_spaces (int num_spaces)
{
    int i;
    HelloFoo *foo;
    foo = hello_foo_new();
    foo->data = malloc(num_spaces + 1);
    for (i = 0; i < num_spaces; i++)
	foo->data[i] = ' ';
    foo->data[i] = '\0';
    return foo;
}

void
hello_foo_ref(HelloFoo *foo)
{
    foo->refcount++;
}

void
hello_foo_unref(HelloFoo *foo)
{
    if (--foo->refcount > 0)
        return;
    
    if (foo->data)
	    free(foo->data);
    free(foo);
}

void
hello_foo_set_data(HelloFoo   *foo,
		   const char *data)
{
    if (foo->data)
	free(foo->data);
    foo->data = strdup(data);
}

const char *
hello_foo_get_data(HelloFoo *foo)
{
    return foo->data;
}

const HelloFoo* hello_foo_get_self  (HelloFoo *foo)
{
    return foo;
}

int hello_get_hash  (const HelloFoo *foo)
{
    if (foo)
    {
        return (int) (long) foo;
    } else {
        return -1;
    }
}