Skip to content

Commit 5514d03

Browse files
committed
Revert r1862435, r1862071 per veto from ivan
msgid: <CABw-3YcK0qbeYWDOwE684XtBj3rCT2CuVOBWWqda4gMtRyRJEw@mail.gmail.com> git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1866019 13f79535-47bb-0310-9956-ffa450edef68
1 parent c715603 commit 5514d03

File tree

6 files changed

+11
-127
lines changed

6 files changed

+11
-127
lines changed

CHANGES

-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ Changes for APR 2.0.0
55

66
*) apr_thread_exit() is now a void function. [Joe Orton]
77

8-
*) apr_dir_read(): The returned finfo->name field is now duplicated
9-
into the pool for all implementations. [Joe Orton]
10-
11-
*) apr_dir_pread(): Add function which restricts per-read memory
12-
consumption to a different pool to the apr_dir_t object.
13-
[Joe Orton]
14-
158
*) apr_crypto_openssl: Remove unused link to the ssl library.
169
[Graham Leggett]
1710

file_io/os2/dir.c

+5-9
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,24 @@ APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *thedir)
7979
return APR_FROM_OS_ERROR(rv);
8080
}
8181

82+
83+
8284
APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
8385
apr_dir_t *thedir)
84-
{
85-
return apr_dir_pread(finfo, wanted, thedir, thedir->pool);
86-
}
87-
88-
APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
89-
apr_dir_t *thedir, apr_pool_t *pool)
9086
{
9187
int rv;
9288
ULONG entries = 1;
9389

9490
if (thedir->handle == 0) {
9591
thedir->handle = HDIR_CREATE;
96-
rv = DosFindFirst(apr_pstrcat(pool, thedir->dirname, "/*", NULL), &thedir->handle,
92+
rv = DosFindFirst(apr_pstrcat(thedir->pool, thedir->dirname, "/*", NULL), &thedir->handle,
9793
FILE_ARCHIVED|FILE_DIRECTORY|FILE_SYSTEM|FILE_HIDDEN|FILE_READONLY,
9894
&thedir->entry, sizeof(thedir->entry), &entries, FIL_STANDARD);
9995
} else {
10096
rv = DosFindNext(thedir->handle, &thedir->entry, sizeof(thedir->entry), &entries);
10197
}
10298

103-
finfo->pool = pool;
99+
finfo->pool = thedir->pool;
104100
finfo->fname = NULL;
105101
finfo->valid = 0;
106102

@@ -122,7 +118,7 @@ APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
122118
apr_os2_time_to_apr_time(&finfo->ctime, thedir->entry.fdateCreation,
123119
thedir->entry.ftimeCreation);
124120

125-
finfo->name = apr_pstrdup(pool, thedir->entry.achName);
121+
finfo->name = thedir->entry.achName;
126122
finfo->valid = APR_FINFO_NAME | APR_FINFO_MTIME | APR_FINFO_ATIME |
127123
APR_FINFO_CTIME | APR_FINFO_TYPE | APR_FINFO_SIZE |
128124
APR_FINFO_CSIZE;

file_io/unix/dir.c

+3-9
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,6 @@ static apr_filetype_e filetype_from_dirent_type(int type)
141141

142142
apr_status_t apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
143143
apr_dir_t *thedir)
144-
{
145-
return apr_dir_pread(finfo, wanted, thedir, thedir->pool);
146-
}
147-
148-
apr_status_t apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
149-
apr_dir_t *thedir, apr_pool_t *pool)
150144
{
151145
apr_status_t ret = 0;
152146
#ifdef DIRENT_TYPE
@@ -257,7 +251,7 @@ apr_status_t apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
257251
apr_cpystrn(end, thedir->entry->d_name,
258252
sizeof fspec - (end - fspec));
259253

260-
ret = apr_stat(finfo, fspec, APR_FINFO_LINK | wanted, pool);
254+
ret = apr_stat(finfo, fspec, APR_FINFO_LINK | wanted, thedir->pool);
261255
/* We passed a stack name that will disappear */
262256
finfo->fname = NULL;
263257
}
@@ -269,7 +263,7 @@ apr_status_t apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
269263
/* We don't bail because we fail to stat, when we are only -required-
270264
* to readdir... but the result will be APR_INCOMPLETE
271265
*/
272-
finfo->pool = pool;
266+
finfo->pool = thedir->pool;
273267
finfo->valid = 0;
274268
#ifdef DIRENT_TYPE
275269
if (type != APR_UNKFILE) {
@@ -285,7 +279,7 @@ apr_status_t apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
285279
#endif
286280
}
287281

