Skip to content

Commit

Permalink
Remove partial compatibility with Rubinius and MRI < 2.0
Browse files Browse the repository at this point in the history
This makes even more have_func-tests unnecessary.

Also deprecate Connection#socket in favor of #socket_io.
  • Loading branch information
larskanis committed Jan 4, 2018
1 parent e588ad1 commit fab02db
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 126 deletions.
8 changes: 6 additions & 2 deletions History.rdoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
== vXXX [YYYY-MM-DD] Michael Granger <ged@FaerieMUD.org>

Deprecated:
- Deprecate Ruby older than 2.2.
- Deprecate Connection#socket in favor of #socket_io.

Removed:
- Deprecate Ruby older than 2.2
- Remove compatibility code for Ruby < 1.9.3 and PostgreSQL < 9.2.
- Remove compatibility code for Ruby < 2.0 and PostgreSQL < 9.2.
- Remove partial compatibility with Rubinius.

Enhancements:
- Update error codes to PostgreSQL-10
Expand Down
7 changes: 0 additions & 7 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@
have_func 'PQsslAttribute'
have_func 'PQencryptPasswordConn'

have_func 'rb_thread_call_without_gvl'
have_func 'rb_thread_call_with_gvl'
have_func 'rb_thread_fd_select'
have_func 'rb_w32_wrap_io_handle'
have_func 'rb_str_modify_expand'
have_func 'rb_hash_dup'

have_const 'PG_DIAG_TABLE_NAME', 'libpq-fe.h'

# unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
Expand Down
55 changes: 17 additions & 38 deletions ext/gvl_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
#ifndef __gvl_wrappers_h
#define __gvl_wrappers_h

#if defined(HAVE_RB_THREAD_CALL_WITH_GVL)
extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
#endif

#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
rb_unblock_function_t *ubf, void *data2);
#endif
#include <ruby/thread.h>

#define DEFINE_PARAM_LIST1(type, name) \
name,
Expand Down Expand Up @@ -53,21 +46,14 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
return NULL; \
}

#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
#define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
struct gvl_wrapper_##name##_params params = { \
{FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
}; \
rb_thread_call_without_gvl(gvl_##name##_skeleton, &params, RUBY_UBF_IO, 0); \
when_non_void( return params.retval; ) \
}
#else
#define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
return name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
}
#endif
#define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
struct gvl_wrapper_##name##_params params = { \
{FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
}; \
rb_thread_call_without_gvl(gvl_##name##_skeleton, &params, RUBY_UBF_IO, 0); \
when_non_void( return params.retval; ) \
}

#define DEFINE_GVL_STUB_DECL(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname);
Expand All @@ -80,21 +66,14 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
return NULL; \
}

#if defined(HAVE_RB_THREAD_CALL_WITH_GVL)
#define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
struct gvl_wrapper_##name##_params params = { \
{FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
}; \
rb_thread_call_with_gvl(gvl_##name##_skeleton, &params); \
when_non_void( return params.retval; ) \
}
#else
#define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
return name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
}
#endif
#define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
struct gvl_wrapper_##name##_params params = { \
{FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
}; \
rb_thread_call_with_gvl(gvl_##name##_skeleton, &params); \
when_non_void( return params.retval; ) \
}

#define GVL_TYPE_VOID(string)
#define GVL_TYPE_NONVOID(string) string
Expand Down
44 changes: 13 additions & 31 deletions ext/pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,38 +257,20 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
* rb_str_set_len( string, current_out - RSTRING_PTR(string) );
*
*/
#ifdef HAVE_RB_STR_MODIFY_EXPAND
/* Use somewhat faster version with access to string capacity on MRI */
char *
pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
{
long curr_len = curr_ptr - RSTRING_PTR(str);
long curr_capa = rb_str_capacity( str );
if( curr_capa < curr_len + expand_len ){
rb_str_set_len( str, curr_len );
rb_str_modify_expand( str, (curr_len + expand_len) * 2 - curr_capa );
curr_ptr = RSTRING_PTR(str) + curr_len;
}
if( end_ptr )
*end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
return curr_ptr;
}
#else
/* Use the more portable version */
char *
pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
{
long curr_len = curr_ptr - RSTRING_PTR(str);
long curr_capa = RSTRING_LEN( str );
if( curr_capa < curr_len + expand_len ){
rb_str_resize( str, (curr_len + expand_len) * 2 - curr_capa );
curr_ptr = RSTRING_PTR(str) + curr_len;
}
if( end_ptr )
*end_ptr = RSTRING_PTR(str) + RSTRING_LEN(str);
return curr_ptr;
char *
pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
{
long curr_len = curr_ptr - RSTRING_PTR(str);
long curr_capa = rb_str_capacity( str );
if( curr_capa < curr_len + expand_len ){
rb_str_set_len( str, curr_len );
rb_str_modify_expand( str, (curr_len + expand_len) * 2 - curr_capa );
curr_ptr = RSTRING_PTR(str) + curr_len;
}
#endif
if( end_ptr )
*end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
return curr_ptr;
}


/**************************************************************************
Expand Down
27 changes: 1 addition & 26 deletions ext/pg.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,16 @@
/* exported by ruby-1.9.3+ but not declared */
extern int rb_encdb_alias(const char *, const char *);


#if !defined(ENCODING_SET_INLINED)
/* Rubinius doesn't define ENCODING_SET_INLINED, so we fall back to the more
* portable version.
*/
# define PG_ENCODING_SET_NOCHECK(obj,i) \
do { \
rb_enc_set_index((obj), (i)); \
} while(0)
#else
# define PG_ENCODING_SET_NOCHECK(obj,i) \
#define PG_ENCODING_SET_NOCHECK(obj,i) \
do { \
if ((i) < ENCODING_INLINE_MAX) \
ENCODING_SET_INLINED((obj), (i)); \
else \
rb_enc_set_index((obj), (i)); \
} while(0)
#endif

#include "ruby/io.h"

#ifdef RUBINIUS
/* Workaround for wrong FIXNUM_MAX definition */
typedef intptr_t native_int;
#endif

#ifndef RETURN_SIZED_ENUMERATOR
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) RETURN_ENUMERATOR((obj), (argc), (argv))
#endif

