ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.193 by root, Thu Apr 19 16:23:48 2007 UTC vs.
Revision 1.202 by root, Sun Apr 29 00:19:39 2007 UTC

21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */ 24 */
25 25
26#include "autoconf.h"
27
26#define PLUGIN_NAME "perl" 28#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 29#define PLUGIN_VERSION "cfperl 0.5"
28 30
29#define CEDES_PER_TICK 5 31#define CEDES_PER_TICK 5
32
33#if HAVE_EXECINFO_H
34# include <execinfo.h>
35#endif
30 36
31#include <plugin_common.h> 37#include <plugin_common.h>
32#include <sounds.h> 38#include <sounds.h>
33#include <cstdarg> 39#include <cstdarg>
34#include <sproto.h> 40#include <sproto.h>
56 62
57typedef char *octet_string; 63typedef char *octet_string;
58typedef char *utf8_string; 64typedef char *utf8_string;
59typedef const char *const_octet_string; 65typedef const char *const_octet_string;
60typedef const char *const_utf8_string; 66typedef const char *const_utf8_string;
67
68typedef std::string std__string;
61 69
62#if IVSIZE >= 8 70#if IVSIZE >= 8
63 typedef IV val64; 71 typedef IV val64;
64# define newSVval64 newSViv 72# define newSVval64 newSViv
65# define SvVAL64 SvIV 73# define SvVAL64 SvIV
109 117
110unordered_vector<attachable *> attachable::mortals; 118unordered_vector<attachable *> attachable::mortals;
111 119
112attachable::~attachable () 120attachable::~attachable ()
113{ 121{
114 flags |=0x3300;//D
115 assert (!self); 122 assert (!self);
116 assert (!cb); 123 assert (!cb);
117} 124}
118 125
119int 126int
135 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 142 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
136 SvREFCNT_dec (self); 143 SvREFCNT_dec (self);
137 144
138 // self *must* be null now because thats sv_unmagic's job. 145 // self *must* be null now because thats sv_unmagic's job.
139 assert (!this->self); 146 assert (!this->self);
140 flags |= 0x80; // severed //D
141 } 147 }
142} 148}
143 149
144void 150void
145attachable::optimise () 151attachable::optimise ()
146{ 152{
147 if (self 153 if (self
148 && SvREFCNT (self) == 1 154 && SvREFCNT (self) == 1
149 && !HvTOTALKEYS (self)) 155 && !HvTOTALKEYS (self))
150 flags |= 0x40,//D
151 sever_self (); 156 sever_self ();
152} 157}
153 158
154// check wether the object really is dead 159// check wether the object really is dead
155void 160void
170 { 175 {
171 SvREFCNT_dec (cb); 176 SvREFCNT_dec (cb);
172 cb = 0; 177 cb = 0;
173 } 178 }
174 179
175 if (self)
176 sever_self ();
177
178 flags |= 0x20; //D
179 mortals.push_back (this); 180 mortals.push_back (this);
180} 181}
181 182
182void 183void
183attachable::destroy () 184attachable::destroy ()
185 if (destroyed ()) 186 if (destroyed ())
186 return; 187 return;
187 188
188 flags |= F_DESTROYED; 189 flags |= F_DESTROYED;
189 do_destroy (); 190 do_destroy ();
191 sever_self ();
190} 192}
191 193
192void 194void
193attachable::check_mortals () 195attachable::check_mortals ()
194{ 196{
199 if (i >= mortals.size ()) 201 if (i >= mortals.size ())
200 { 202 {
201 i = 0; 203 i = 0;
202 204
203 if (mortals.size () > 1000) 205 if (mortals.size () > 1000)
204 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); 206 LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ());
205 207
206 break; 208 break;
207 } 209 }
208 210
209 attachable *obj = mortals [i]; 211 attachable *obj = mortals [i];
210 212
211 obj->refcnt_chk (); // unborrow from perl, if necessary 213#if 0
212 214 if (obj->self)//D make this an assert later
213 //if (obj->refcnt > 0 || obj->self)
214 if (obj->refcnt || obj->self)
215 { 215 {
216//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D 216 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
217 obj->sever_self ();
218 }
219#endif
220
221 if (obj->refcnt)
222 {
217 ++i; // further delay freeing 223 ++i; // further delay freeing
218 224
219 if (!(i & 0x3ff)) 225 if (!(i & 0x3ff))
220 break; 226 break;
221 } 227 }
222 else 228 else
223 { 229 {
224 mortals.erase (i); 230 mortals.erase (i);
231 obj->sever_self ();
225 delete obj; 232 delete obj;
226 } 233 }
227 } 234 }
228} 235}
229 236
278 285
279 if (!obj->self) 286 if (!obj->self)
280 { 287 {
281 obj->self = newHV (); 288 obj->self = newHV ();
282 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 289 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
283 obj->flags |= (obj->flags & 0xc0) << 8;
284 obj->flags &= ~0xc0;//D
285 obj->flags |= 0x10;//D
286 290
287 // now bless the object _once_ 291 // now bless the object _once_
288 return sv_bless (newRV_inc ((SV *)obj->self), stash); 292 return sv_bless (newRV_inc ((SV *)obj->self), stash);
289 } 293 }
290 else 294 else
356inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 360inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
357 361
358inline SV *to_sv (object & v) { return to_sv (&v); } 362inline SV *to_sv (object & v) { return to_sv (&v); }
359inline SV *to_sv (living & v) { return to_sv (&v); } 363inline SV *to_sv (living & v) { return to_sv (&v); }
360 364
361//inline SV *to_sv (faceinfo * v) { return to_sv (v->name); }
362inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
363inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } 365inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
366inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); }
364 367
365inline SV *to_sv (UUID v) 368inline SV *to_sv (UUID v)
366{ 369{
367 char buf[128]; 370 char buf[128];
368 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); 371 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
614 perl_construct (perl); 617 perl_construct (perl);
615 618
616 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 619 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
617 620
618 const char *argv[] = { 621 const char *argv[] = {
619 "", 622 settings.argv [0],
620 "-e" 623 "-e"
621 "use Event; use Coro;" // required for bootstrap 624 "use Event; use Coro;" // required for bootstrap
622 "cf->bootstrap;" // required for datadir :*> 625 "cf->bootstrap;" // required for datadir :*>
623 "unshift @INC, cf::datadir ();" 626 "unshift @INC, cf::datadir ();"
624 "require cf;" 627 "require cf;"
946 CALL_ARG (exit); 949 CALL_ARG (exit);
947 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 950 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
948 CALL_END; 951 CALL_END;
949} 952}
950 953
954void
955log_backtrace (const char *msg)
956{
957#if HAVE_BACKTRACE
958 void *addr [20];
959 int size = backtrace (addr, 20);
960
961 CALL_BEGIN (size);
962 CALL_ARG (msg);
963 for (int i = 0; i < size; ++i)
964 CALL_ARG ((IV)addr [i]);
965 CALL_CALL ("cf::_log_backtrace", G_VOID);
966 CALL_END;
967#endif
968}
969
951///////////////////////////////////////////////////////////////////////////// 970/////////////////////////////////////////////////////////////////////////////
952 971
953struct EventAPI *watcher_base::GEventAPI; 972struct EventAPI *watcher_base::GEventAPI;
954struct CoroAPI *coroapi::GCoroAPI; 973struct CoroAPI *coroapi::GCoroAPI;
955 974
1109 const char *name; 1128 const char *name;
1110 IV iv; 1129 IV iv;
1111 } *civ, const_iv[] = { 1130 } *civ, const_iv[] = {
1112# define const_iv(name) { # name, (IV)name }, 1131# define const_iv(name) { # name, (IV)name },
1113 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1132 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1133 const_iv (logBacktrace)
1114 1134
1115 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1135 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1116 1136
1117 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1137 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1118 1138
1265 1285
1266 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1286 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1267 1287
1268 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) 1288 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM)
1269 1289
1270 const_iv (ST_CHANGE_CLASS)
1271
1272 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1290 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1273 1291
1274 // random map generator 1292 // random map generator
1275 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) 1293 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL)
1276 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) 1294 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL)
1279 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) 1297 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE)
1280 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) 1298 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS)
1281 1299
1282 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1300 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1283 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1301 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1302
1303 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1304 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1305 const_iv (GT_MINIMAL)
1284 }; 1306 };
1285 1307
1286 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1308 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1287 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1309 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1288 1310
1388 CODE: 1410 CODE:
1389 runtime = SvNVx (sv_runtime); 1411 runtime = SvNVx (sv_runtime);
1390 server_tick (); 1412 server_tick ();
1391 1413
1392void 1414void
1415log_backtrace (utf8_string msg)
1416
1417void
1393LOG (int level, utf8_string msg) 1418LOG (int flags, utf8_string msg)
1394 PROTOTYPE: $$ 1419 PROTOTYPE: $$
1395 C_ARGS: (LogLevel)level, "%s", msg 1420 C_ARGS: flags, "%s", msg
1396 1421
1397octet_string path_combine (octet_string base, octet_string path) 1422octet_string path_combine (octet_string base, octet_string path)
1398 PROTOTYPE: $$ 1423 PROTOTYPE: $$
1399 1424
1400octet_string path_combine_and_normalize (octet_string base, octet_string path) 1425octet_string path_combine_and_normalize (octet_string base, octet_string path)
1437 } 1462 }
1438 OUTPUT: RETVAL 1463 OUTPUT: RETVAL
1439 1464
1440void abort () 1465void abort ()
1441 1466
1467void reset_signals ()
1468
1442void fork_abort (octet_string cause = "cf::fork_abort") 1469void fork_abort (octet_string cause = "cf::fork_abort")
1443 1470
1444void cleanup (octet_string cause, bool make_core = false) 1471void cleanup (octet_string cause, bool make_core = false)
1445 1472
1446void emergency_save () 1473void emergency_save ()
1972 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 1999 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1973 { 2000 {
1974 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2001 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1975 ob->flag [FLAG_NO_MAP_SAVE] = true; 2002 ob->flag [FLAG_NO_MAP_SAVE] = true;
1976 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2003 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2004
2005 if (ob->randomitems)
2006 {
2007 ob->create_treasure (ob->randomitems);
2008 ob->randomitems = 0;
2009 }
1977 } 2010 }
1978 } 2011 }
1979 } 2012 }
1980 2013
1981 skip_space: ; 2014 skip_space: ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines