-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boost filesystem directory_iterator problem on iOS? #50
Comments
I'm not sure off the top of my head, but I'll take a look when I get a chance. |
Any thoughts on this, or should i submit to the main boost group? |
Well, unfortunately I don't have an answer for you. I tried several different ways of accessing the directory with boost::filesystem and nothing worked. I'm seeing the same thing you are regarding inlines: I get warnings with the default settings, and a EXC_BAD_ACCESS when freeing the iterator if I build boost with What is interesting to me is that the filesystem iterator loop does execute once, printing If I run this:
I get :
I tried running this exact same code in a macOS CLI app and it works just fine. So boost::filesystem obviously works - there just appears to be a problem with At this point, if you really need to use Out of curiosity, why can't you just read files from the users documents directory using normal iOS functions? |
Thank you very much for fully checking it out; always nice to know I’m not crazy. Any suggestion where the best place to submit to the larger project would be? We’re using this code in a pure c++ model that is shared between Android and iOS. I was cleaning up a bunch of compiler warnings when I came across this issue. It’s not a particularly critical piece of code, so I might just restructure. For now, I just ignore the loader warnings, and it seems to work great. Thanks again, and thanks for the installer. It’s been a huge timesaver in using boost. |
It's been quite a while since I communicated with the Boost guys, so I don't recall exactly what the best line of communication is. They have this community page with links to their mailing list & IRC channels. I'm pretty sure I used IRC last time, but my question was more easily answered than I think this will be. Still, I'd try there first. We do have some bits in our shared library that I've had to explicitly re-write in mobile platform compatible ways (various filesystem stuff, cryptography, etc). We typically abstract the interface away & then I'll just supply my platform specific implementation. If it's just a small piece of code, I might add an |
Of note: I switched from using |
I’ll give that a try. Thanks again! |
Just for your interest, I did some further debugging. Had to switch optimization off to single-step through the boost code (after recompiling, I admit I was somewhat surprised that it still fails). Setting a breakpoint when it enters the loop.
p itr
p itr.m_imp.px->dir_entry.m_path
but then a call to path (which should simply returns m_path) fails, both from lldb and the program... the source of f.dereference is just
BUT if you print p f
p &(f.dereference()) bad one
p &(f.m_imp.px->dir_entry) correct one
I note that the addresses of both of these directory entries are very similar, but I have no idea where the bad path one comes from; it looks like general garbage. In particular, that's not the "end of directory" entry that we had just created as that has a null px pointer. And that's about as far as I can take it. It looks like a function |
Wow. I did a little digging too, but I didn't get quite this far. That's very interesting. I'm sure it's probably something like "you need to pass this flag when building for iOS (or maybe ARM?)". The Boost guys are a different kind of C++ magician. I've looked through the source many times and it's still very mysterious to me. Sometimes I can see what's going on, but most of the time I just wind up with "I have no idea why or how this works, but it does... Let's leave it at that. Maybe I'll understand this some day." If you do wind up opening a discussion with them about this & get it figured out, please let me know! If it's some build setting we can change in the script it would be awesome to fix it. |
FYI: boostorg/filesystem#147 |
So, you can see in the filesystem issue, they gave me a clue that enabled me track it down to a mutex pointer problem due to the use of pthreads. You can see the discussion at the bottom there, but one theory is that one should use BOOST_SP_USE_SPINLOCK instead. mutex v atomic counter v spinlocks in ARM multi-processor environments is now officially above my paygrade, but I thought I should let you know that maybe EXTRA_ARM_FLAGS should change (or maybe not). |
Just a bump here that the pThreads used in EXTRA_ARM_FLAGS is incompatible with iOS; one symptom as documented above is that the filesystem directory_iterator fails. EXTRA_ARM_FLAGS should be: |
I confirm that this solution works. Thanks @mackworth ! |
. @kambala-decapitator: Ah. I was just coming back to let you know my sample project worked fine with your code (Unfortunately, Github sends the original comment as an email and not the edits.). Glad to see it worked for you after all! |
sorry for the noise :) I simply forgot to change path to the built libs while testing the solution. |
Just wanted to comment that this crash also happens when building macOS silicon (not just iOS) since it includes $EXTRA_ARM_FLAGS as well. |
@mbendiksen Were you able to make it work with this updated one: https://github.com/mackworth/Apple-Boost-BuildScript ? |
Yes, your new proposed $EXTRA_ARM_FLAGS seem to work well. |
I'm a beginner of c/c++ and ios. @mbendiksen where add the $EXTRA_ARM_FLAGS flag? @mackworth where add the EXTRA_ARM_FLAGS="-DBOOST_SP_USE_SPINLOCK -g -DNDEBUG" ? |
@kambala-decapitator Thanks so much. I think that commits too complicated for me, so I use the pr's branch to build, my real device works well but there is no a ios simulator floder. what can i do? I wondering why the cool pr not be merged? |
@parcool I can't say why simulator wasn't built without seeing the command you used. Please also tell which Xcode version you use. PRs aren't merged because the repo seems abandoned. btw you can also use my branch where I have some other fixes applied, if it fits you: https://github.com/kambala-decapitator/Apple-Boost-BuildScript/tree/all-improvements-from-PRs |
@kambala-decapitator hello good man. I have tried your link post there and It get some error in the log file. I just use the command |
@parcool sorry, I haven't tried with Xcode 14 yet (only with 13), maybe there're new issues with it. by default Boost is built for all available platforms, maybe that's where the error is coming from. You can pass e.g. |
Hi, I'm having a weird problem, and before I raise it to the boost folks, I was hoping I can get your "Boost on iOS" opinion, as I'm not a boost expert (barely c++ capable).
When I use the boost filesystem::directory_iterator in my iOS program, it just plain doesn't work.
I started by building the current boost library using your script:
directory_iterator wasn't working and sometimes crashed in the project I'm working on, so I created a new Xcode project (attached below) to narrow it down. All I did was:
I'm using current Xcode Version 11.4.1 (11E503a) on current MacOS: 10.15.4 (19E287) and current iOS: 13.4.1 (17E262).
Results: the
itr->path
exists; once for each file, but is always empty, giving error msg:"" does not exist
. I point out that the preceding Cocoa access to the same directory works fine. so the file(s) are there, and the app has rights to get to them. As discussed below, sometimes I also get a malloc crash indirectory.cpp > dir_itr_close
when the for-loop finishes.I did the same steps on a macOS version (both a command line version in main.mm and a sandboxed app version in applicationDidFinishLaunching; also attached for your interest). No changes to code at all, and both worked fine, either giving me a listing of my real Documents directory, or just showing the dummy file in the sandboxed Documents.
What triggered my investigation, was that I got two warning messages when compiling in my real project (these are the ones from the test project; I compressed the long names to $DerivedData). As discussed below, these only appear when I compile on the simulator with
Inline Methods Hidden: NO
So, with that clue... I tried changing Xcode's Hidden options. In the test project, if I set
Inline Methods Hidden
(matching the compilation), then I get no warnings, empty file names reported and then a malloc crash. If I turn it off, I get the warnings, empty file names, but no crash. TheSymbols Hidden by Default
option seems to have no effect in either case. I note that the warnings only appear when I'm compiling on the simulator, but the other results are the same.I then rebuilt the boost library removing the
--hidden-visibility
option. Absolutely no effect:Inline Methods hidden
still gives no warning, no names and malloc crash;Inline Methods hidden
off still gives warning, no names, and no malloc crash.So, any obvious things I've missed, or suggestions for other things to try before escalating to the boost group?
thx
/Hugh
TestBoost.zip
The text was updated successfully, but these errors were encountered: