… | |
… | |
11 | #include <EXTERN.h> |
11 | #include <EXTERN.h> |
12 | #include <perl.h> |
12 | #include <perl.h> |
13 | #include <XSUB.h> |
13 | #include <XSUB.h> |
14 | |
14 | |
15 | #include <EventAPI.h> |
15 | #include <EventAPI.h> |
|
|
16 | #include <CoroAPI.h> |
16 | |
17 | |
|
|
18 | #include "util.h" |
|
|
19 | #include "keyword.h" |
|
|
20 | #include "dynbuf.h" |
17 | #include "callback.h" |
21 | #include "callback.h" |
|
|
22 | |
|
|
23 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
18 | |
24 | |
19 | // optimisations/workaround for functions requiring my_perl in scope (anti-bloat) |
25 | // optimisations/workaround for functions requiring my_perl in scope (anti-bloat) |
20 | #undef localtime |
26 | #undef localtime |
21 | #undef srand48 |
27 | #undef srand48 |
22 | #undef drand48 |
28 | #undef drand48 |
… | |
… | |
28 | #undef strerror |
34 | #undef strerror |
29 | |
35 | |
30 | // same here, massive symbol spamming |
36 | // same here, massive symbol spamming |
31 | #undef do_open |
37 | #undef do_open |
32 | #undef do_close |
38 | #undef do_close |
|
|
39 | #undef ref |
33 | |
40 | |
34 | // perl bug #40256: perl does overwrite those with reentrant versions |
41 | // perl bug #40256: perl does overwrite those with reentrant versions |
35 | // but does not initialise their state structures. |
42 | // but does not initialise their state structures. |
36 | #undef random |
43 | #undef random |
37 | #undef crypt |
44 | #undef crypt |
38 | |
45 | |
|
|
46 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
47 | |
|
|
48 | // some macros to simplify perl in-calls |
|
|
49 | |
|
|
50 | #define CHECK_ERROR \ |
|
|
51 | if (SvTRUE (ERRSV)) \ |
|
|
52 | LOG (llevError, "runtime error in %s: %s\n", __func__, SvPVutf8_nolen (ERRSV)); |
|
|
53 | |
|
|
54 | #define CALL_BEGIN(args) dSP; ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, args) |
|
|
55 | #define CALL_ARG_SV(sv) PUSHs (sv_2mortal (sv)) // separate because no refcount inc |
|
|
56 | #define CALL_ARG(expr) PUSHs (sv_2mortal (to_sv (expr))) |
|
|
57 | #define CALL_CALL(name, flags) PUTBACK; int count = call_pv (name, (flags) | G_EVAL); SPAGAIN; |
|
|
58 | #define CALL_END CHECK_ERROR; FREETMPS; LEAVE |
|
|
59 | |
|
|
60 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
61 | |
39 | void cfperl_init (); |
62 | void cfperl_init (); |
40 | void cfperl_main (); |
63 | void cfperl_main (); |
|
|
64 | |
|
|
65 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
66 | |
|
|
67 | // virtual server time, excluding time jumps and lag |
|
|
68 | extern double runtime; |
41 | |
69 | |
42 | enum event_klass |
70 | enum event_klass |
43 | { |
71 | { |
44 | KLASS_NONE, |
72 | KLASS_NONE, |
45 | KLASS_GLOBAL, |
73 | KLASS_GLOBAL, |
… | |
… | |
89 | #define RESULT_INT(idx) RESULT(idx, INT) |
117 | #define RESULT_INT(idx) RESULT(idx, INT) |
90 | |
118 | |
91 | double cfperl_result_DOUBLE (int idx); |
119 | double cfperl_result_DOUBLE (int idx); |
92 | int cfperl_result_INT (int idx); |
120 | int cfperl_result_INT (int idx); |
93 | |
121 | |
|
|
122 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
123 | |
94 | struct attachable |
124 | struct attachable |
95 | { |
125 | { |
|
|
126 | static MGVTBL vtbl; |
|
|
127 | |
96 | static unordered_vector<attachable *> mortals; |
128 | static unordered_vector<attachable *> mortals; |
97 | static void check_mortals (); |
129 | static void check_mortals (); |
98 | |
130 | |
99 | enum { |
131 | enum { |
100 | F_DESTROYED = 0x01, |
132 | F_DESTROYED = 0x01, |
… | |
… | |
164 | { |
196 | { |
165 | void gather_callbacks (AV *&callbacks, event_type event) const; |
197 | void gather_callbacks (AV *&callbacks, event_type event) const; |
166 | }; |
198 | }; |
167 | |
199 | |
168 | extern struct global gbl_ev; |
200 | extern struct global gbl_ev; |
|
|
201 | |
|
|
202 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
169 | |
203 | |
170 | struct object_freezer : dynbuf |
204 | struct object_freezer : dynbuf |
171 | { |
205 | { |
172 | AV *av; |
206 | AV *av; |
173 | |
207 | |
… | |
… | |
303 | struct object_thawer |
337 | struct object_thawer |
304 | { |
338 | { |
305 | SV *text; // text part |
339 | SV *text; // text part |
306 | AV *av; // perl part |
340 | AV *av; // perl part |
307 | char *line; // current beginning of line |
341 | char *line; // current beginning of line |
308 | char *last_value; |
342 | char *last_keyword, *last_value; |
309 | |
343 | |
310 | operator bool () { return !!text; } |
344 | operator bool () { return !!text; } |
311 | |
345 | |
312 | object_thawer (const char *filename = 0); |
346 | object_thawer (const char *filename = 0); |
313 | object_thawer (const char *data, AV *perlav); |
347 | object_thawer (const char *data, AV *perlav); |
314 | ~object_thawer (); |
348 | ~object_thawer (); |
315 | |
349 | |
316 | void get (attachable *obj, int oid); |
350 | void get (attachable *obj, int oid); |
317 | |
351 | |
318 | keyword get_kv (); // also parse value for later use |
352 | keyword get_kv (); // also parse value for later use |
|
|
353 | void skip_kv (keyword kw); |
319 | |
354 | |
320 | const char *get_str () { return last_value; } // may be 0 |
355 | const char *get_str () { return last_value; } // may be 0 |
321 | |
356 | |
322 | void get (shstr &sh) const; |
357 | void get (shstr &sh) const; |
323 | void get_ornull (shstr &sh) const { sh = last_value; } |
358 | void get_ornull (shstr &sh) const { sh = last_value; } |
… | |
… | |
325 | |
360 | |
326 | sint32 get_sint32 () const; |
361 | sint32 get_sint32 () const; |
327 | sint64 get_sint64 () const; |
362 | sint64 get_sint64 () const; |
328 | double get_double () const; |
363 | double get_double () const; |
329 | |
364 | |
330 | void get (float &v) { v = get_double (); } |
365 | void get (float &v) { v = get_double (); } |
331 | void get (double &v) { v = get_double (); } |
366 | void get (double &v) { v = get_double (); } |
332 | |
367 | |
|
|
368 | void get (bool &i) { i = get_sint32 (); } |
333 | void get (sint8 &i) { i = get_sint32 (); } |
369 | void get (sint8 &i) { i = get_sint32 (); } |
334 | void get (uint8 &i) { i = get_sint32 (); } |
370 | void get (uint8 &i) { i = get_sint32 (); } |
335 | void get (sint16 &i) { i = get_sint32 (); } |
371 | void get (sint16 &i) { i = get_sint32 (); } |
336 | void get (uint16 &i) { i = get_sint32 (); } |
372 | void get (uint16 &i) { i = get_sint32 (); } |
337 | void get (sint32 &i) { i = get_sint32 (); } |
373 | void get (sint32 &i) { i = get_sint32 (); } |
… | |
… | |
340 | void get (sint64 &i) { i = get_sint64 (); } |
376 | void get (sint64 &i) { i = get_sint64 (); } |
341 | }; |
377 | }; |
342 | |
378 | |
343 | char *fgets (char *s, int n, object_thawer &thawer); |
379 | char *fgets (char *s, int n, object_thawer &thawer); |
344 | |
380 | |
|
|
381 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
382 | |
|
|
383 | struct coroapi { |
|
|
384 | static struct CoroAPI *GCoroAPI; |
|
|
385 | |
|
|
386 | static int nready () { return CORO_NREADY; } |
|
|
387 | static int cede () { return CORO_CEDE ; } |
|
|
388 | }; |
|
|
389 | |
345 | struct watcher_base |
390 | struct watcher_base |
346 | { |
391 | { |
347 | static struct EventAPI *GEventAPI; |
392 | static struct EventAPI *GEventAPI; |
348 | }; |
393 | }; |
349 | |
394 | |