Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to release resources with Clang using C API?
    primarykey
    data
    text
    <p>Sorry for probably silly question: should i release command args vars and unsaved files structures when using Clang C API functions? I do know that in common case one should release resources to avoid memory leaks, but i wonder if Clang does it itself on <code>clang_disposeTranslationUnit()</code>.</p> <p>I'm having clang crash after few iterations of parse/diags + tokenize/dispose so i have to eliminate possible problems one-by-one.</p> <p>Parsing for example:</p> <pre><code>char **args; CXUnsavedFile *files; // allocate args args = new char*[N]; for (int i=0; i&lt;N; i++) { int len = strlen(argv[i]); args[i] = new char[len + 1]; args[i][len] = 0; strcpy(arg[i], argv[i]); } // allocate unsaved files files = new CXUnsavedFile[M]; for (int i=0; i&lt;M; i++) { files[i].Filename = new char[BBB]; // + fill Filename files[i].Contents = new char[CCC]; // + fill Contents files[i].Length = strlen(files[i].Contents); } clang_parseTranslationUnit(..., args, N, files, M); // release resources (need to do?) // args for (int i=0; i&lt;N; i++) { delete []args[i]; } delete[] args; // unsaved files for (int i=0; i&lt;M; i++) { delete []files[i].Filename; delete []files[i].Contents; } delete []files; </code></pre> <p>UPDATE: for those who think it's really silly question - answer in 30 seconds what is the reason for the crash:</p> <pre><code>12-11 00:10:38.126: INFO/DEBUG(166): backtrace: 12-11 00:10:38.126: INFO/DEBUG(166): #00 pc 0001832a /system/lib/libc.so 12-11 00:10:38.126: INFO/DEBUG(166): #01 pc 0000dc04 /system/lib/libc.so (abort+4) 12-11 00:10:38.126: INFO/DEBUG(166): #02 pc 0001f0df /system/lib/libc.so (__assert2+30) 12-11 00:10:38.126: INFO/DEBUG(166): #03 pc 0077c954 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::getSourceLocation(char const*, unsigned int) const+76) 12-11 00:10:38.126: INFO/DEBUG(166): #04 pc 0077ca4c /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::FormTokenWithChars(clang::Token&amp;, char const*, clang::tok::TokenKind)+100) 12-11 00:10:38.126: INFO/DEBUG(166): #05 pc 00781098 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::LexTokenInternal(clang::Token&amp;)+5616) 12-11 00:10:38.126: INFO/DEBUG(166): #06 pc 0015de68 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::LexFromRawLexer(clang::Token&amp;)+116) 12-11 00:10:38.126: INFO/DEBUG(166): #07 pc 00781d3c /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::getRawToken(clang::SourceLocation, clang::Token&amp;, clang::SourceManager const&amp;, clang::LangOptions const&amp;)+220) 12-11 00:10:38.126: INFO/DEBUG(166): #08 pc 00781d9c /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::MeasureTokenLength(clang::SourceLocation, clang::SourceManager const&amp;, clang::LangOptions const&amp;)+36) 12-11 00:10:38.126: INFO/DEBUG(166): #09 pc 001d1824 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::DiagnosticRenderer::emitMacroExpansions(clang::SourceLocation, clang::DiagnosticsEngine::Level, llvm::ArrayRef&lt;clang::CharSourceRange&gt;, llvm::ArrayRef&lt;clang::FixItHint&gt;, clang::SourceManager const&amp;, unsigned int&amp;, unsigned int)+840) 12-11 00:10:38.126: INFO/DEBUG(166): #10 pc 001d13ec /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::DiagnosticRenderer::emitDiagnostic(clang::SourceLocation, clang::DiagnosticsEngine::Level, llvm::StringRef, llvm::ArrayRef&lt;clang::CharSourceRange&gt;, llvm::ArrayRef&lt;clang::FixItHint&gt;, clang::SourceManager const*, llvm::PointerUnion&lt;clang::Diagnostic const*, clang::StoredDiagnostic const*&gt;)+1224) 12-11 00:10:38.126: INFO/DEBUG(166): #11 pc 001d1b20 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::DiagnosticRenderer::emitStoredDiagnostic(clang::StoredDiagnostic&amp;)+304) 12-11 00:10:38.126: INFO/DEBUG(166): #12 pc 0017b1c8 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::cxdiag::lazyCreateDiags(CXTranslationUnitImpl*, bool)+248) 12-11 00:10:38.126: INFO/DEBUG(166): #13 pc 00009028 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang_wrapper.so (Java_name_antonsmirnov_clang_clang_1wrapper_getDiagnostics+72) 12-11 00:10:38.126: INFO/DEBUG(166): #14 pc 0001fb70 /system/lib/libdvm.so (dvmPlatformInvoke+112) 12-11 00:10:38.126: INFO/DEBUG(166): #15 pc 0004e8b9 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+360) 12-11 00:10:38.126: INFO/DEBUG(166): #16 pc 00029020 /system/lib/libdvm.so 12-11 00:10:38.126: INFO/DEBUG(166): #17 pc 0002d7e8 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+180) 12-11 00:10:38.126: INFO/DEBUG(166): #18 pc 0005fed5 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+272) 12-11 00:10:38.126: INFO/DEBUG(166): #19 pc 0005feff /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+20) 12-11 00:10:38.126: INFO/DEBUG(166): #20 pc 00055327 /system/lib/libdvm.so 12-11 00:10:38.126: INFO/DEBUG(166): #21 pc 00012e70 /system/lib/libc.so (__thread_entry+48) 12-11 00:10:38.126: INFO/DEBUG(166): #22 pc 000125c8 /system/lib/libc.so (pthread_create+172) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload