Sublime Forum

Clang (C/C++/Objective-C/Objective-C++) autocomplete

#85

Iā€™ve found a problem that if in my sublimeclang_options I include a directory with a large number of files (1249 to be exact), sublime crashes with the following error:

https://dl.dropbox.com/u/427616/crash.png

I happen to have VS10 installed, and this is the assertion in question:

_Myiter& operator++()
		{	// preincrement
 #if _ITERATOR_DEBUG_LEVEL == 2
		if (this->_Getcont() == 0
			|| this->_Ptr == 0
			|| ((_Myvec *)this->_Getcont())->_Mylast <= this->_Ptr)
			{	// report error
			_DEBUG_ERROR("vector iterator not incrementable");
			_SCL_SECURE_OUT_OF_RANGE;
			}

The Sublime console shows the following after the crash:

Exception AttributeError: "Cache instance has no attribute 'cache'" in <bound method Cache.__del__ of <translationunitcache.Cache instance at 0x000000000552F808>> ignored
Traceback (most recent call last):
  File ".\common.py", line 173, in worker
  File ".\translationunitcache.py", line 723, in task_reparse
  File ".\translationunitcache.py", line 849, in get_translation_unit
  File ".\translationunitcache.py", line 640, in __init__
  File ".\translationunitcache.py", line 108, in __init__
WindowsError: [Error -2147483645] One or more arguments are invalid

Sublime itself doesnā€™t crash until I click ā€˜abortā€™, so Iā€™m actually guessing the assertion is actually in libclang.dll.
This is with ST 2181 (Windows obviously).

Thanks.

0 Likes

#86

Iā€™ve opened up a new issue on github for this. Is your code base shareable so that I can get a copy of what you are seeing? If not, do you have a small test where this reproduces? Otherwise itā€™s unlikely to be fixed from my side as I donā€™t code on Windows and itā€™s not something Iā€™ve seen from my limited testing on Windows.

0 Likes

#87

Thanks. Iā€™m not able to share the codebase Iā€™m working on, but Iā€™ll try to reproduce the problem with test code. Barring that, I can help debug it a bit for you if you have some things youā€™d like me to try.

0 Likes

#88

I had a quick play with this yesterday on windows and was getting lockups

I seem to recall reading that clang hardcodes visual studio/mingw paths?

Does anyone know if itā€™s possible to steer it towards sources on a linux vm?

0 Likes

#89

castles_made_of_sand, if your lockups are the same as RyanJā€™s then maybe it has been fixed now. You could disable all the standard includes via ā€œ-nostdincā€. As long as the vm sources are available as a windows file path you should be able to steer it that way.

RyanJ, I think your issue has been fixed. As issue 74 hasnā€™t been fixed yet, could you use package control to remove SublimeClang, quit Sublime Text 2, delete the SublimeClang package folder and then re-install it via Package Control and see if the issue is gone now please?

0 Likes

#90

Awesome :smile: Thanks. Iā€™ll give it a crack.

0 Likes

#91

So, I just got a lockup, the console was open and there was a traceback:

[code]Traceback (most recent call last):

File ".\sublimeclang.py", line 553, in recompile
File ".\translationunitcache.py", line 776, in reparse
File ".\translationunitcache.py", line ???, in get_opts_script
File ".\common.py", line 82, in expand_path

TypeError: unsupported operand type(s) for %: ā€˜NoneTypeā€™ and ā€˜dictā€™
[/code]

(FFFF I just typed that in by hand and seem to have fucked up one of the line numbers :smile:)

Dunno how itā€™s related to the lockup, but that 's the last bit info in the console.

0 Likes

#92

From a superficial look, not really understanding the why/what/how of the locking , I can see a lack of try/finally with some uses of the locks, so an exception will mean the lock doesnā€™t get released.

Seems like itā€™s a dictlike.get(key, None) % dict() situation

Will take a look

0 Likes

#93

Ah, using a Lock() instead of a reentrant lock, which if you grab in the same thread again, wonā€™t cause these locks.

I made a 1 character change to RLock and that same exception no longer causes the freeze.

Traceback (most recent call last): File ".\sublimeclang.py", line 553, in recompile File ".\translationunitcache.py", line 776, in reparse File ".\translationunitcache.py", line 806, in get_opts_script File ".\common.py", line 82, in expand_path TypeError: unsupported operand type(s) for %: 'NoneType' and 'dict'

Iā€™ll patch LockedVariable to make it a context manager.

0 Likes

#94

Is there any way to get contextually aware auto completion?

For example, say I have my cursor, represented as ā€œ|ā€, inside #include <|, Iā€™m getting completion choices for macros and what have you.

0 Likes

#95

You can disable the fast completions with alt+d,alt+f which will then fall back to clangā€™s built in autocomplete functionality which is more accurate but slower.

0 Likes

#96

Sweet, cheers :smiley:

Iā€™ll be sending you some paypal love when I have some credit.

Iā€™ve been getting paid cash via western union so nothing in the pig atm :unamused:

0 Likes

#97

How did you end up in the situation where options_script is None anyway? Because by default itā€™s set to ā€œā€ so wouldnā€™t trigger this issueā€¦

09:11 /tmp/SublimeClang $ curl -O http://cloud.github.com/downloads/quarnster/SublimeClang/SublimeClang.sublime-package % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11.1M 100 11.1M 0 0 4207k 0 0:00:02 0:00:02 --:--:-- 4330k 09:11 /tmp/SublimeClang $ unzip SublimeClang.sublime-package Archive: SublimeClang.sublime-package inflating: Context.sublime-menu inflating: Default.sublime-commands inflating: Default.sublime-keymap inflating: Main.sublime-menu inflating: README.creole inflating: SublimeClang.sublime-settings creating: clang/ inflating: clang/__init__.py inflating: clang/cindex.py creating: clang/include/ inflating: clang/include/altivec.h inflating: clang/include/arm_neon.h inflating: clang/include/avxintrin.h inflating: clang/include/emmintrin.h inflating: clang/include/float.h inflating: clang/include/immintrin.h inflating: clang/include/iso646.h inflating: clang/include/limits.h inflating: clang/include/mm3dnow.h inflating: clang/include/mm_malloc.h inflating: clang/include/mmintrin.h inflating: clang/include/nmmintrin.h inflating: clang/include/pmmintrin.h inflating: clang/include/smmintrin.h inflating: clang/include/stdalign.h inflating: clang/include/stdarg.h inflating: clang/include/stdbool.h inflating: clang/include/stddef.h inflating: clang/include/stdint.h inflating: clang/include/tgmath.h inflating: clang/include/tmmintrin.h inflating: clang/include/varargs.h inflating: clang/include/wmmintrin.h inflating: clang/include/x86intrin.h inflating: clang/include/xmmintrin.h inflating: common.py inflating: errormarkers.py inflating: libcache.dll inflating: libcache.dylib inflating: libcache_x64.dll inflating: libclang.dll inflating: libclang.dylib inflating: libclang_x64.dll inflating: package.json creating: parsehelp/ extracting: parsehelp/__init__.py inflating: parsehelp/parsehelp.py creating: src/ creating: src/clang-c/ inflating: src/clang-c/Index.h inflating: src/CMakeLists.txt inflating: src/main.cpp inflating: staticanalyzer.py inflating: sublimeclang.py inflating: sublimeclang.sublime-project inflating: translationunitcache.py 09:11 /tmp/SublimeClang $ cat SublimeClang.sublime-settings | grep options_script "options_script": "", 09:11 /tmp/SublimeClang $

The right fix is to do try finally blocks as there shouldnā€™t be a need for reentrance. Iā€™ll patch this up.

0 Likes

#98
return expand_path(get_setting("options_script", None, view), view.window())

I think after nuking/recloning fresh I just rewound the history on the settings file using a backups plugin. The keys must have changed.

Iā€™ll revert it to make sure I have all the latest settings.

Yeah, I just changed it to use RLock as it was a quick 1 character fix to stop it locking so I could take a look at the code.

I donā€™t like editing in notepad LOL

Context managers, ie with blocks, are nice for that. Saves having try/finally every where.

0 Likes

#99

Thanks, no luck though. Iā€™ve tried making a test project with the same include paths, but the error is sporadic. I donā€™t think that the one path which caused the error before is really the issue ā€“ it seems to be something else which happened to be triggered in this case.

I printed out the filename & opts in translationunitcache.py in the parse/reparse functions, but nothing seemed unusual.

0 Likes

#100

RyanJ, You could compile libcache (and possibly libclang too) yourself with debug symbols enabled, and you should be able to attach a debugger to Sublime Text 2 and get a proper stacktrace for this issue.

0 Likes

#101

FYI, it looks like one of your recent changes seems to have fixed the issue I was seeing. If I do see it again Iā€™ll build the libs to debug it more (Iā€™d been too busy to attempt that yet).

soā€¦ thanks! :smiley:

0 Likes

#102

Cool, thanks for the update :smile:

0 Likes

#103

edit:

Never mind. It did find my include files, but it throws numerous errors on the new header files from the Windows 8 SDK, so Iā€™ll just leave it for now and try again later.

0 Likes

#104

Hey folks,

Iā€™m trying to get SublimeClang to play friendly with Objective-C. Iā€™ve followed the suggestions on this forum and the GitHub Page and added the following to my ā€œoptionsā€:

"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.2.sdk", "-D__IPHONE_OS_VERSION_MIN_REQUIRED=40300", "-I/Users/CVSS/Documents/Reader"

However, I still get the following error when I open a file in my project:

Fatal - 'UIKit/UIKit.h' file not found Did you configure the include path used by clang properly? See http://github.com/quarnster/SublimeClang for more details on how to configure SublimeClang.

Iā€™m using the latest SDK, lateste build of ST2 and Running on Lion.

Any ideas? Thanks.

0 Likes