From 148045d0d4ce7145d6fa90f76a132c6bfb1efcb3 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Wed, 26 Aug 2015 01:57:57 -0700 Subject: [PATCH] Fix the example for folly::static_function_deleter. Summary: [Folly] Fix the example for folly::static_function_deleter. The problem is that int BIO_free(BIO*) is not directly compatible. So have two examples. One using `RSA_free` which is compatible, and one making a compatible wrapper around `BIO_free`. Reviewed By: @Gownta Differential Revision: D2381125 --- folly/Memory.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/folly/Memory.h b/folly/Memory.h index 76f11dc1..cf32e743 100644 --- a/folly/Memory.h +++ b/folly/Memory.h @@ -61,7 +61,17 @@ make_unique(Args&&...) = delete; * * So you can write this: * - * using BIO_deleter = folly::static_function_deleter; + * using RSA_deleter = folly::static_function_deleter; + * auto rsa = std::unique_ptr(RSA_new()); + * RSA_generate_key_ex(rsa.get(), bits, exponent, nullptr); + * rsa = nullptr; // calls RSA_free(rsa.get()) + * + * This would be sweet as well for BIO, but unfortunately BIO_free has signature + * int(BIO*) while we require signature void(BIO*). So you would need to make a + * wrapper for it: + * + * inline void BIO_free_fb(BIO* bio) { CHECK_EQ(1, BIO_free(bio)); } + * using BIO_deleter = folly::static_function_deleter; * auto buf = std::unique_ptr(BIO_new(BIO_s_mem())); * buf = nullptr; // calls BIO_free(buf.get()) */ -- 2.34.1