From 0d6837e9575f498ad8d79736c4f592b7de78e393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Mon, 13 Jun 2016 23:11:24 +0100 Subject: [PATCH] Only use the typed data interface for Ruby version >= 2.2.0 --- ext/openssl/cipher/aead/aead.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ext/openssl/cipher/aead/aead.c b/ext/openssl/cipher/aead/aead.c index 94fd04b..dc850d2 100644 --- a/ext/openssl/cipher/aead/aead.c +++ b/ext/openssl/cipher/aead/aead.c @@ -1,17 +1,25 @@ #include +#include #include #include VALUE dOSSL; VALUE eCipherError; +#if RUBY_API_VERSION_CODE >= 20200 #define GetCipherInit(obj, ctx) do { \ TypedData_Get_Struct((obj), EVP_CIPHER_CTX, RTYPEDDATA_TYPE(obj), (ctx)); \ } while (0) -#define GetCipher(obj, ctx) do { \ - GetCipherInit((obj), (ctx)); \ - if (!(ctx)) { \ - ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \ +#else +#define GetCipherInit(obj, ctx) do { \ + Data_Get_Struct((obj), EVP_CIPHER_CTX, (ctx)); \ +} while (0) +#endif + +#define GetCipher(obj, ctx) do { \ + GetCipherInit((obj), (ctx)); \ + if (!(ctx)) { \ + ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \ } \ } while (0)