Skip to content

Commit

Permalink
libclang: declare blocks interfaces always
Browse files Browse the repository at this point in the history
The implementation of these methods is not reliant on the availability
of the Blocks extension in the compiler.  However, when building on
Windows, the interface declaration is important for the attribution of
the DLL storage.  Without the attribution, the method implementation is
built but not made available as part of the ABI.  Use a check for the
blocks extension to determine how method signature is viewed rather than
controlling whether it is part of the interface.
  • Loading branch information
compnerd committed May 10, 2023
1 parent 9fb9c77 commit ce5ad23
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions clang/include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#define CINDEX_VERSION_STRING \
CINDEX_VERSION_STRINGIZE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR)

#ifndef __has_feature
#define __has_feature(feature) 0
#endif

LLVM_CLANG_C_EXTERN_C_BEGIN

/** \defgroup CINDEX libclang: C Interface to Clang
Expand Down Expand Up @@ -3856,8 +3860,6 @@ typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
CXCursorVisitor visitor,
CXClientData client_data);
#ifdef __has_feature
#if __has_feature(blocks)
/**
* Visitor invoked for each cursor found by a traversal.
*
Expand All @@ -3868,17 +3870,19 @@ CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
* The visitor should return one of the \c CXChildVisitResult values
* to direct clang_visitChildrenWithBlock().
*/
#if __has_feature(blocks)
typedef enum CXChildVisitResult (^CXCursorVisitorBlock)(CXCursor cursor,
CXCursor parent);
#else
typedef _CXChildVisitResult *CXCursorVisitorBlock;
#endif

/**
* Visits the children of a cursor using the specified block. Behaves
* identically to clang_visitChildren() in all other respects.
*/
CINDEX_LINKAGE unsigned
clang_visitChildrenWithBlock(CXCursor parent, CXCursorVisitorBlock block);
#endif
#endif

/**
* @}
Expand Down Expand Up @@ -5879,11 +5883,12 @@ CINDEX_LINKAGE CXResult clang_findReferencesInFile(
CINDEX_LINKAGE CXResult clang_findIncludesInFile(
CXTranslationUnit TU, CXFile file, CXCursorAndRangeVisitor visitor);

#ifdef __has_feature
#if __has_feature(blocks)

typedef enum CXVisitorResult (^CXCursorAndRangeVisitorBlock)(CXCursor,
CXSourceRange);
#else
typedef struct _CXCursorAndRangeVisitorBlock *CXCursorAndRangeVisitorBlock;
#endif

CINDEX_LINKAGE
CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
Expand All @@ -5893,9 +5898,6 @@ CINDEX_LINKAGE
CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
CXCursorAndRangeVisitorBlock);

#endif
#endif

/**
* The client's data object that is associated with a CXFile.
*/
Expand Down

0 comments on commit ce5ad23

Please sign in to comment.