--- deliantra/server/include/cfperl.h 2009/11/11 23:27:57 1.112 +++ deliantra/server/include/cfperl.h 2010/04/15 03:34:30 1.121 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010 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 @@ -26,10 +26,6 @@ #ifndef CFPERL_H__ #define CFPERL_H__ -#include -#include -#include - using namespace std; #include @@ -87,11 +83,14 @@ inline int call_pvsv (const char *ob, I32 flags) { return call_pv (ob, flags); } inline int call_pvsv (SV *ob, I32 flags) { return call_sv (ob, flags); } -#define CALL_BEGIN(args) dSP; ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, args) +// TODO: temporarily enabled pushstack/popstack for all calls from the core, to maybe fix object memleak? +#define CALL_PUSH PUSHSTACKi (PERLSI_UNKNOWN) +#define CALL_POP PUTBACK; POPSTACK; SPAGAIN +#define CALL_BEGIN(args) dSP; CALL_PUSH; ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, args) #define CALL_ARG_SV(sv) PUSHs (sv_2mortal (sv)) // separate because no refcount inc #define CALL_ARG(expr) PUSHs (sv_2mortal (to_sv (expr))) #define CALL_CALL(name, flags) PUTBACK; int count = call_pvsv (name, (flags) | G_EVAL); SPAGAIN; -#define CALL_END PUTBACK; CHECK_ERROR; FREETMPS; LEAVE +#define CALL_END PUTBACK; CHECK_ERROR; FREETMPS; LEAVE; CALL_POP ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -101,15 +100,15 @@ void cfperl_emergency_save (); void cfperl_cleanup (int make_core); void cfperl_make_book (object *book, int level); -void cfperl_send_msg (client *ns, int color, const char *type, const char *msg); +void cfperl_send_msg (client *ns, int color, const_utf8_string type, const_utf8_string msg); int cfperl_can_merge (object *ob1, object *ob2); void cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator = 0); -bool is_match_expr (const char *expr); +bool is_match_expr (const_utf8_string expr); // applies the match expression and returns true if it matches -bool match (const char *expr, object *ob, object *self = 0, object *source = 0, object *originator = 0); +bool match (const_utf8_string expr, object *ob, object *self = 0, object *source = 0, object *originator = 0); // same as above, but returns the first object found, or 0 -object *match_one (const char *expr, object *ob, object *self = 0, object *source = 0, object *originator = 0); +object *match_one (const_utf8_string expr, object *ob, object *self = 0, object *source = 0, object *originator = 0); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -216,6 +215,9 @@ // return wether an object was destroyed already MTH bool destroyed () const { return attachable_flags & F_DESTROYED; } + // destruct and free the memory for this object + virtual void do_delete (); + virtual void gather_callbacks (AV *&callbacks, event_type event) const; #if 0 @@ -242,21 +244,21 @@ } // set a custom key to the given value, or delete it if value = 0 - void set_key (const char *key, const char *value = 0, bool is_utf8 = 0); + void set_key (const_utf8_string key, const_utf8_string value = 0, bool is_utf8 = 0); - void set_key_text (const char *key, const char *value = 0) + void set_key_text (const_utf8_string key, const_utf8_string value = 0) { set_key (key, value, 1); } - void set_key_data (const char *key, const char *value = 0) + void set_key_data (const_utf8_string key, const_utf8_string value = 0) { set_key (key, value, 0); } attachable &operator =(const attachable &src); - // used to _quickly_ device wether to shortcut the evaluation + // used to _quickly_ decide wether to shortcut the evaluation bool should_invoke (event_type event) { return ev_want_event [event] || cb; @@ -289,6 +291,8 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // a little dirty hack, maybe unify with something else at a later time +// it is used to communicate as much info about the keyword string +// to the consuemr as possible, for maximum performance. struct keyword_string { const char *s; @@ -344,7 +348,7 @@ alloc (p); } - void put (const keyword_string k, const char *v) + void put (const keyword_string k, const_utf8_string v) { if (expect_true (v)) put (k, keyword_string (v, strlen (v))); @@ -421,7 +425,7 @@ } MTH bool save (const_octet_string path); - char *as_string (); // like strdup + utf8_string as_string (); // like strdup operator bool () { return !!av; } }; @@ -441,8 +445,8 @@ operator bool () const { return !!text; } - object_thawer (const char *path = 0); - object_thawer (const char *data, AV *perlav); + object_thawer (const_utf8_string path = 0); + object_thawer (const_utf8_string data, AV *perlav); ~object_thawer (); void get (attachable *obj, int oid); @@ -454,7 +458,8 @@ MTH void skip (); MTH void skip_block (); // skips till and over KW_end - char *get_str () { return value; } // may be 0 + bool has_value () { return value; } + const_utf8_string get_str () { return value_nn; } // empty string when missing void get_ml (keyword kend, shstr &sh); void get_ornull (shstr &sh) const { sh = value; } @@ -478,17 +483,17 @@ void get (uint32 &i) { i = get_sint64 (); } void get (sint64 &i) { i = get_sint64 (); } - MTH void parse_warn (const char *msg); - MTH bool parse_error (const char *type = 0, const char *name = 0, bool skip = true); + MTH void parse_warn (const_utf8_string msg); + MTH bool parse_error (const_utf8_string type = 0, const_utf8_string name = 0, bool skip = true); struct delayed_ref { attachable *op; object_ptr *ptr; - const char *ref; + const_utf8_string ref; }; std::vector delrefs; - void delayed_deref (attachable *op, object_ptr &ptr, const char *ref); + void delayed_deref (attachable *op, object_ptr &ptr, const_utf8_string ref); MTH void resolve_delayed_derefs (bool deref = true); };