Fix the example for folly::static_function_deleter.
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 26 Aug 2015 08:57:57 +0000 (01:57 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 31 Aug 2015 20:24:47 +0000 (13:24 -0700)
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

index 76f11dc155b5ae26d148aff07e8573cd990fbeab..cf32e7438daa951dda6310012b9510c088359acd 100644 (file)
@@ -61,7 +61,17 @@ make_unique(Args&&...) = delete;
  *
  * So you can write this:
  *
- *      using BIO_deleter = folly::static_function_deleter<BIO, &BIO_free>;
+ *      using RSA_deleter = folly::static_function_deleter<RSA, &RSA_free>;
+ *      auto rsa = std::unique_ptr<RSA, RSA_deleter>(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<BIO, &BIO_free_fb>;
  *      auto buf = std::unique_ptr<BIO, BIO_deleter>(BIO_new(BIO_s_mem()));
  *      buf = nullptr;  // calls BIO_free(buf.get())
  */