Skip to content

Commit

Permalink
Fix crash on mac (and 32-bit iOS?) - don't represent SRDelegateAvaila…
Browse files Browse the repository at this point in the history
…bleMethods as a bitfield (facebookincubator#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
  • Loading branch information
danielrhammond authored and nlutsenko committed Apr 28, 2018
1 parent 28035e1 commit 0a02340
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions SocketRocket/Internal/Delegate/SRDelegateController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

NS_ASSUME_NONNULL_BEGIN

#if OBJC_BOOL_IS_BOOL

struct SRDelegateAvailableMethods {
BOOL didReceiveMessage : 1;
BOOL didReceiveMessageWithString : 1;
Expand All @@ -24,6 +26,23 @@ struct SRDelegateAvailableMethods {
BOOL didReceivePong : 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 void(^SRDelegateBlock)(id<SRWebSocketDelegate> _Nullable delegate, SRDelegateAvailableMethods availableMethods);
Expand Down

0 comments on commit 0a02340

Please sign in to comment.