b9434cda1d4403fa48352162d673b0b139a66835
[debian/amanda] / perl / amglue / amglue.h
1 /*
2  * Copyright (c) 2005 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2.1 as
6  * published by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
11  * License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
16  *
17  * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 #ifndef AMANDA_AMGLUE_H
22 #define AMANDA_AMGLUE_H
23
24 #include "EXTERN.h"
25 #include "perl.h"
26 #include "XSUB.h"
27 #include <glib.h>
28 #include <glib-object.h>
29
30 /* These defines are missing from older glibs, so we add them here */
31 #ifndef G_MAXINT8
32 #define G_MAXINT8 (127)
33 #endif
34
35 #ifndef G_MININT8
36 #define G_MININT8 (-127-1)
37 #endif
38
39 #ifndef G_MAXUINT8
40 #define G_MAXUINT8 (255)
41 #endif
42
43 #ifndef G_MAXINT16
44 #define G_MAXINT16 (32767)
45 #endif
46
47 #ifndef G_MININT16
48 #define G_MININT16 (-32767-1)
49 #endif
50
51 #ifndef G_MAXUINT16
52 #define G_MAXUINT16 (65535)
53 #endif
54
55 #ifndef G_MAXINT32
56 #define G_MAXINT32 (2147483647)
57 #endif
58
59 #ifndef G_MININT32
60 #define G_MININT32 (-2147483647-1)
61 #endif
62
63 #ifndef G_MAXUINT32
64 #define G_MAXUINT32 (4294967295U)
65 #endif
66
67 /*
68  * prototypes for ghashtable.c
69  */
70
71 /* Turn a GLib hash table (mapping strings to strings) into a reference
72  * to a Perl hash table.
73  *
74  * @param hash: GLib hash table
75  * @returns: Perl hashref
76  */
77 SV *g_hash_table_to_hashref(GHashTable *hash);
78
79 /*
80  * prototypes for bigint.c
81  */
82
83 /*
84  * These functions handle conversion of integers to and from Perl-compatible
85  * values.  Most perls do not natively support 64-bit integers, so these functions
86  * interface with the Math::BigInt module to support those integers.  The functions
87  * also handle conversions from floating-point to integer values, with silent fraction
88  * truncation, as perl automatically promotes integers to doubles on overflow.
89  */
90
91 /* Convert an (unsigned) integer to a Perl SV.  These will always produce a 
92  * Math::BigInt object.  Any failure is fatal.  *All* C-to-Perl integer conversions
93  * must use these functions.
94  *
95  * @param v: value to convert
96  * @returns: pointer to a new SV (refcount=1)
97  */
98 SV *amglue_newSVi64(gint64 v);
99 SV *amglue_newSVu64(guint64 v);
100
101 /* Convert a Perl SV to an integer of the specified size.  These functions should
102  * be used for *all* Perl-to-C integer conversions, since the Perl value may be a
103  * Math::BigInt object.  All of these functions will call croak() on an overflow
104  * condition, rather than silently truncate.
105  *
106  * @param sv: perl value to convert
107  * @returns: value of the given type
108  */
109 gint64 amglue_SvI64(SV *sv);
110 guint64 amglue_SvU64(SV *sv);
111 gint32 amglue_SvI32(SV *sv);
112 guint32 amglue_SvU32(SV *sv);
113 gint16 amglue_SvI16(SV *sv);
114 guint16 amglue_SvU16(SV *sv);
115 gint8 amglue_SvI8(SV *sv);
116 guint8 amglue_SvU8(SV *sv);
117
118 #endif /* AMANDA_AMGLUE_H */