Merge lp:~zorba-coders/zorba/bug-921458 into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Paul J. Lucas
Approved revision: 10755
Merged at revision: 10766
Proposed branch: lp:~zorba-coders/zorba/bug-921458
Merge into: lp:zorba
Diff against target: 291 lines (+222/-5)
7 files modified
ChangeLog (+1/-0)
modules/org/expath/ns/file.xq (+1/-5)
modules/org/expath/ns/file.xq.src/file.cpp (+118/-0)
modules/org/expath/ns/file.xq.src/file.h (+64/-0)
modules/org/expath/ns/file.xq.src/file_module.cpp (+2/-0)
test/rbkt/ExpQueryResults/zorba/file/file_read_text_lines.xml.res (+32/-0)
test/rbkt/Queries/zorba/file/file_read_text_lines.xq (+4/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug-921458
Reviewer Review Type Date Requested Status
Paul J. Lucas Approve
William Candillon Approve
Review via email: mp+102058@code.launchpad.net

This proposal supersedes a proposal from 2012-04-13.

Commit message

Fix for bug #921458 (file:read-text-lines() blocking)

Description of the change

Fix for bug #921458 (file:read-text-lines() blocking)

The problem was that the string:split function isn't suitable for tokenizing with newlines as separator.

I have provided a native implementation using C++'s getline.

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job bug-921458-2012-04-13T09-53-08.237Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 2 Pending.

Revision history for this message
William Candillon (wcandillon) wrote : Posted in a previous version of this proposal

Works great.

review: Approve
Revision history for this message
Paul J. Lucas (paul-lucas) wrote : Posted in a previous version of this proposal

Required: After your call to getline(), you should check the state of the stream again for badbit.

Optional: you ought to use std::unique_ptr for the stream member so you don't have to delete it explicitly.

Revision history for this message
Paul J. Lucas (paul-lucas) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
William Candillon (wcandillon) :
review: Approve
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-921458-2012-04-16T14-47-08.502Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2012-04-14 06:12:29 +0000
+++ ChangeLog 2012-04-16 07:12:21 +0000
@@ -21,6 +21,7 @@
21 * Fixed bug #872234 (prevent a rewritting to take place in case of sequential expr)21 * Fixed bug #872234 (prevent a rewritting to take place in case of sequential expr)
22 * Fixed bug #906494 (default compile with D_FILE_OFFSET_BITS=64)22 * Fixed bug #906494 (default compile with D_FILE_OFFSET_BITS=64)
23 * Fixed bug #912586, #912593 and #912722 (assertion failures with lax validation)23 * Fixed bug #912586, #912593 and #912722 (assertion failures with lax validation)
24 * Fixed bug #921458 (file:read-text-lines() blocking)
24 * Fixed bug #949910 (has-children may be invoked on all nodes). Internally, zorba::store::Item::getChildren() now returns NULL on node classes without offspring (instead of raising an error).25 * Fixed bug #949910 (has-children may be invoked on all nodes). Internally, zorba::store::Item::getChildren() now returns NULL on node classes without offspring (instead of raising an error).
2526
2627
2728
=== modified file 'modules/org/expath/ns/file.xq'
--- modules/org/expath/ns/file.xq 2012-04-14 01:36:33 +0000
+++ modules/org/expath/ns/file.xq 2012-04-16 07:12:21 +0000
@@ -422,11 +422,7 @@
422declare %an:nondeterministic function file:read-text-lines(422declare %an:nondeterministic function file:read-text-lines(
423 $file as xs:string,423 $file as xs:string,
424 $encoding as xs:string424 $encoding as xs:string
425) as xs:string*425) as xs:string* external;
426{
427 let $content := file:read-text($file, $encoding)
428 return fn:tokenize($content, "\n")
429};
430426
431(:~427(:~
432 : This is an internal function that copies an entire source directory to an428 : This is an internal function that copies an entire source directory to an
433429
=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
--- modules/org/expath/ns/file.xq.src/file.cpp 2012-03-30 19:03:09 +0000
+++ modules/org/expath/ns/file.xq.src/file.cpp 2012-04-16 07:12:21 +0000
@@ -223,6 +223,124 @@
223223
224//*****************************************************************************224//*****************************************************************************
225225
226ReadTextLinesFunction::ReadTextLinesFunction(const FileModule* aModule)
227 : FileFunction(aModule)
228{
229}
230
231ItemSequence_t
232ReadTextLinesFunction::evaluate(
233 const ExternalFunction::Arguments_t& aArgs,
234 const StaticContext* aSctxCtx,
235 const DynamicContext* aDynCtx) const
236{
237 String lFileStr = getFilePathString(aArgs, 0);
238 File_t lFile = File::createFile(lFileStr.c_str());
239 String lEncoding("UTF-8");
240
241 // preconditions
242 if (!lFile->exists()) {
243 raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
244 }
245 if (lFile->isDirectory()) {
246 raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
247 }
248
249 lEncoding = getEncodingArg(aArgs, 1);
250
251 return ItemSequence_t(new LinesItemSequence(lFile, lEncoding, this));
252}
253
254ReadTextLinesFunction::LinesItemSequence::LinesItemSequence(
255 const File_t& aFile,
256 const String& aEncoding,
257 const ReadTextLinesFunction* aFunc)
258 : theFile(aFile),
259 theEncoding(aEncoding),
260 theFunc(aFunc)
261{
262}
263
264Iterator_t
265ReadTextLinesFunction::LinesItemSequence::getIterator()
266{
267 return new ReadTextLinesFunction::LinesItemSequence::LinesIterator(
268 theFile, theEncoding, theFunc
269 );
270}
271
272ReadTextLinesFunction::LinesItemSequence::LinesIterator::LinesIterator(
273 const File_t& aFile,
274 const String& aEncoding,
275 const ReadTextLinesFunction* aFunc)
276 : theFile(aFile),
277 theEncoding(aEncoding),
278 theFunc(aFunc),
279 theStream(0)
280{
281}
282
283ReadTextLinesFunction::LinesItemSequence::LinesIterator::~LinesIterator()
284{
285 delete theStream;
286}
287
288void
289ReadTextLinesFunction::LinesItemSequence::LinesIterator::open()
290{
291 if ( transcode::is_necessary( theEncoding.c_str() ) )
292 {
293 try
294 {
295 theStream = new transcode::stream<std::ifstream>(theEncoding.c_str());
296 }
297 catch (std::invalid_argument const& e)
298 {
299 theFunc->raiseFileError("FOFL0006", "Unsupported encoding", theEncoding.c_str());
300 }
301 }
302 else
303 {
304 theStream = new std::ifstream();
305 }
306 theFile->openInputStream(*theStream, false, true);
307}
308
309bool
310ReadTextLinesFunction::LinesItemSequence::LinesIterator::next(Item& aRes)
311{
312 if (!theStream || !theStream->good())
313 return false;
314
315 std::string lStr;
316 getline(*theStream, lStr);
317
318 if (theStream->bad())
319 {
320 return false;
321 }
322 else
323 {
324 aRes = theFunc->theModule->getItemFactory()->createString(lStr);
325 return true;
326 }
327}
328
329void
330ReadTextLinesFunction::LinesItemSequence::LinesIterator::close()
331{
332 delete theStream;
333 theStream = 0;
334}
335
336bool
337ReadTextLinesFunction::LinesItemSequence::LinesIterator::isOpen() const
338{
339 return theStream != 0;
340}
341
342//*****************************************************************************
343
226ExistsFunction::ExistsFunction(const FileModule* aModule)344ExistsFunction::ExistsFunction(const FileModule* aModule)
227 : FileFunction(aModule)345 : FileFunction(aModule)
228{346{
229347
=== modified file 'modules/org/expath/ns/file.xq.src/file.h'
--- modules/org/expath/ns/file.xq.src/file.h 2012-03-30 19:03:09 +0000
+++ modules/org/expath/ns/file.xq.src/file.h 2012-04-16 07:12:21 +0000
@@ -316,6 +316,70 @@
316316
317//*****************************************************************************317//*****************************************************************************
318318
319 class ReadTextLinesFunction : public FileFunction
320 {
321 public:
322 ReadTextLinesFunction(const FileModule* aModule);
323
324 virtual String
325 getLocalName() const { return "read-text-lines"; }
326
327 virtual ItemSequence_t
328 evaluate(const ExternalFunction::Arguments_t& args,
329 const StaticContext* aSctxCtx,
330 const DynamicContext* aDynCtx) const;
331
332 protected:
333 class LinesItemSequence : public ItemSequence
334 {
335 protected:
336 File_t theFile;
337 String theEncoding;
338 const ReadTextLinesFunction* theFunc;
339
340 class LinesIterator : public Iterator
341 {
342 protected:
343 const File_t& theFile;
344 const String& theEncoding;
345 const ReadTextLinesFunction* theFunc;
346
347 std::ifstream* theStream;
348
349 public:
350 LinesIterator(
351 const File_t&,
352 const String&,
353 const ReadTextLinesFunction*);
354
355 virtual ~LinesIterator();
356
357 virtual void
358 open();
359
360 virtual bool
361 next(Item&);
362
363 virtual void
364 close();
365
366 virtual bool
367 isOpen() const;
368 };
369
370 public:
371 LinesItemSequence(
372 const File_t& aFile,
373 const String& aEncoding,
374 const ReadTextLinesFunction*);
375
376 Iterator_t
377 getIterator();
378 };
379 };
380
381//*****************************************************************************
382
319 class WriteTextFunction : public WriterFileFunction383 class WriteTextFunction : public WriterFileFunction
320 {384 {
321 public:385 public:
322386
=== modified file 'modules/org/expath/ns/file.xq.src/file_module.cpp'
--- modules/org/expath/ns/file.xq.src/file_module.cpp 2012-03-30 19:03:09 +0000
+++ modules/org/expath/ns/file.xq.src/file_module.cpp 2012-04-16 07:12:21 +0000
@@ -46,6 +46,8 @@
46 lFunc = new ReadBinaryFunction(this);46 lFunc = new ReadBinaryFunction(this);
47 } else if (aLocalname == "read-text") {47 } else if (aLocalname == "read-text") {
48 lFunc = new ReadTextFunction(this);48 lFunc = new ReadTextFunction(this);
49 } else if (aLocalname == "read-text-lines") {
50 lFunc = new ReadTextLinesFunction(this);
49 } else if (aLocalname == "exists") {51 } else if (aLocalname == "exists") {
50 lFunc = new ExistsFunction(this);52 lFunc = new ExistsFunction(this);
51 } else if (aLocalname == "is-directory") {53 } else if (aLocalname == "is-directory") {
5254
=== added file 'test/rbkt/ExpQueryResults/zorba/file/file_read_text_lines.xml.res'
--- test/rbkt/ExpQueryResults/zorba/file/file_read_text_lines.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/file/file_read_text_lines.xml.res 2012-04-16 07:12:21 +0000
@@ -0,0 +1,32 @@
1&lt;products&gt;
2 &lt;product&gt;
3 &lt;name&gt;broiler&lt;/name&gt;
4 &lt;category&gt;kitchen&lt;/category&gt;
5 &lt;price&gt;100&lt;/price&gt;
6 &lt;cost&gt;70&lt;/cost&gt;
7 &lt;/product&gt;
8 &lt;product&gt;
9 &lt;name&gt;toaster&lt;/name&gt;
10 &lt;category&gt;kitchen&lt;/category&gt;
11 &lt;price&gt;30&lt;/price&gt;
12 &lt;cost&gt;10&lt;/cost&gt;
13 &lt;/product&gt;
14 &lt;product&gt;
15 &lt;name&gt;blender&lt;/name&gt;
16 &lt;category&gt;kitchen&lt;/category&gt;
17 &lt;price&gt;50&lt;/price&gt;
18 &lt;cost&gt;25&lt;/cost&gt;
19 &lt;/product&gt;
20 &lt;product&gt;
21 &lt;name&gt;socks&lt;/name&gt;
22 &lt;category&gt;clothes&lt;/category&gt;
23 &lt;price&gt;10&lt;/price&gt;
24 &lt;cost&gt;2&lt;/cost&gt;
25 &lt;/product&gt;
26 &lt;product&gt;
27 &lt;name&gt;shirt&lt;/name&gt;
28 &lt;category&gt;clothes&lt;/category&gt;
29 &lt;price&gt;10&lt;/price&gt;
30 &lt;cost&gt;3&lt;/cost&gt;
31 &lt;/product&gt;
32&lt;/products&gt;
033
=== added file 'test/rbkt/Queries/zorba/file/file_read_text_lines.xq'
--- test/rbkt/Queries/zorba/file/file_read_text_lines.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/file/file_read_text_lines.xq 2012-04-16 07:12:21 +0000
@@ -0,0 +1,4 @@
1import module namespace file = "http://expath.org/ns/file";
2
3string-join(file:read-text-lines(fn:resolve-uri("mydata.xml")), '
4')

Subscribers

People subscribed via source and target branches