ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/utils.C
(Generate patch)

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.105 by root, Thu Jan 19 21:51:43 2017 UTC vs.
Revision 1.107 by root, Sat Nov 17 23:33:17 2018 UTC

40 40
41#include <glib.h> 41#include <glib.h>
42 42
43refcnt_base::refcnt_t refcnt_dummy; 43refcnt_base::refcnt_t refcnt_dummy;
44ssize_t slice_alloc; 44ssize_t slice_alloc;
45
46#if !GCC_VERSION(3,4)
47int 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
134void * 117void *
135salloc_ (int n) throw (std::bad_alloc) 118salloc_ (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
146void * 129void *
147salloc_ (int n, void *src) throw (std::bad_alloc) 130salloc_ (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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines