Browse Source

Fix crash on mac (and 32-bit iOS?) - don't represent SRDelegateAvailableMethods as a bitfield (#530)

* Don't represent SRDelegateAvailableMethods as a bitfield

Since Objective-C uses a signed char for BOOL on some platforms (macOS and 32-bit iOS) packing this into a bitfield doesn't work since when it tries to read the field it looks for the sign bit and fails with an EXC_BAD_INSTRUCTION. This change sacrifices a few bits for the extra portability.

* CR - followup
Daniel Hammond 7 years ago
parent
commit
0a023409b1
1 changed files with 19 additions and 0 deletions
  1. 19 0
      SocketRocket/Internal/Delegate/SRDelegateController.h

+ 19 - 0
SocketRocket/Internal/Delegate/SRDelegateController.h

@@ -13,6 +13,8 @@
 
 
 NS_ASSUME_NONNULL_BEGIN
 NS_ASSUME_NONNULL_BEGIN
 
 
+#if OBJC_BOOL_IS_BOOL
+
 struct SRDelegateAvailableMethods {
 struct SRDelegateAvailableMethods {
     BOOL didReceiveMessage : 1;
     BOOL didReceiveMessage : 1;
     BOOL didReceiveMessageWithString : 1;
     BOOL didReceiveMessageWithString : 1;
@@ -24,6 +26,23 @@ struct SRDelegateAvailableMethods {
     BOOL didReceivePong : 1;
     BOOL didReceivePong : 1;
     BOOL shouldConvertTextFrameToString : 1;
     BOOL shouldConvertTextFrameToString : 1;
 };
 };
+
+#else
+
+struct SRDelegateAvailableMethods {
+    BOOL didReceiveMessage;
+    BOOL didReceiveMessageWithString;
+    BOOL didReceiveMessageWithData;
+    BOOL didOpen;
+    BOOL didFailWithError;
+    BOOL didCloseWithCode;
+    BOOL didReceivePing;
+    BOOL didReceivePong;
+    BOOL shouldConvertTextFrameToString;
+};
+
+#endif
+
 typedef struct SRDelegateAvailableMethods SRDelegateAvailableMethods;
 typedef struct SRDelegateAvailableMethods SRDelegateAvailableMethods;
 
 
 typedef void(^SRDelegateBlock)(id<SRWebSocketDelegate> _Nullable delegate, SRDelegateAvailableMethods availableMethods);
 typedef void(^SRDelegateBlock)(id<SRWebSocketDelegate> _Nullable delegate, SRDelegateAvailableMethods availableMethods);