New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-11763] C array larger than 4096 failed to import in Swift with Xcode 11.2 #54170
Comments
I actually screened your radar this morning. I guess you'll just get the reply a little sooner! Thanks for reporting this issue. This behavior change was intentional—we found that extremely large tuples like this one were causing compiler performance problems and were too clumsy to use in practice anyway. Although the print(MemoryLayout<TEST_FIXED_ARRAY>.size) // => 4097 And it will also copy the contents as necessary—they just aren’t directly exposed to Swift. As a workaround, I’d recommend writing a C function along the lines of |
Comment by Rejean Lamy (JIRA) Thanks Brent for the explanation. I hope Swift will soon support fixed array natively so we can import such large C array directly. |
Comment by Rejean Lamy (JIRA) Brent, I suggest lifting this limit.
My point is not whether it makes sense for a Swift programmer to work with a large tuple and where to put a limit, but the fact that the absence of other mechanisms penalizes the programmer to access C structs array members. So, I suggest that you lift this limit until you find another acceptable solution. On several discussion threads I notice requests and proposals to implement of Swift fixed-size array type. Is fixed-size array support coming soon? |
The 4096 limit was selected because it matches C’s BUFSIZ constant, which is used in structs defined in some C headers. We’d love to do something about fixed-size arrays, but they would probably require new generics features. Another possibility would be to import these fields as having |
Comment by Rejean Lamy (JIRA) Brent, A short-term solution based on a new Swift API as withUnsafeMutablePointerToFixedArray ... would be really good. Thanks for considering. |
Comment by Jeff Verkoeyen (JIRA) I believe I'm encountering this issue again in https://bugs.swift.org/browse/SR-14061. |
Environment
macOS 10.15.1
Xcode 11.2
Also filed on Apple Feedback #
FB7438876
Additional Detail from JIRA
md5: 07ffc60aaca6251835926f69d4e71aa3
relates to:
Issue Description:
This c struct with fixed array size of 8192 imported ok using Swift with Xcode 10:
typedef struct
{ uint8_t data[8192]; }
TEST_FIXED_ARRAY;
The same code failed to import using Swift with Xcode 11.2
Error message say: Value of type 'TEST_FIXED_ARRAY' has no member 'data'
Changing to data[4096]; is working ok however.
Its very easy to reproduce.
A simple Swift console project with a C header file containing
// file testc.h
#include <stdio.h>
typedef struct
{ uint8_t data[4097]; }
TEST_FIXED_ARRAY;
In Build Setting specify as Objective-C Bridging Header
And test using the followng Swift code in main.swift
// file main.swift
import Foundation
print("Hello, World!")
let cStruct = TEST_FIXED_ARRAY()
let data = cStruct.data
print(data)
This work without problem using Xcode 10 with size > 4096
But with Xcode 11.2 the following error:
Value of type 'TEST_FIXED_ARRAY' has no member 'data'
So the compiler simply don't see the 'data' member.
Changing the size to 4096 and its fine.
Also filed on Apple Feedback #
FB7438876
The text was updated successfully, but these errors were encountered: