… | |
… | |
40 | |
40 | |
41 | #include <glib.h> |
41 | #include <glib.h> |
42 | |
42 | |
43 | refcnt_base::refcnt_t refcnt_dummy; |
43 | refcnt_base::refcnt_t refcnt_dummy; |
44 | ssize_t slice_alloc; |
44 | ssize_t slice_alloc; |
45 | |
|
|
46 | #if !GCC_VERSION(3,4) |
|
|
47 | int least_significant_bit (uint32_t x) |
|
|
48 | { |
|
|
49 | x &= -x; // this isolates the lowest bit |
|
|
50 | |
|
|
51 | int r = 0; |
|
|
52 | |
|
|
53 | if (x & 0xaaaaaaaa) r += 1; |
|
|
54 | if (x & 0xcccccccc) r += 2; |
|
|
55 | if (x & 0xf0f0f0f0) r += 4; |
|
|
56 | if (x & 0xff00ff00) r += 8; |
|
|
57 | if (x & 0xffff0000) r += 16; |
|
|
58 | |
|
|
59 | return r; |
|
|
60 | } |
|
|
61 | #endif |
|
|
62 | |
45 | |
63 | /******************************************************************************/ |
46 | /******************************************************************************/ |
64 | |
47 | |
65 | /* Checks a player-provided string which will become the msg property of |
48 | /* Checks a player-provided string which will become the msg property of |
66 | * an object for dangerous input. |
49 | * an object for dangerous input. |
… | |
… | |
130 | |
113 | |
131 | LOG (llevError, "fork abort: %s\n", msg); |
114 | LOG (llevError, "fork abort: %s\n", msg); |
132 | } |
115 | } |
133 | |
116 | |
134 | void * |
117 | void * |
135 | salloc_ (int n) throw (std::bad_alloc) |
118 | salloc_ (int n) |
136 | { |
119 | { |
137 | void *ptr = g_slice_alloc (n); |
120 | void *ptr = g_slice_alloc (n); |
138 | |
121 | |
139 | if (!ptr) |
122 | if (!ptr) |
140 | throw std::bad_alloc (); |
123 | throw std::bad_alloc (); |
… | |
… | |
142 | slice_alloc += n; |
125 | slice_alloc += n; |
143 | return ptr; |
126 | return ptr; |
144 | } |
127 | } |
145 | |
128 | |
146 | void * |
129 | void * |
147 | salloc_ (int n, void *src) throw (std::bad_alloc) |
130 | salloc_ (int n, void *src) |
148 | { |
131 | { |
149 | void *ptr = salloc_ (n); |
132 | void *ptr = salloc_ (n); |
150 | |
133 | |
151 | if (src) |
134 | if (src) |
152 | memcpy (ptr, src, n); |
135 | memcpy (ptr, src, n); |