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.68 by elmex, Sat Nov 18 23:16:19 2006 UTC vs.
Revision 1.69 by root, Fri Nov 24 09:44:14 2006 UTC

51 51
52static f_plug_api gethook = cfapi_get_hooks; 52static f_plug_api gethook = cfapi_get_hooks;
53static f_plug_api object_set_property = cfapi_object_set_property; 53static f_plug_api object_set_property = cfapi_object_set_property;
54static f_plug_api object_insert = cfapi_object_insert; 54static f_plug_api object_insert = cfapi_object_insert;
55 55
56static HV *obj_cache;
57static PerlInterpreter *perl; 56static PerlInterpreter *perl;
58 57
59static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 58static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map;
60 59
61////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 60//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 80
82 if (!obj->self) 81 if (!obj->self)
83 obj->self = newSVptr (obj, klass); 82 obj->self = newSVptr (obj, klass);
84 83
85 return newSVsv (obj->self); 84 return newSVsv (obj->self);
86}
87
88static void
89SVptr_cache_set (void *ptr, SV *sv)
90{
91 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0);
92}
93
94static SV *
95SVptr_cache_get (void *ptr)
96{
97 SV **he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0);
98
99 return he ? *he : 0;
100}
101
102static SV *
103newSVptr_cached (void *ptr, const char *klass)
104{
105 SV *sv;
106
107 if (!ptr)
108 return &PL_sv_undef;
109
110 sv = SVptr_cache_get (ptr);
111
112 if (!sv)
113 {
114 HV *hv = newHV ();
115 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
116 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
117
118 SVptr_cache_set (ptr, sv);
119 }
120
121 return newSVsv (sv);
122} 85}
123 86
124static void 87static void
125clearSVptr (SV *sv) 88clearSVptr (SV *sv)
126{ 89{
182 145
183//TODO: 146//TODO:
184inline SV *to_sv (New_Face * v) { return to_sv (v->name); } 147inline SV *to_sv (New_Face * v) { return to_sv (v->name); }
185inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 148inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
186 149
187inline SV *to_sv (UUID v) { 150inline SV *to_sv (UUID v)
151{
188 char buf[128]; 152 char buf[128];
189 snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq + UUID_SKIP * 2); 153 snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq);
190 return newSVpv (buf, 0); 154 return newSVpv (buf, 0);
191} 155}
192 156
193inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 157inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
194inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed 158inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed
220inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 184inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
221 185
222template<int N> 186template<int N>
223inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 187inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
224 188
225inline void sv_to (SV *sv, UUID &v) { 189inline void sv_to (SV *sv, UUID &v)
226 char *sv_str = SvOK (sv) ? SvPV_nolen (sv) : 0; 190{
227 unsigned int version = 0; 191 unsigned int version;
228 unsigned long long seq = 0; 192 unsigned long long seq;
229 193
230 if (!sv_str)
231 return;
232
233 if (2 == sscanf (sv_str, "<%d.%llx>", &version, &seq) && version == 1) 194 if (2 != sscanf (SvPV_nolen (sv), "<%d.%llx>", &version, &seq) || 1 != version)
234 { 195 croak ("unparsable uuid: %s", SvPV_nolen (sv));
196
235 v.seq = seq; 197 v.seq = seq;
236 }
237
238 return;
239} 198}
240 199
241static SV * 200static SV *
242newSVdt_va (va_list &ap, data_type type) 201newSVdt_va (va_list &ap, data_type type)
243{ 202{
922 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 881 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
923 { 882 {
924 printf ("unable to initialize perl-interpreter, aborting.\n"); 883 printf ("unable to initialize perl-interpreter, aborting.\n");
925 exit (EXIT_FAILURE); 884 exit (EXIT_FAILURE);
926 } 885 }
927
928 obj_cache = newHV ();
929} 886}
930 887
931void cfperl_main () 888void cfperl_main ()
932{ 889{
933 dSP; 890 dSP;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines