Skip to content

Commit

Permalink
Make the MTRDevice ivars protected. (#35101)
Browse files Browse the repository at this point in the history
It seems like by default we have the following visibility options here:

@Private - subclasses can't touch, not workable.
@public - anyone can touch, not desirable.
@Package - @public inside Matter.framework, @Private ouside it. Does not export
           the symbols, but anyone inside Matter.framework can touch.
@Protected - only subclasses can touch, but exports the symbols in case we have
             out-of-framework subclasses who want to touch it.  Since the
             declarations are in a project header that TAPI does not know about
             in release builds, we get complaints about mismatches between
             what's declared public and what's exported.

What we would really want here is "@Protected inside Matter.framework, @Private
ouside it", but that does not exist.  So this switches to @Protected, and uses
linker arguments to not export the symbols in release builds.  Since the header
itself is not public, this accomplishes the same goal.  In debug builds, we do
expose project headers to TAPI, hence there we want to keep exporting the
symbols.

The linker arguments just prevent exporting all ivar symbols, since we shouldn't
be exporting any of those anyway.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Oct 25, 2024
1 parent 9e88a2b commit 1219650
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 1 addition & 14 deletions src/darwin/Framework/CHIP/MTRDevice_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,7 @@ MTR_DIRECT_MEMBERS

@interface MTRDevice () {
// Ivars needed to implement shared MTRDevice functionality.
//
// Unfortunately, we can't use @protected here, because that exports the
// symbols (so that subclasses that are not part of the framework can see
// them), but TAPI does not see these declarations, because they are in a
// project header.
//
// Using @package means that the symbols do not need to be exported, but
// unfortunately gets treated as @public from inside our framework, which
// means random other framework code can access these ivars. Hopefully the
// naming with leading '_' will make it clearer that random other code
// should not touch these.
//
// TODO: Figure out some way of doing @protected but still not exporting the symbol.
@package
@protected
// Lock that protects overall device state, including delegate storage.
os_unfair_lock _lock;
NSMutableSet<MTRDeviceDelegateInfo *> * _delegates;
Expand Down
2 changes: 2 additions & 0 deletions src/darwin/Framework/Matter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,7 @@
"-Wl,-unexported_symbol,\"___*\"",
"-Wl,-unexported_symbol,\"__Unwind_*\"",
"-Wl,-unexported_symbol,\"_unw_*\"",
"-Wl,-unexported_symbol,\"_OBJC_IVAR_*\"",
"-Wl,-hidden-lCHIP",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
Expand All @@ -2583,6 +2584,7 @@
"-Wl,-unexported_symbol,\"___*\"",
"-Wl,-unexported_symbol,\"__Unwind_*\"",
"-Wl,-unexported_symbol,\"_unw_*\"",
"-Wl,-unexported_symbol,\"_OBJC_IVAR_*\"",
"-Wl,-hidden-lCHIP",
);
PRODUCT_BUNDLE_IDENTIFIER = com.csa.matter;
Expand Down

0 comments on commit 1219650

Please sign in to comment.