1 /* babl - dynamically extendable universal pixel conversion library.
2  * Copyright (C) 2005, Øyvind Kolås.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, see
16  * <https://www.gnu.org/licenses/>.
17  */
18 
19 #include "config.h"
20 #include <stdlib.h>
21 #include "babl-internal.h"
22 
23 static const char *class_names[] =
24 {
25   "BablInstance",
26   "BablType",
27   "BablTypeInteger",
28   "BablTypeFloat",
29   "BablSampling",
30   "BablTRC",
31   "BablComponent",
32   "BablModel",
33   "BablFormat",
34   "BablSpace",
35   "BablConversion",
36   "BablConversionLinear",
37   "BablConversionPlane",
38   "BablConversionPlanar",
39   "BablFish",
40   "BablFishReference",
41   "BablFishSimple",
42   "BablFishPath",
43   "BablImage",
44   "BablExtenstion",
45   "BablSky"
46 };
47 
48 const char *
babl_class_name(BablClassType klass)49 babl_class_name (BablClassType klass)
50 {
51   return class_names[klass - BABL_INSTANCE];
52 }
53 
54 /* global variable, indicating whether name lookups
55  * are frowned upon or not (they are frowned upon within BablBase,
56  * since that leads to more strings than neccesary in the library.)
57  */
58 int babl_hmpf_on_name_lookups = 0;
59 
60 #include <sys/types.h>
61 #include <unistd.h>
62 
63 int
babl_backtrack(void)64 babl_backtrack (void)
65 {
66   char buf[512];
67 
68   snprintf (buf, sizeof (buf), "echo bt>/tmp/babl.gdb;"
69            "gdb -q --batch -x /tmp/babl.gdb --pid=%i | grep 'in ''babl_die' -A40", getpid ());
70   return system (buf);
71 }
72 
73 void
babl_die(void)74 babl_die (void)
75 {
76   babl_backtrack ();
77   exit (-1);
78 }
79 
80 BablMutex *babl_fish_mutex;
81 
82 BablMutex *babl_format_mutex;
83 #if BABL_DEBUG_MEM
84 BablMutex *babl_debug_mutex;
85 #endif
86 BablMutex *babl_reference_mutex;
87 BablMutex *babl_space_mutex;
88 
89 void
babl_internal_init(void)90 babl_internal_init (void)
91 {
92   babl_set_malloc (malloc);
93   babl_set_free (free);
94   babl_fish_mutex = babl_mutex_new ();
95   babl_format_mutex = babl_mutex_new ();
96   babl_reference_mutex = babl_mutex_new ();
97   babl_space_mutex = babl_mutex_new ();
98 #if BABL_DEBUG_MEM
99   babl_debug_mutex = babl_mutex_new ();
100 #endif
101 }
102 
103 void
babl_internal_destroy(void)104 babl_internal_destroy (void)
105 {
106   babl_mutex_destroy (babl_fish_mutex);
107   babl_mutex_destroy (babl_format_mutex);
108   babl_mutex_destroy (babl_reference_mutex);
109 #if BABL_DEBUG_MEM
110   babl_mutex_destroy (babl_debug_mutex);
111 #endif
112 }
113 
114 
115 const char *
babl_get_name(const Babl * babl)116 babl_get_name (const Babl *babl)
117 {
118   babl_assert (BABL_IS_BABL (babl));
119   return babl->instance.name;
120 }
121 
122 const char *
babl_get_doc(const Babl * babl)123 babl_get_doc (const Babl *babl)
124 {
125   babl_assert (BABL_IS_BABL (babl));
126   return babl->instance.doc;
127 }
128 
babl_doc(const Babl * babl,const char * doc)129 void babl_doc (const Babl     *babl,
130                const char     *doc)
131 {
132   babl_assert (BABL_IS_BABL (babl));
133   ((Babl*)babl)->instance.doc = doc;
134 }
135