/
phpresource.pmc
174 lines (106 loc) · 2.14 KB
/
phpresource.pmc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
Copyright (C) 2008, The Perl Foundation.
=head1 NAME
src/pmc/phpresource.pmc - PHP Resource
=head1 DESCRIPTION
=head2 Methods
=over 4
=cut
*/
#include "pipp_private.h"
pmclass PhpResource
provides ref
dynpmc
group pipp_group
hll PHP {
ATTR PMC *pointee; /* the resource that is handled by the PhpResource PMC */
/*
=item C<void init()>
Raises an exception. Use C<init_pmc()>.
=cut
*/
VTABLE void init() {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"PhpResource init without pmc");
}
/*
=item C<void init_pmc(PMC *initializer)>
Sets the referenced PMC to C<initializer>.
=cut
*/
VTABLE void init_pmc(PMC *initializer) {
Parrot_PhpResource_attributes *attrs =
mem_allocate_zeroed_typed(Parrot_PhpResource_attributes);
PMC_data(SELF) = attrs;
PARROT_PHPRESOURCE(SELF)->pointee = initializer;
PObj_custom_mark_destroy_SETALL(SELF);
}
/*
=item C<void destroy()>
Destroys the PMC.
=cut
*/
VTABLE void destroy() {
mem_sys_free(PMC_data(SELF));
}
/*
=item C<PMC *get_pmc()>
Get the referenced PMC.
=cut
*/
VTABLE PMC *get_pmc() {
return PARROT_PHPRESOURCE(SELF)->pointee;
}
/*
=item C<void mark()>
Marks the referenced PMC as live.
=cut
*/
VTABLE void mark() {
Parrot_gc_mark_PObj_alive(INTERP, (PObj *) PARROT_PHPRESOURCE(SELF)->pointee);
}
/*
=item C<STRING* name()>
Return the string 'resource'.
=cut
*/
STRING* name() {
return Parrot_str_new_constant(INTERP, "resource");
}
/*
=item C<STRING *get_string()>
Returns a string representation of the resource.
=cut
*/
VTABLE STRING *get_string() {
return Parrot_sprintf_c(INTERP, "Resource id #%08X", SELF);
}
/*
=back
=head2 non-Vtable Methods
=over 4
=item C<PMC* to_number()>
=cut
*/
METHOD PMC* to_number() {
RETURN(PMC *SELF);
}
/*
=back
=head2 Specific Methods
=over 4
=cut
*/
}
/*
=back
=head1 AUTHORS
Francois Perrad.
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/