--- deliantra/server/common/utils.C 2010/07/02 02:00:47 1.97
+++ deliantra/server/common/utils.C 2017/01/19 21:51:43 1.105
@@ -1,22 +1,22 @@
/*
* This file is part of Deliantra, the Roguelike Realtime MMORPG.
- *
- * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
- *
+ *
+ * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
+ *
* Deliantra is free software: you can redistribute it and/or modify it under
* the terms of the Affero GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the Affero GNU General Public License
* and the GNU General Public License along with this program. If not, see
* .
- *
+ *
* The authors can be reached via e-mail to
*/
@@ -65,7 +65,7 @@
/* Checks a player-provided string which will become the msg property of
* an object for dangerous input.
*/
-bool
+bool
msg_is_safe (const char *msg)
{
bool safe = true;
@@ -94,7 +94,10 @@
signal (SIGABRT, SIG_IGN);
signal (SIGSEGV, SIG_DFL);
+ signal (SIGFPE , SIG_DFL);
+#ifdef SIGBUS
signal (SIGBUS , SIG_DFL);
+#endif
signal (SIGILL , SIG_DFL);
signal (SIGTRAP, SIG_DFL);
@@ -128,7 +131,8 @@
LOG (llevError, "fork abort: %s\n", msg);
}
-void *salloc_ (int n) throw (std::bad_alloc)
+void *
+salloc_ (int n) throw (std::bad_alloc)
{
void *ptr = g_slice_alloc (n);
@@ -139,7 +143,8 @@
return ptr;
}
-void *salloc_ (int n, void *src) throw (std::bad_alloc)
+void *
+salloc_ (int n, void *src) throw (std::bad_alloc)
{
void *ptr = salloc_ (n);
@@ -157,7 +162,8 @@
#define MAGIC 0xa1b2c35543deadLL
-void *g_slice_alloc (unsigned long size)
+void *
+g_slice_alloc (unsigned long size)
{
unsigned long *p = (unsigned long *) (g_slice_alloc)(size + sizeof (unsigned long));
*p++ = size ^ MAGIC;
@@ -165,12 +171,14 @@
return (void *)p;
}
-void *g_slice_alloc0 (unsigned long size)
+void *
+g_slice_alloc0 (unsigned long size)
{
return memset (g_slice_alloc (size), 0, size);
}
-void g_slice_free1 (unsigned long size, void *ptr)
+void
+g_slice_free1 (unsigned long size, void *ptr)
{
//fprintf (stderr, "g_slice_free %ld %p\n", size, ptr);//D
if (expect_true (ptr))
@@ -194,6 +202,42 @@
/******************************************************************************/
+refcnt_buf::refcnt_buf (size_t size)
+{
+ static uint32_t empty_buf [2] = { 0, 1 }; // 2 == never deallocated
+ data = (char *)empty_buf + overhead;
+ assert (overhead == sizeof (empty_buf));
+ inc ();
+}
+
+refcnt_buf::refcnt_buf (void *data, size_t size)
+{
+ _alloc (size);
+ memcpy (this->data, data, size);
+}
+
+refcnt_buf::~refcnt_buf ()
+{
+ dec ();
+}
+
+void
+refcnt_buf::_dealloc ()
+{
+ sfree (data - overhead, size () + overhead);
+}
+
+refcnt_buf &
+refcnt_buf::operator =(const refcnt_buf &src)
+{
+ dec ();
+ data = src.data;
+ inc ();
+ return *this;
+}
+
+/******************************************************************************/
+
int
assign (char *dst, const char *src, int maxsize)
{
@@ -247,7 +291,8 @@
return buf;
}
-tstamp now ()
+tstamp
+now ()
{
struct timeval tv;
@@ -322,7 +367,8 @@
0x2d02ef8dL
};
-void thread::start (void *(*start_routine)(void *), void *arg)
+void
+thread::start (void *(*start_routine)(void *), void *arg)
{
pthread_attr_t attr;