From 1e80d4465a01869b7455b31f53a0aff42d939f6d Mon Sep 17 00:00:00 2001 From: Bryan Duxbury Date: Tue, 3 Feb 2009 18:16:54 +0000 Subject: [PATCH] THRIFT-302. ruby: Native extension fails to build A piece of code needed for compilation on Linux was missing; this patch replaces it. Also, there were some compiler warnings and declarations that were missing that are now fixed. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@740366 13f79535-47bb-0310-9956-ffa450edef68 --- lib/rb/ext/binary_protocol_accelerated.c | 3 ++- lib/rb/ext/binary_protocol_accelerated.h | 3 +-- lib/rb/ext/constants.h | 2 +- lib/rb/ext/memory_buffer.c | 2 +- lib/rb/ext/memory_buffer.h | 3 +-- lib/rb/ext/protocol.c | 2 +- lib/rb/ext/protocol.h | 3 +-- lib/rb/ext/struct.c | 23 ++++++++++++++++++++++- lib/rb/ext/struct.h | 2 +- lib/rb/ext/thrift_native.c | 2 +- 10 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/rb/ext/binary_protocol_accelerated.c b/lib/rb/ext/binary_protocol_accelerated.c index 27567fc4..8a6757f8 100644 --- a/lib/rb/ext/binary_protocol_accelerated.c +++ b/lib/rb/ext/binary_protocol_accelerated.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -434,4 +435,4 @@ void Init_binary_protocol_accelerated() { VALUE method_table_object = Data_Wrap_Struct(rb_cObject, 0, free, npmt); rb_const_set(bpa_class, rb_intern("@native_method_table"), method_table_object); -} \ No newline at end of file +} diff --git a/lib/rb/ext/binary_protocol_accelerated.h b/lib/rb/ext/binary_protocol_accelerated.h index 4d3517ba..6175ff40 100644 --- a/lib/rb/ext/binary_protocol_accelerated.h +++ b/lib/rb/ext/binary_protocol_accelerated.h @@ -1,2 +1 @@ - -void Init_binary_protocol_accelerated(); \ No newline at end of file +void Init_binary_protocol_accelerated(); diff --git a/lib/rb/ext/constants.h b/lib/rb/ext/constants.h index f66a3ac7..e540234d 100644 --- a/lib/rb/ext/constants.h +++ b/lib/rb/ext/constants.h @@ -72,4 +72,4 @@ extern VALUE rb_cSet; extern VALUE thrift_module; extern VALUE thrift_types_module; extern VALUE class_thrift_protocol; -extern VALUE protocol_exception_class; \ No newline at end of file +extern VALUE protocol_exception_class; diff --git a/lib/rb/ext/memory_buffer.c b/lib/rb/ext/memory_buffer.c index a607ae2f..00545cc9 100644 --- a/lib/rb/ext/memory_buffer.c +++ b/lib/rb/ext/memory_buffer.c @@ -49,4 +49,4 @@ void Init_memory_buffer() { slice_method_id = rb_intern("slice"); GARBAGE_BUFFER_SIZE = FIX2INT(rb_const_get(thrift_memory_buffer_class, rb_intern("GARBAGE_BUFFER_SIZE"))); -} \ No newline at end of file +} diff --git a/lib/rb/ext/memory_buffer.h b/lib/rb/ext/memory_buffer.h index ccc2aedf..9e01d13a 100644 --- a/lib/rb/ext/memory_buffer.h +++ b/lib/rb/ext/memory_buffer.h @@ -1,2 +1 @@ - -void Init_memory_buffer(); \ No newline at end of file +void Init_memory_buffer(); diff --git a/lib/rb/ext/protocol.c b/lib/rb/ext/protocol.c index b548f97a..207e78d0 100644 --- a/lib/rb/ext/protocol.c +++ b/lib/rb/ext/protocol.c @@ -163,4 +163,4 @@ void Init_protocol() { // // VALUE method_table_object = Data_Wrap_Struct(rb_cObject, 0, free, npmt); // rb_const_set(c_protocol, rb_intern("@native_method_table"), method_table_object); -} \ No newline at end of file +} diff --git a/lib/rb/ext/protocol.h b/lib/rb/ext/protocol.h index 534c8594..b5e066f6 100644 --- a/lib/rb/ext/protocol.h +++ b/lib/rb/ext/protocol.h @@ -1,2 +1 @@ - -void Init_protocol(); \ No newline at end of file +void Init_protocol(); diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c index 0e7aa1a2..b882344b 100644 --- a/lib/rb/ext/struct.c +++ b/lib/rb/ext/struct.c @@ -1,7 +1,28 @@ - #include #include +#ifndef HAVE_STRLCPY + +static +size_t +strlcpy (char *dst, const char *src, size_t dst_sz) +{ + size_t n; + + for (n = 0; n < dst_sz; n++) { + if ((*dst++ = *src++) == '\0') + break; + } + + if (n < dst_sz) + return n; + if (n > 0) + *(dst - 1) = '\0'; + return n + strlen (src); +} + +#endif + static native_proto_method_table *mt; #define IS_CONTAINER(ttype) ((ttype) == TTYPE_MAP || (ttype) == TTYPE_LIST || (ttype) == TTYPE_SET) diff --git a/lib/rb/ext/struct.h b/lib/rb/ext/struct.h index bf2350d2..870d24e7 100644 --- a/lib/rb/ext/struct.h +++ b/lib/rb/ext/struct.h @@ -45,4 +45,4 @@ typedef struct native_proto_method_table { } native_proto_method_table; -void Init_struct(); \ No newline at end of file +void Init_struct(); diff --git a/lib/rb/ext/thrift_native.c b/lib/rb/ext/thrift_native.c index 60d0fc0f..89d32c52 100644 --- a/lib/rb/ext/thrift_native.c +++ b/lib/rb/ext/thrift_native.c @@ -166,4 +166,4 @@ void Init_thrift_native() { Init_struct(); Init_binary_protocol_accelerated(); Init_memory_buffer(); -} \ No newline at end of file +} -- 2.17.1