288-
finfo->name = apr_pstrdup(pool, thedir->entry->d_name);
282+
finfo->name = apr_pstrdup(thedir->pool, thedir->entry->d_name);
289283
finfo->valid |= APR_FINFO_NAME;
290284

291285
if (wanted)

file_io/win32/dir.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *dir)
9090

9191
APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
9292
apr_dir_t *thedir)
93-
{
94-
return apr_dir_pread(finfo, wanted, thedir, thedir->pool);
95-
}
96-
97-
APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
98-
apr_dir_t *thedir, apr_pool_t *pool)
9993
{
10094
apr_status_t rv;
10195
char *fname;
@@ -152,11 +146,11 @@ APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
152146
if ((rv = unicode_to_utf8_path(thedir->name, APR_FILE_MAX * 3 + 1,
153147
thedir->entry->cFileName)))
154148
return rv;
155-
fname = apr_pstrdup(pool, thedir->name);
149+
fname = thedir->name;
156150

157151
fillin_fileinfo(finfo, (WIN32_FILE_ATTRIBUTE_DATA *) thedir->entry,
158152
0, 1, fname, wanted);
159-
finfo->pool = pool;
153+
finfo->pool = thedir->pool;
160154

161155
finfo->valid |= APR_FINFO_NAME;
162156
finfo->name = fname;

include/apr_file_info.h

-28
Original file line numberDiff line numberDiff line change
@@ -257,44 +257,16 @@ APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *thedir);
257257
* @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
258258
values
259259
* @param thedir the directory descriptor returned from apr_dir_open
260-
*
261260
* @remark No ordering is guaranteed for the entries read.
262-
* @c finfo->pool is set to the pool used to create @a thedir,
263-
* and @c finfo->name is allocated from that pool.
264261
*
265262
* @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
266263
* not be filled in, and you need to check the @c finfo->valid bitmask
267264
* to verify that what you're looking for is there. When no more
268265
* entries are available, APR_ENOENT is returned.
269-
*
270-
* @warning Allocations will use the directory pool; use
271-
* apr_dir_pread() and a temporary pool to restrict memory
272-
* consumption for a large directory.
273266
*/
274267
APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
275268
apr_dir_t *thedir);
276269

