ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/XML-DB/DB.xs
(Generate patch)

Comparing XML-DB/DB.xs (file contents):
Revision 1.1 by root, Sun Apr 21 15:41:31 2002 UTC vs.
Revision 1.2 by root, Sun Apr 21 17:30:08 2002 UTC

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
17MODULE = DBIx::Tree PACKAGE = DBIx::Tree 21#define KEYLEN 8 // number of bytes in the l, m, r fields
18 22
23static SV *
24new_key (void)
25{
26 SV *new = NEWSV(0, KEYLEN);
27 SvPOK_only (new);
28 SvCUR_set (new, KEYLEN);
29
30 return new;
31}
32
33MODULE = XML::DB PACKAGE = XML::DB::Key
34
35PROTOTYPES: ENABLE
36
37int
38KEYLEN()
39 CODE:
40 RETVAL = KEYLEN;
41 OUTPUT:
42 RETVAL
43
44SV *
450()
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
55SV *
56m(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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines