Skip to content

Commit 1219650

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Make the MTRDevice ivars protected. (#35101)
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.
1 parent 9e88a2b commit 1219650

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

src/darwin/Framework/CHIP/MTRDevice_Internal.h

+1-14
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,7 @@ MTR_DIRECT_MEMBERS
108108

109109
@interface MTRDevice () {
110110
// Ivars needed to implement shared MTRDevice functionality.
111-
//
112-
// Unfortunately, we can't use @protected here, because that exports the
113-
// symbols (so that subclasses that are not part of the framework can see
114-
// them), but TAPI does not see these declarations, because they are in a
115-
// project header.
116-
//
117-
// Using @package means that the symbols do not need to be exported, but
118-
// unfortunately gets treated as @public from inside our framework, which
119-
// means random other framework code can access these ivars. Hopefully the
120-
// naming with leading '_' will make it clearer that random other code
121-
// should not touch these.
122-
//
123-
// TODO: Figure out some way of doing @protected but still not exporting the symbol.
124-
@package
111+
@protected
125112
// Lock that protects overall device state, including delegate storage.
126113
os_unfair_lock _lock;
127114
NSMutableSet<MTRDeviceDelegateInfo *> * _delegates;

src/darwin/Framework/Matter.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -2565,6 +2565,7 @@
25652565
"-Wl,-unexported_symbol,\"___*\"",
25662566
"-Wl,-unexported_symbol,\"__Unwind_*\"",
25672567
"-Wl,-unexported_symbol,\"_unw_*\"",
2568+
"-Wl,-unexported_symbol,\"_OBJC_IVAR_*\"",
25682569
"-Wl,-hidden-lCHIP",
25692570
);
25702571
"OTHER_LDFLAGS[sdk=macosx*]" = (
@@ -2583,6 +2584,7 @@
25832584
"-Wl,-unexported_symbol,\"___*\"",
25842585
"-Wl,-unexported_symbol,\"__Unwind_*\"",
25852586
"-Wl,-unexported_symbol,\"_unw_*\"",
2587+
"-Wl,-unexported_symbol,\"_OBJC_IVAR_*\"",
25862588
"-Wl,-hidden-lCHIP",
25872589
);
25882590
PRODUCT_BUNDLE_IDENTIFIER = com.csa.matter;

0 commit comments

Comments
 (0)