277-
/**
278-
* Read the next entry from the specified directory.
279-
* @param finfo the file info structure and filled in by apr_dir_read
280-
* @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
281-
values
282-
* @param thedir the directory descriptor returned from apr_dir_open
283-
* @param pool the pool to use for allocations
284-
285-
* @remark No ordering is guaranteed for the entries read.
286-
* @remark @c finfo->pool is set to @a pool, and @c finfo->name is
287-
* allocated from that pool.
288-
*
289-
* @note If @c APR_INCOMPLETE is returned all the fields in @a finfo may
290-
* not be filled in, and you need to check the @c finfo->valid bitmask
291-
* to verify that what you're looking for is there. When no more
292-
* entries are available, APR_ENOENT is returned.
293-
*/
294-
APR_DECLARE(apr_status_t) apr_dir_pread(apr_finfo_t *finfo, apr_int32_t wanted,
295-
apr_dir_t *thedir, apr_pool_t *pool);
296-
297-
298270
/**
299271
* Rewind the directory to the first entry.
300272
* @param thedir the directory descriptor to rewind.

test/testdir.c

+1-66
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "apr_file_info.h"
2222
#include "apr_errno.h"
2323
#include "apr_general.h"
24-
#include "apr_strings.h"
2524
#include "apr_lib.h"
2625
#include "apr_thread_proc.h"
2726
#include "testutil.h"
@@ -431,66 +430,6 @@ static void test_readmore_info(abts_case* tc, void* data)
431430
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
432431
}
433432

434-
#if APR_POOL_DEBUG
435-
static void test_pread(abts_case *tc, void *data)
436-
{
437-
apr_dir_t *dir;
438-
apr_finfo_t finfo;
439-
apr_size_t before, after;
440-
apr_pool_t *subp;
441-
442-
APR_ASSERT_SUCCESS(tc, "apr_dir_open failed", apr_dir_open(&dir, "data", p));
443-
444-
apr_pool_create(&subp, p);
445-
446-
before = apr_pool_num_bytes(p, 0);
447-
448-
APR_ASSERT_SUCCESS(tc, "apr_dir_read failed",
449-
apr_dir_pread(&finfo, APR_FINFO_DIRENT, dir, subp));
450-
451-
after = apr_pool_num_bytes(p, 0);
452-
453-
ABTS_PTR_EQUAL(tc, finfo.pool, subp);
454-
455-
apr_pool_destroy(subp);
456-
457-
APR_ASSERT_SUCCESS(tc, "apr_dir_close failed", apr_dir_close(dir));
458-
459-
ABTS_INT_EQUAL(tc, before, after);
460-
461-
}
462-
#endif
463-
464-
/* Ensure that apr_dir_read() doesn't have side-effects, because
465-
* finfo->name points to a static buffer inside the apr_dir_t */
466-
static void test_read_side_effects(abts_case *tc, void *data)
467-
{
468-
apr_dir_t *dir;
469-
apr_finfo_t f1;
470-
apr_finfo_t f2;
471-
char name[APR_PATH_MAX], fname[APR_PATH_MAX];
472-
473-
APR_ASSERT_SUCCESS(tc, "apr_dir_open failed", apr_dir_open(&dir, "data", p));
474-
475-
APR_ASSERT_SUCCESS(tc, "apr_dir_read failed",
476-
apr_dir_read(&f1, APR_FINFO_DIRENT, dir));
477-
478-
if (f1.name)
479-
apr_cpystrn(name, f1.name, sizeof name);
480-
if (f1.fname)
481-
apr_cpystrn(fname, f1.fname, sizeof fname);
482-
483-
APR_ASSERT_SUCCESS(tc, "second apr_dir_read failed",
484-
apr_dir_read(&f2, APR_FINFO_DIRENT, dir));
485-
486-
if (f1.name)
487-
ABTS_STR_EQUAL(tc, name, f1.name);
488-
if (f1.fname)
489-
ABTS_STR_EQUAL(tc, fname, f1.fname);
490-
491-
APR_ASSERT_SUCCESS(tc, "apr_dir_close failed", apr_dir_close(dir));
492-
}
493-
494433
abts_suite *testdir(abts_suite *suite)
495434
{
496435
suite = ADD_SUITE(suite)
@@ -512,11 +451,7 @@ abts_suite *testdir(abts_suite *suite)
512451
abts_run_test(suite, test_closedir, NULL);
513452
abts_run_test(suite, test_uncleared_errno, NULL);
514453
abts_run_test(suite, test_readmore_info, NULL);
515-
#if APR_POOL_DEBUG
516-
abts_run_test(suite, test_pread, NULL);
517-
#endif
518-
abts_run_test(suite, test_read_side_effects, NULL);
519-
454+
520455
return suite;
521456
}
522457

0 commit comments

Comments
 (0)