#ifndef HAVE_RB_HASH_DUP
/* Rubinius doesn't define rb_hash_dup() */
#define rb_hash_dup(tuple) rb_funcall((tuple), rb_intern("dup"), 0)
#endif

#ifndef timeradd
#define timeradd(a, b, result) \
do { \
Expand Down
28 changes: 6 additions & 22 deletions ext/pg_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ static VALUE pgconn_finish( VALUE );
static VALUE pgconn_set_default_encoding( VALUE self );
void pgconn_set_internal_encoding_index( VALUE );

#ifndef HAVE_RB_THREAD_FD_SELECT
#define rb_fdset_t fd_set
#define rb_fd_init(f)
#define rb_fd_zero(f) FD_ZERO(f)
#define rb_fd_set(n, f) FD_SET(n, f)
#define rb_fd_term(f)
#define rb_thread_fd_select rb_thread_select
#endif

/*
* Global functions
*/
Expand Down Expand Up @@ -93,7 +84,7 @@ pgconn_close_socket_io( VALUE self )
VALUE socket_io = this->socket_io;

if ( RTEST(socket_io) ) {
#if defined(_WIN32) && defined(HAVE_RB_W32_WRAP_IO_HANDLE)
#if defined(_WIN32)
int ruby_sd = NUM2INT(rb_funcall( socket_io, rb_intern("fileno"), 0 ));
if( rb_w32_unwrap_io_handle(ruby_sd) ){
rb_raise(rb_eConnectionBad, "Could not unwrap win32 socket handle");
Expand Down Expand Up @@ -853,6 +844,8 @@ pgconn_error_message(VALUE self)
* call-seq:
* conn.socket() -> Integer
*
* This method is deprecated. Please use the more portable method #socket_io .
*
* Returns the socket's file descriptor for this connection.
* <tt>IO.for_fd()</tt> can be used to build a proper IO object to the socket.
* If you do so, you will likely also want to set <tt>autoclose=false</tt>
Expand All @@ -861,7 +854,7 @@ pgconn_error_message(VALUE self)
* creates an IO that's associated with the connection object itself,
* and so won't go out of scope until the connection does.
*
* *Note:* On Windows the file descriptor is not really usable,
* *Note:* On Windows the file descriptor is not usable,
* since it can not be used to build a Ruby IO object.
*/
static VALUE
Expand All @@ -873,22 +866,17 @@ pgconn_socket(VALUE self)
return INT2NUM(sd);
}


#if !defined(_WIN32) || defined(HAVE_RB_W32_WRAP_IO_HANDLE)

/*
* call-seq:
* conn.socket_io() -> IO
*
* Fetch a memoized IO object created from the Connection's underlying socket.
* Fetch a memorized IO object created from the Connection's underlying socket.
* This object can be used for IO.select to wait for events while running
* asynchronous API calls.
*
* Using this instead of #socket avoids the problem of the underlying connection
* being closed by Ruby when an IO created using <tt>IO.for_fd(conn.socket)</tt>
* goes out of scope.
*
* This method can also be used on Windows but requires Ruby-2.0+.
* goes out of scope. In contrast to #socket, it also works on Windows.
*/
static VALUE
pgconn_socket_io(VALUE self)
Expand Down Expand Up @@ -922,8 +910,6 @@ pgconn_socket_io(VALUE self)
return socket_io;
}

#endif

/*
* call-seq:
* conn.backend_pid() -> Integer
Expand Down Expand Up @@ -3953,9 +3939,7 @@ init_pg_connection()
rb_define_method(rb_cPGconn, "server_version", pgconn_server_version, 0);
rb_define_method(rb_cPGconn, "error_message", pgconn_error_message, 0);
rb_define_method(rb_cPGconn, "socket", pgconn_socket, 0);
#if !defined(_WIN32) || defined(HAVE_RB_W32_WRAP_IO_HANDLE)
rb_define_method(rb_cPGconn, "socket_io", pgconn_socket_io, 0);
#endif
rb_define_method(rb_cPGconn, "backend_pid", pgconn_backend_pid, 0);
rb_define_method(rb_cPGconn, "connection_needs_password", pgconn_connection_needs_password, 0);
rb_define_method(rb_cPGconn, "connection_used_password", pgconn_connection_used_password, 0);
Expand Down

0 comments on commit fab02db

Please sign in to comment.