… | |
… | |
104 | } |
104 | } |
105 | #endif |
105 | #endif |
106 | |
106 | |
107 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
107 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
108 | |
108 | |
|
|
109 | bool object_thawer::errors_are_fatal = true; |
|
|
110 | |
109 | object_thawer::object_thawer (const char *path) |
111 | object_thawer::object_thawer (const char *data, AV *perlav) |
|
|
112 | : name (strdup ("(memory stream)")) |
|
|
113 | { |
|
|
114 | av = perlav; |
|
|
115 | text = newSVpv (data, 0); |
|
|
116 | sv_catpv (text, thawer_eof); |
|
|
117 | line = SvPVbyte_nolen (text); |
|
|
118 | next (); |
|
|
119 | } |
|
|
120 | |
|
|
121 | object_thawer::object_thawer (const_utf8_string path) |
|
|
122 | { |
|
|
123 | new_from_path (path); |
|
|
124 | } |
|
|
125 | |
|
|
126 | // convenience constructor |
|
|
127 | object_thawer::object_thawer (const_utf8_string dir, const_utf8_string file) |
|
|
128 | { |
|
|
129 | new_from_path (format ("%s/%s", dir, file)); |
|
|
130 | } |
|
|
131 | |
|
|
132 | void |
|
|
133 | object_thawer::new_from_path (const_utf8_string path) |
|
|
134 | { |
110 | : name (strdup (path)) |
135 | name = strdup (path); |
111 | { |
|
|
112 | av = 0; |
136 | av = 0; |
113 | text = 0; |
137 | text = 0; |
114 | line = 0; |
138 | line = 0; |
115 | linenum = 0; |
139 | linenum = 0; |
116 | |
140 | |
… | |
… | |
150 | |
174 | |
151 | CALL_END; |
175 | CALL_END; |
152 | } |
176 | } |
153 | } |
177 | } |
154 | |
178 | |
155 | object_thawer::object_thawer (const char *data, AV *perlav) |
|
|
156 | : name (strdup ("(memory stream)")) |
|
|
157 | { |
|
|
158 | av = perlav; |
|
|
159 | text = newSVpv (data, 0); |
|
|
160 | sv_catpv (text, thawer_eof); |
|
|
161 | line = SvPVbyte_nolen (text); |
|
|
162 | next (); |
|
|
163 | } |
|
|
164 | |
|
|
165 | void |
179 | void |
166 | object_thawer::get (attachable *obj, int oid) |
180 | object_thawer::get (attachable *obj, int oid) |
167 | { |
181 | { |
168 | if (!av || oid < 0) // this is actually an error of sorts |
182 | if (!av || oid < 0) // this is actually an error of sorts |
169 | return; |
183 | return; |
… | |
… | |
223 | resolve_delayed_derefs (false); |
237 | resolve_delayed_derefs (false); |
224 | |
238 | |
225 | free ((void *)name); |
239 | free ((void *)name); |
226 | } |
240 | } |
227 | |
241 | |
|
|
242 | static void |
|
|
243 | error_out () |
|
|
244 | { |
|
|
245 | if (object_thawer::errors_are_fatal) |
|
|
246 | { |
|
|
247 | LOG (llevError, "(parse errors at this time are fatal, exiting)"); |
|
|
248 | exit (1); |
|
|
249 | } |
|
|
250 | } |
|
|
251 | |
228 | void |
252 | void |
229 | object_thawer::parse_warn (const char *msg) |
253 | object_thawer::parse_warn (const char *msg) const |
230 | { |
254 | { |
231 | LOG (llevWarn, "%s:%d, \"%s %s\": %s\n", |
255 | LOG (llevWarn, "%s:%d, \"%s %s\": %s\n", |
232 | this->name, linenum, |
256 | this->name, linenum, |
233 | kw_str ? kw_str : "<null>", |
257 | kw_str ? kw_str : "<null>", |
234 | value ? value : "<null>", |
258 | value ? value : "<null>", |
235 | msg); |
259 | msg); |
236 | } |
260 | } |
237 | |
261 | |
238 | bool |
262 | bool |
239 | object_thawer::parse_error (const char *type, const char *name, bool skip) |
263 | object_thawer::parse_error (const char *type, const char *name, bool skip) const |
240 | { |
264 | { |
241 | if (!type) type = "file section"; |
265 | if (!type) type = "file section"; |
242 | if (!name) name = "generic"; |
266 | if (!name) name = "generic"; |
243 | |
267 | |
244 | switch (kw) |
268 | switch (kw) |
245 | { |
269 | { |
246 | case KW_EOF: |
270 | case KW_EOF: |
247 | LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n", |
271 | LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n", |
248 | this->name, linenum, type, name); |
272 | this->name, linenum, type, name); |
|
|
273 | error_out (); |
249 | return false; |
274 | return false; |
250 | |
275 | |
251 | case KW_ERROR: |
276 | case KW_ERROR: |
252 | LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n", |
277 | LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n", |
253 | this->name, linenum, |
278 | this->name, linenum, |
254 | type, name, |
279 | type, name, |
255 | kw_str ? kw_str : "<file load>"); |
280 | kw_str ? kw_str : "<file load>"); |
|
|
281 | error_out (); |
256 | return false; |
282 | return false; |
257 | |
283 | |
258 | default: |
284 | default: |
259 | LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n", |
285 | LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n", |
260 | this->name, linenum, |
286 | this->name, linenum, |
261 | kw_str ? kw_str : "<null>", |
287 | kw_str ? kw_str : "<null>", |
262 | value ? value : "<null>", |
288 | value ? value : "<null>", |
263 | type, name, |
289 | type, name, |
264 | skip ? "skipping line" : "aborting load"); |
290 | skip ? "skipping line" : "aborting load"); |
|
|
291 | error_out (); |
265 | return skip; |
292 | return skip; |
266 | } |
293 | } |
267 | } |
294 | } |
268 | |
295 | |
269 | void |
296 | void |