Skip to content

CF_RETURNS_* issues when naming Core Foundation functions #2598

@zhongwuzw

Description

@zhongwuzw

New Issue Checklist

Issue Info

Info Value
SDWebImage Version 5.x`

Issue Description and Steps

// Marks functions which return a CF type that needs to be released by the caller but whose names are not consistent with CoreFoundation naming rules. The recommended fix to this is to rename the functions, but this macro can be used to let the clang static analyzer know of any exceptions that cannot be fixed.
// This macro is ONLY to be used in exceptional circumstances, not to annotate functions which conform to the CoreFoundation naming rules.
#ifndef CF_RETURNS_RETAINED
#if __has_feature(attribute_cf_returns_retained)
#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
#else
#define CF_RETURNS_RETAINED
#endif
#endif

// Marks functions which return a CF type that may need to be retained by the caller but whose names are not consistent with CoreFoundation naming rules. The recommended fix to this is to rename the functions, but this macro can be used to let the clang static analyzer know of any exceptions that cannot be fixed. 
// This macro is ONLY to be used in exceptional circumstances, not to annotate functions which conform to the CoreFoundation naming rules.
#ifndef CF_RETURNS_NOT_RETAINED
#if __has_feature(attribute_cf_returns_not_retained)
#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
#else
#define CF_RETURNS_NOT_RETAINED
#endif
#endif

CF_RETURNS_RETAINED and CF_RETURNS_NOT_RETAINED can only used in exceptional circumstances, which is to say, if function name conforms the naming rules, we should not annotate it. But currently, we don't conform this rule, like :

+ (CGColorSpaceRef _Nonnull)colorSpaceGetDeviceRGB CF_RETURNS_NOT_RETAINED;
+ (CGImageRef _Nullable)CGImageCreateDecoded:(_Nonnull CGImageRef)cgImage CF_RETURNS_RETAINED;
and so on.....

From the git log, seems it try to optimize Swift Unmanaged type.

Two options we can solve issues:

  1. Remove all CF_RETURNS_* annotate if it already satisfy naming rules. Let Unmanaged type exist.
  2. Remove all CF_RETURNS_* annotate if it already satisfy naming rules. Refactor SDImageCoderHelper, make all class methods to be C functions, use CF_IMPLICIT_BRIDGING_ENABLED to fix swift Unmanaged type issues.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions