Review Request 129267: [OS X] emulate posix_fallocate()

Michael Pyne mpyne at kde.org
Thu Oct 27 01:55:26 UTC 2016


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/129267/#review100318
-----------------------------------------------------------


Fix it, then Ship it!




I'm fine with the proposal but would like for the proposed `posix_fallocate` reimplementation to be improved for portability and resiliency to errors.

If the issues are addressed please commit.


src/lib/caching/posix_fallocate_mac.h (line 91)
<https://git.reviewboard.kde.org/r/129267/#comment67339>

    This should be `__cplusplus` (if `cplusplus` works, it's a non-portable extension).
    
    Better yet, we could probably get rid of this linkage specifier entirely, since this function is used entirely within our C++ source anyways. But I'll leave that up to you to decide.



src/lib/caching/posix_fallocate_mac.h (line 97)
<https://git.reviewboard.kde.org/r/129267/#comment67337>

    Given that the user has some input into the size of the cache I'd prefer to have some kind of integer overflow check on offset + len (since off_t is a signed integer type, this addition is susceptible to undefined behavior). A potential overflow check is available at http://stackoverflow.com/a/1514309, and maybe Qt has something as well.



src/lib/caching/posix_fallocate_mac.h (line 100)
<https://git.reviewboard.kde.org/r/129267/#comment67341>

    I'd prefer the error check is consistent with the style used below at line 104, ideally `(-1 == ret)` or `(ret < 0)` at both locations.
    
    This will make it clear that both conditionals are intended to check for errors as opposed to other potential uses of the `fcntl()` output.



src/lib/caching/posix_fallocate_mac.h (line 108)
<https://git.reviewboard.kde.org/r/129267/#comment67338>

    Given that the ftruncate man page is documented as leaving the current file offset unchanged, why are we trying to read the old offset and reset it later? Does ftruncate fail on Mac OS X if the offset is set wrong?
    
    The reason I ask is that we don't check the return value of lseek() here and while it seems like it should be safe it's at least theoretically possible to have it return an error.



src/lib/caching/posix_fallocate_mac.h (line 115)
<https://git.reviewboard.kde.org/r/129267/#comment67340>

    Likewise, needs to be `__cplusplus`.


- Michael Pyne


On Oct. 26, 2016, 6:23 p.m., René J.V. Bertin wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/129267/
> -----------------------------------------------------------
> 
> (Updated Oct. 26, 2016, 6:23 p.m.)
> 
> 
> Review request for KDE Software on Mac OS X and KDE Frameworks.
> 
> 
> Repository: kcoreaddons
> 
> 
> Description
> -------
> 
> Mac OS X doesn't have `posix_fallocate()` but as written in the comments, this function can be emulated (at least for simple use with `offset=0`).
> 
> This patch introduces such an emulation, based on `mozilla::fallocation()`. There's so little of that function left that it may be overkill to maintain its original copyright statement but I'll leave that to the legalese experts.
> 
> 
> Diffs
> -----
> 
>   src/lib/caching/kshareddatacache_p.h 9fd0bb1 
>   src/lib/caching/posix_fallocate_mac.h PRE-CREATION 
> 
> Diff: https://git.reviewboard.kde.org/r/129267/diff/
> 
> 
> Testing
> -------
> 
> Works as intended on OS X 10.9.5 as far as I can tell; original file contents were not overwritten in my testing.
> 
> The autotest succeeds (with an additional debug statement left out of the patch):
> 
> ```
> > kf5-kcoreaddons/work/build/autotests/kshareddatacachetest 
> ********* Start testing of KSharedDataCacheTest *********
> Config: Using QtTest library 5.6.1, Qt 5.6.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 6.0 (clang-600.0.57) (Apple))
> PASS   : KSharedDataCacheTest::initTestCase()
> QWARN  : KSharedDataCacheTest::simpleInsert() void KSharedDataCache::Private::mapSharedMemory() posix_fallocated 5273696 bytes for file "/Users/bertin/.cache/myTestCache.kcache"
> PASS   : KSharedDataCacheTest::simpleInsert()
> PASS   : KSharedDataCacheTest::cleanupTestCase()
> Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted
> ********* Finished testing of KSharedDataCacheTest *********
> ```
> 
> 
> File Attachments
> ----------------
> 
> a simple commandline test app
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/10/26/e0af195f-b484-4647-b211-cc78b5b0584b__posix_fallocate.c
> 
> 
> Thanks,
> 
> René J.V. Bertin
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-mac/attachments/20161027/85518e6d/attachment-0001.html>


More information about the kde-mac mailing list