Skip to content

Commit a084d04

Browse files
authored
Merge pull request swiftlang#31686 from 3405691582/ManagedBuffer_WithoutMallocSize
[stdlib] ManagedBuffer independent of malloc_size.
2 parents 01547a6 + cd7570f commit a084d04

File tree

12 files changed

+32
-0
lines changed

12 files changed

+32
-0
lines changed

include/swift/AST/PlatformKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ AVAILABILITY_PLATFORM(watchOSApplicationExtension, "application extensions for w
3232
AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS")
3333
AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst")
3434
AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst")
35+
AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD")
3536

3637
#undef AVAILABILITY_PLATFORM

lib/AST/PlatformKind.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ static bool isPlatformActiveForTarget(PlatformKind Platform,
8787
case PlatformKind::watchOS:
8888
case PlatformKind::watchOSApplicationExtension:
8989
return Target.isWatchOS();
90+
case PlatformKind::OpenBSD:
91+
return Target.isOSOpenBSD();
9092
case PlatformKind::none:
9193
llvm_unreachable("handled above");
9294
}

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
19301930
"APIs deprecated as of macOS 10.9 and earlier are unavailable in Swift";
19311931
break;
19321932

1933+
case PlatformKind::OpenBSD:
1934+
deprecatedAsUnavailableMessage = "";
1935+
break;
1936+
19331937
case PlatformKind::none:
19341938
break;
19351939
}
@@ -1962,6 +1966,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
19621966
case PlatformKind::watchOSApplicationExtension:
19631967
return name == "watchos" || name == "watchos_app_extension";
19641968

1969+
case PlatformKind::OpenBSD:
1970+
return name == "openbsd";
1971+
19651972
case PlatformKind::none:
19661973
return false;
19671974
}
@@ -2001,6 +2008,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
20012008
case PlatformKind::watchOSApplicationExtension:
20022009
// No deprecation filter on watchOS
20032010
return false;
2011+
2012+
case PlatformKind::OpenBSD:
2013+
// No deprecation filter on OpenBSD
2014+
return false;
20042015
}
20052016

20062017
llvm_unreachable("Unexpected platform");

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,9 @@ class DeclAndTypePrinter::Implementation
878878
case PlatformKind::watchOSApplicationExtension:
879879
plat = "watchos_app_extension";
880880
break;
881+
case PlatformKind::OpenBSD:
882+
plat = "openbsd";
883+
break;
881884
case PlatformKind::none:
882885
llvm_unreachable("handled above");
883886
}

lib/SymbolGraphGen/AvailabilityMixin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ StringRef getDomain(const AvailableAttr &AvAttr) {
5656
return { "tvOSAppExtension" };
5757
case swift::PlatformKind::watchOSApplicationExtension:
5858
return { "watchOSAppExtension" };
59+
case swift::PlatformKind::OpenBSD:
60+
return { "OpenBSD" };
5961
case swift::PlatformKind::none:
6062
return { "*" };
6163
}

lib/TBDGen/TBDGen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) {
249249
switch(Ver.Platform) {
250250
case swift::PlatformKind::none:
251251
llvm_unreachable("cannot find platform kind");
252+
case swift::PlatformKind::OpenBSD:
253+
llvm_unreachable("not used for this platform");
252254
case swift::PlatformKind::iOS:
253255
case swift::PlatformKind::iOSApplicationExtension:
254256
return Ver.IsSimulator ? LinkerPlatformId::iOS_sim:

stdlib/public/core/BridgingBuffer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ internal final class __BridgingBufferStorage
2525
internal typealias _BridgingBuffer
2626
= ManagedBufferPointer<_BridgingBufferHeader, AnyObject>
2727

28+
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
2829
extension ManagedBufferPointer
2930
where Header == _BridgingBufferHeader, Element == AnyObject {
3031
internal init(_ count: Int) {

stdlib/public/core/ManagedBuffer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ extension ManagedBuffer {
8383
/// idea to store this information in the "header" area when
8484
/// an instance is created.
8585
@inlinable
86+
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
8687
public final var capacity: Int {
8788
let storageAddr = UnsafeMutableRawPointer(Builtin.bridgeToRawPointer(self))
8889
let endAddr = storageAddr + _swift_stdlib_malloc_size(storageAddr)
@@ -197,6 +198,7 @@ public struct ManagedBufferPointer<Header, Element> {
197198
/// properties. The `deinit` of `bufferClass` must destroy its
198199
/// stored `Header` and any constructed `Element`s.
199200
@inlinable
201+
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
200202
public init(
201203
bufferClass: AnyClass,
202204
minimumCapacity: Int,
@@ -329,6 +331,7 @@ extension ManagedBufferPointer {
329331
/// idea to store this information in the "header" area when
330332
/// an instance is created.
331333
@inlinable
334+
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
332335
public var capacity: Int {
333336
return (
334337
_capacityInBytes &- ManagedBufferPointer._elementOffset
@@ -431,6 +434,7 @@ extension ManagedBufferPointer {
431434

432435
/// The actual number of bytes allocated for this object.
433436
@inlinable
437+
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
434438
internal var _capacityInBytes: Int {
435439
return _swift_stdlib_malloc_size(_address)
436440
}

test/IDE/complete_decl_attribute.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct MyStruct {}
3939
// AVAILABILITY1-NEXT: Keyword/None: macOSApplicationExtension[#Platform#]; name=macOSApplicationExtension{{$}}
4040
// AVAILABILITY1-NEXT: Keyword/None: macCatalyst[#Platform#]; name=macCatalyst
4141
// AVAILABILITY1-NEXT: Keyword/None: macCatalystApplicationExtension[#Platform#]; name=macCatalystApplicationExtension
42+
// AVAILABILITY1-NEXT: Keyword/None: OpenBSD[#Platform#]; name=OpenBSD{{$}}
4243
// AVAILABILITY1-NEXT: End completions
4344

4445
@available(*, #^AVAILABILITY2^#)

test/Interpreter/generic_ref_counts.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-run-simple-swift | %FileCheck %s
22
// REQUIRES: executable_test
3+
// XFAIL: OS=openbsd
34

45
import Swift
56

0 commit comments

Comments
 (0)