File Coverage

Devel.xs
Criterion Covered Total %
statement 15 21 71.4
branch 2 4 50.0
condition n/a
subroutine n/a
pod n/a
total 17 25 68.0


line stmt bran cond sub pod time code
1             /* $Id: Devel.xs 20 2011-10-11 02:05:01Z jo $
2             *
3             * This is free software, you may use it and distribute it under the same terms as
4             * Perl itself.
5             *
6             * Copyright 2011 Joachim Zobel
7             *
8             * This module gives external access to the functions needed to create
9             * and use XML::LibXML::Nodes from C functions. These functions are made
10             * accessible from Perl to have cleaner dependencies.
11             * The idea is to pass xmlNode * pointers (as typemapped void *) to and
12             * from Perl and call the functions that turns them to and from
13             * XML::LibXML::Nodes there.
14             *
15             * Be aware that using this module gives you the ability to easily create
16             * segfaults and memory leaks.
17             */
18              
19             #include "EXTERN.h"
20             #include "perl.h"
21             #include "XSUB.h"
22              
23             #include "ppport.h"
24              
25             #include
26              
27             /* XML::LibXML stuff */
28             #include
29             #include "perl-libxml-mm.h"
30              
31             #undef NDEBUG
32             #include
33              
34 115           static void * xmlMemMallocAtomic(size_t size)
35             {
36 115           return xmlMallocAtomicLoc(size, "none", 0);
37             }
38              
39 1           static int debug_memory()
40             {
41 1           return xmlGcMemSetup( xmlMemFree,
42             xmlMemMalloc,
43             xmlMemMallocAtomic,
44             xmlMemRealloc,
45             xmlMemStrdup);
46             }
47              
48             MODULE = XML::LibXML::Devel PACKAGE = XML::LibXML::Devel
49              
50             PROTOTYPES: DISABLE
51              
52             BOOT:
53 66 100         if (getenv("DEBUG_MEMORY")) {
54 1           debug_memory();
55             }
56              
57              
58              
59             SV*
60             node_to_perl( n, o = NULL )
61             void * n
62             void * o
63             PREINIT:
64 0           xmlNode *node = n;
65 0           xmlNode *owner = o;
66             CODE:
67 0 0         RETVAL = PmmNodeToSv(node , owner?owner->_private:NULL );
68             OUTPUT:
69             RETVAL
70              
71             void *
72             node_from_perl( sv )
73             SV *sv
74             PREINIT:
75 6           xmlNode *n = PmmSvNodeExt(sv, 0);
76             CODE:
77 6           RETVAL = n;
78             OUTPUT:
79             RETVAL
80              
81             void
82             refcnt_inc( n )
83             void *n
84             PREINIT:
85 4           xmlNode *node = n;
86             CODE:
87 4           PmmREFCNT_inc(((ProxyNode *)(node->_private)));
88              
89             int
90             refcnt_dec( n )
91             void *n
92             PREINIT:
93 4           xmlNode *node = n;
94             CODE:
95 4           RETVAL = PmmREFCNT_dec(((ProxyNode *)(node->_private)));
96             OUTPUT:
97             RETVAL
98              
99             int
100             refcnt( n )
101             void *n
102             PREINIT:
103 8           xmlNode *node = n;
104             CODE:
105 8           RETVAL = PmmREFCNT(((ProxyNode *)(node->_private)));
106             OUTPUT:
107             RETVAL
108              
109             int
110             fix_owner( n, p )
111             void * n
112             void * p
113             PREINIT:
114 0           xmlNode *node = n;
115 0           xmlNode *parent = p;
116             CODE:
117 0           RETVAL = PmmFixOwner(node->_private , parent->_private);
118             OUTPUT:
119             RETVAL
120              
121             int
122             mem_used()
123             CODE:
124 9           RETVAL = xmlMemUsed();
125             OUTPUT:
126             RETVAL
127              
128