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.196 by root, Fri Apr 27 02:23:07 2007 UTC vs.
Revision 1.204 by root, Mon Apr 30 04:25:30 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>
169 { 175 {
170 SvREFCNT_dec (cb); 176 SvREFCNT_dec (cb);
171 cb = 0; 177 cb = 0;
172 } 178 }
173 179
174 if (self)
175 sever_self ();
176
177 mortals.push_back (this); 180 mortals.push_back (this);
178} 181}
179 182
180void 183void
181attachable::destroy () 184attachable::destroy ()
183 if (destroyed ()) 186 if (destroyed ())
184 return; 187 return;
185 188
186 flags |= F_DESTROYED; 189 flags |= F_DESTROYED;
187 do_destroy (); 190 do_destroy ();
191 sever_self ();
188} 192}
189 193
190void 194void
191attachable::check_mortals () 195attachable::check_mortals ()
192{ 196{
197 if (i >= mortals.size ()) 201 if (i >= mortals.size ())
198 { 202 {
199 i = 0; 203 i = 0;
200 204
201 if (mortals.size () > 1000) 205 if (mortals.size () > 1000)
202 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 ());
203 207
204 break; 208 break;
205 } 209 }
206 210
207 attachable *obj = mortals [i]; 211 attachable *obj = mortals [i];
208 212
209 obj->refcnt_chk (); // unborrow from perl, if necessary 213#if 0
214 if (obj->self)//D make this an assert later
215 {
216 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
217 obj->sever_self ();
218 }
219#endif
210 220
211 if (obj->refcnt || obj->self) 221 if (obj->refcnt)
212 { 222 {
213 ++i; // further delay freeing 223 ++i; // further delay freeing
214 224
215 if (!(i & 0x3ff)) 225 if (!(i & 0x3ff))
216 break; 226 break;
217 } 227 }
218 else 228 else
219 { 229 {
220 mortals.erase (i); 230 mortals.erase (i);
231 obj->sever_self ();
221 delete obj; 232 delete obj;
222 } 233 }
223 } 234 }
224} 235}
225 236
393inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 404inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
394 405
395template<int N> 406template<int N>
396inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 407inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
397 408
398inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
399inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 409inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
400inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 410inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
401inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 411inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
402inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 412inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
403 413
606 perl_construct (perl); 616 perl_construct (perl);
607 617
608 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 618 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
609 619
610 const char *argv[] = { 620 const char *argv[] = {
611 "", 621 settings.argv [0],
612 "-e" 622 "-e"
613 "use Event; use Coro;" // required for bootstrap 623 "use Event; use Coro;" // required for bootstrap
614 "cf->bootstrap;" // required for datadir :*> 624 "cf->bootstrap;" // required for datadir :*>
615 "unshift @INC, cf::datadir ();" 625 "unshift @INC, cf::datadir ();"
616 "require cf;" 626 "require cf;"
938 CALL_ARG (exit); 948 CALL_ARG (exit);
939 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 949 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
940 CALL_END; 950 CALL_END;
941} 951}
942 952
953void
954log_backtrace (const char *msg)
955{
956#if HAVE_BACKTRACE
957 void *addr [20];
958 int size = backtrace (addr, 20);
959
960 CALL_BEGIN (size);
961 CALL_ARG (msg);
962 for (int i = 0; i < size; ++i)
963 CALL_ARG ((IV)addr [i]);
964 CALL_CALL ("cf::_log_backtrace", G_VOID);
965 CALL_END;
966#endif
967}
968
943///////////////////////////////////////////////////////////////////////////// 969/////////////////////////////////////////////////////////////////////////////
944 970
945struct EventAPI *watcher_base::GEventAPI; 971struct EventAPI *watcher_base::GEventAPI;
946struct CoroAPI *coroapi::GCoroAPI; 972struct CoroAPI *coroapi::GCoroAPI;
947 973
1101 const char *name; 1127 const char *name;
1102 IV iv; 1128 IV iv;
1103 } *civ, const_iv[] = { 1129 } *civ, const_iv[] = {
1104# define const_iv(name) { # name, (IV)name }, 1130# define const_iv(name) { # name, (IV)name },
1105 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1131 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1132 const_iv (logBacktrace)
1106 1133
1107 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1134 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1108 1135
1109 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1136 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1110 1137
1382 CODE: 1409 CODE:
1383 runtime = SvNVx (sv_runtime); 1410 runtime = SvNVx (sv_runtime);
1384 server_tick (); 1411 server_tick ();
1385 1412
1386void 1413void
1414log_backtrace (utf8_string msg)
1415
1416void
1387LOG (int level, utf8_string msg) 1417LOG (int flags, utf8_string msg)
1388 PROTOTYPE: $$ 1418 PROTOTYPE: $$
1389 C_ARGS: (LogLevel)level, "%s", msg 1419 C_ARGS: flags, "%s", msg
1390 1420
1391octet_string path_combine (octet_string base, octet_string path) 1421octet_string path_combine (octet_string base, octet_string path)
1392 PROTOTYPE: $$ 1422 PROTOTYPE: $$
1393 1423
1394octet_string path_combine_and_normalize (octet_string base, octet_string path) 1424octet_string path_combine_and_normalize (octet_string base, octet_string path)
1431 } 1461 }
1432 OUTPUT: RETVAL 1462 OUTPUT: RETVAL
1433 1463
1434void abort () 1464void abort ()
1435 1465
1466void reset_signals ()
1467
1436void fork_abort (octet_string cause = "cf::fork_abort") 1468void fork_abort (octet_string cause = "cf::fork_abort")
1437 1469
1438void cleanup (octet_string cause, bool make_core = false) 1470void cleanup (octet_string cause, bool make_core = false)
1439 1471
1440void emergency_save () 1472void emergency_save ()
1966 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 1998 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1967 { 1999 {
1968 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2000 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1969 ob->flag [FLAG_NO_MAP_SAVE] = true; 2001 ob->flag [FLAG_NO_MAP_SAVE] = true;
1970 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2002 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2003
2004 if (ob->randomitems)
2005 {
2006 if (!ob->above)
2007 {
2008 ob->create_treasure (ob->randomitems);
2009
2010 for (object *op = ob->above; op; op = op->above)
2011 op->flag [FLAG_NO_MAP_SAVE] = true;
2012 }
2013
2014 ob->randomitems = 0;
2015 }
1971 } 2016 }
1972 } 2017 }
1973 } 2018 }
1974 2019
1975 skip_space: ; 2020 skip_space: ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines