1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
|
|
4 | |
|
|
5 | #include <string.h> |
|
|
6 | |
|
|
7 | // a compiler supporting C99 is required |
4 | |
8 | |
5 | /* try to be compatible with older perls */ |
9 | /* try to be compatible with older perls */ |
6 | /* SvPV_nolen() macro first defined in 5.005_55 */ |
10 | /* SvPV_nolen() macro first defined in 5.005_55 */ |
7 | /* this is slow, not threadsafe, but works */ |
11 | /* this is slow, not threadsafe, but works */ |
8 | #include "patchlevel.h" |
12 | #include "patchlevel.h" |
… | |
… | |
12 | #endif |
16 | #endif |
13 | #if PATCHLEVEL < 6 |
17 | #if PATCHLEVEL < 6 |
14 | # define call_sv perl_call_sv |
18 | # define call_sv perl_call_sv |
15 | #endif |
19 | #endif |
16 | |
20 | |
17 | MODULE = DBIx::Tree PACKAGE = DBIx::Tree |
21 | #define KEYLEN 8 // number of bytes in the l, m, r fields |
18 | |
22 | |
|
|
23 | static SV * |
|
|
24 | new_key (void) |
|
|
25 | { |
|
|
26 | SV *new = NEWSV(0, KEYLEN); |
|
|
27 | SvPOK_only (new); |
|
|
28 | SvCUR_set (new, KEYLEN); |
|
|
29 | |
|
|
30 | return new; |
|
|
31 | } |
|
|
32 | |
|
|
33 | MODULE = XML::DB PACKAGE = XML::DB::Key |
|
|
34 | |
|
|
35 | PROTOTYPES: ENABLE |
|
|
36 | |
|
|
37 | int |
|
|
38 | KEYLEN() |
|
|
39 | CODE: |
|
|
40 | RETVAL = KEYLEN; |
|
|
41 | OUTPUT: |
|
|
42 | RETVAL |
|
|
43 | |
|
|
44 | SV * |
|
|
45 | 0() |
|
|
46 | ALIAS: |
|
|
47 | 1 = 255 |
|
|
48 | CODE: |
|
|
49 | RETVAL = new_key (); |
|
|
50 | memset (SvPVX (RETVAL), ix, KEYLEN); |
|
|
51 | OUTPUT: |
|
|
52 | RETVAL |
|
|
53 | |
|
|
54 | # calculcate l + r |
|
|
55 | SV * |
|
|
56 | m(ls,rs) |
|
|
57 | SV * ls |
|
|
58 | SV * rs |
|
|
59 | CODE: |
|
|
60 | unsigned char *l, *m, *r, *me; |
|
|
61 | unsigned int mx, carry; |
|
|
62 | |
|
|
63 | RETVAL = new_key (); |
|
|
64 | |
|
|
65 | l = SvPVX (ls ) + KEYLEN; |
|
|
66 | r = SvPVX (rs ) + KEYLEN; |
|
|
67 | m = (me = SvPVX (RETVAL)) + KEYLEN; |
|
|
68 | |
|
|
69 | me [0] = 'U'; |
|
|
70 | me [1] = 'U'; |
|
|
71 | |
|
|
72 | mx = (unsigned int)*--l + (unsigned int)*--r + 1; *--m = (mx & 0x0ff) >> 1; |
|
|
73 | carry = mx & 0x100; |
|
|
74 | |
|
|
75 | do |
|
|
76 | { |
|
|
77 | mx = (unsigned int)*--l + (unsigned int)*--r + (carry >> 8); *--m = (mx & 0x0ff) >> 1; |
|
|
78 | |
|
|
79 | m[1] |= (mx & 0x001) << 7; |
|
|
80 | carry = (mx & 0x100); |
|
|
81 | } |
|
|
82 | while (me < m); |
|
|
83 | |
|
|
84 | m[0] |= carry >> 1; |
|
|
85 | |
|
|
86 | OUTPUT: |
|
|
87 | RETVAL |
|
|
88 | |
|
|
89 | |