@@ -143,17 +143,6 @@ public struct __ExpectationContext: ~Copyable {
143
143
144
144
return expression
145
145
}
146
-
147
- #if !SWT_FIXED_122011759
148
- /// Storage for any locally-created C strings.
149
- private var _transformedCStrings = [ UnsafeMutablePointer < CChar > ] ( )
150
-
151
- deinit {
152
- for cString in _transformedCStrings {
153
- free ( cString)
154
- }
155
- }
156
- #endif
157
146
}
158
147
159
148
@available ( * , unavailable)
@@ -464,15 +453,15 @@ extension __ExpectationContext {
464
453
// MARK: - Implicit pointer conversion
465
454
466
455
extension __ExpectationContext {
467
- /// Convert some pointer to an immutable one and capture information about it
468
- /// for use if the expectation currently being evaluated fails.
456
+ /// Convert some pointer to another pointer type and capture information about
457
+ /// it for use if the expectation currently being evaluated fails.
469
458
///
470
459
/// - Parameters:
471
- /// - value: The pointer to make immutable .
460
+ /// - value: The pointer to cast .
472
461
/// - id: A value that uniquely identifies the represented expression in the
473
462
/// context of the expectation currently being evaluated.
474
463
///
475
- /// - Returns: `value`, cast to an immutable pointer.
464
+ /// - Returns: `value`, cast to another type of pointer.
476
465
///
477
466
/// This overload of `callAsFunction(_:_:)` handles the implicit conversions
478
467
/// between various pointer types that are normally provided by the compiler.
@@ -486,67 +475,63 @@ extension __ExpectationContext {
486
475
}
487
476
}
488
477
489
- #if !SWT_FIXED_122011759
490
478
// MARK: - String-to-C-string handling
491
479
492
480
extension __ExpectationContext {
493
- /// Convert a string to a C string and capture information about it for use if
494
- /// the expectation currently being evaluated fails.
481
+ /// Capture information about a value for use if the expectation currently
482
+ /// being evaluated fails.
495
483
///
496
484
/// - Parameters:
497
- /// - value: The string value that should be transformed into a C string .
485
+ /// - value: The value to pass through .
498
486
/// - id: A value that uniquely identifies the represented expression in the
499
487
/// context of the expectation currently being evaluated.
500
488
///
501
- /// - Returns: `value`, transformed into a pointer to a C string. The caller
502
- /// should _not_ free this string; it will be freed when the expectation
503
- /// context is destroyed.
489
+ /// - Returns: `value`, verbatim.
504
490
///
505
- /// This overload of `callAsFunction(_:_:)` is necessary because Swift allows
506
- /// passing string literals directly to functions that take C strings. The
507
- /// default overload of `callAsFunction(_:_:)` does not trigger this implicit
508
- /// cast and causes a compile-time error. ([122011759](rdar://122011759))
491
+ /// This overload of `callAsFunction(_:_:)` helps the compiler disambiguate
492
+ /// string values when they need to be implicitly cast to C strings.
509
493
///
510
494
/// - Warning: This function is used to implement the `#expect()` and
511
495
/// `#require()` macros. Do not call it directly.
512
- public mutating func callAsFunction< P> ( _ value: String , _ id: __ExpressionID ) -> P where P: _Pointer {
513
- // Perform the normal value capture.
514
- let value = _captureValue ( value, id)
515
-
516
- // Create a C string copy of `value`.
517
- let valueCString = value. withCString { value in
518
- #if os(Windows)
519
- _strdup ( value)
520
- #else
521
- strdup ( value)
522
- #endif
523
- }
524
-
525
- let result = valueCString. flatMap { valueCString in
526
- // Store the C string pointer so we can free it later when this context is
527
- // torn down.
528
- if _transformedCStrings. capacity == 0 {
529
- _transformedCStrings. reserveCapacity ( 2 )
530
- }
531
- _transformedCStrings. append ( valueCString)
532
-
533
- // Return the C string as whatever pointer type the caller wants.
534
- return P ( bitPattern: Int ( bitPattern: valueCString) )
535
- }
496
+ public mutating func callAsFunction( _ value: String , _ id: __ExpressionID ) -> String {
497
+ _captureValue ( value, id)
498
+ }
536
499
537
- return result!
500
+ /// Capture information about a value for use if the expectation currently
501
+ /// being evaluated fails.
502
+ ///
503
+ /// - Parameters:
504
+ /// - value: The value to pass through.
505
+ /// - id: A value that uniquely identifies the represented expression in the
506
+ /// context of the expectation currently being evaluated.
507
+ ///
508
+ /// - Returns: An optional value containing a copy of `value`.
509
+ ///
510
+ /// This overload of `callAsFunction(_:_:)` helps the compiler disambiguate
511
+ /// string values when they need to be implicitly cast to C strings.
512
+ ///
513
+ /// - Warning: This function is used to implement the `#expect()` and
514
+ /// `#require()` macros. Do not call it directly.
515
+ public mutating func callAsFunction( _ value: String , _ id: __ExpressionID ) -> String ? {
516
+ _captureValue ( value, id)
538
517
}
539
518
540
519
/// Capture information about a value for use if the expectation currently
541
520
/// being evaluated fails.
542
521
///
522
+ /// - Parameters:
523
+ /// - value: The value to pass through.
524
+ /// - id: A value that uniquely identifies the represented expression in the
525
+ /// context of the expectation currently being evaluated.
526
+ ///
527
+ /// - Returns: An optional value containing a copy of `value`.
528
+ ///
543
529
/// This overload of `callAsFunction(_:_:)` helps the compiler disambiguate
544
- /// optional string values.
530
+ /// string values when they need to be implicitly cast to C strings .
545
531
///
546
532
/// - Warning: This function is used to implement the `#expect()` and
547
533
/// `#require()` macros. Do not call it directly.
548
- public mutating func callAsFunction( _ value: String ? , _ id: __ExpressionID ) -> String ! {
534
+ public mutating func callAsFunction( _ value: String ? , _ id: __ExpressionID ) -> String ? {
549
535
_captureValue ( value, id)
550
536
}
551
537
}
552
- #endif
0 commit comments