Created
February 21, 2009 20:35
-
-
Save samgranieri/68177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ext/extconf.rb b/ext/extconf.rb | |
index c959833..241ea67 100644 | |
--- a/ext/extconf.rb | |
+++ b/ext/extconf.rb | |
@@ -1,13 +1,13 @@ | |
# windows compatibility, need different library name | |
-if(PLATFORM =~ /mingw|mswin/) then | |
+if(RUBY_PLATFORM =~ /mingw|mswin/) then | |
$libname = '/ms/libpq' | |
else | |
$libname = 'pq' | |
end | |
-if(PLATFORM =~ /darwin/) then | |
+if(RUBY_PLATFORM =~ /darwin/) then | |
# test if postgresql is probably universal | |
bindir = (IO.popen("pg_config --bindir").readline.chomp rescue nil) | |
filetype = (IO.popen("file #{bindir}/pg_config"). | |
diff --git a/ext/postgres.c b/ext/postgres.c | |
index c6c2bb7..496db28 100644 | |
--- a/ext/postgres.c | |
+++ b/ext/postgres.c | |
@@ -13,7 +13,7 @@ | |
************************************************/ | |
#include "ruby.h" | |
-#include "rubyio.h" | |
+#include "ruby/io.h" | |
#if RUBY_VM != 1 | |
#define RUBY_18_COMPAT | |
@@ -192,7 +192,7 @@ pgconn_connect(argc, argv, self) | |
PGconn *conn = NULL; | |
rb_scan_args(argc, argv, "0*", &args); | |
- if (RARRAY(args)->len == 1) { | |
+ if (RARRAY_LEN(args) == 1) { | |
conn = try_connectdb(rb_ary_entry(args, 0)); | |
} | |
if (conn == NULL) { | |
@@ -720,14 +720,14 @@ pgconn_exec(argc, argv, obj) | |
Check_Type(command, T_STRING); | |
- if (RARRAY(params)->len <= 0) { | |
+ if (RARRAY_LEN(params) <= 0) { | |
result = PQexec(conn, StringValuePtr(command)); | |
} | |
else { | |
- int len = RARRAY(params)->len; | |
+ int len = RARRAY_LEN(params); | |
int i; | |
#ifdef HAVE_PQEXECPARAMS | |
- VALUE* ptr = RARRAY(params)->ptr; | |
+ VALUE* ptr = RARRAY_PTR(params); | |
char const** values = ALLOCA_N(char const*, len); | |
int* lengths = ALLOCA_N(int, len); | |
int* formats = ALLOCA_N(int, len); | |
@@ -947,9 +947,9 @@ pgconn_insert_table(obj, table, values) | |
Check_Type(table, T_STRING); | |
Check_Type(values, T_ARRAY); | |
- i = RARRAY(values)->len; | |
+ i = RARRAY_LEN(values); | |
while (i--) { | |
- if (TYPE(RARRAY(RARRAY(values)->ptr[i])) != T_ARRAY) { | |
+ if (TYPE(RARRAY(RARRAY_PTR(values)[i])) != T_ARRAY) { | |
rb_raise(rb_ePGError, "second arg must contain some kind of arrays."); | |
} | |
} | |
@@ -964,15 +964,15 @@ pgconn_insert_table(obj, table, values) | |
} | |
PQclear(result); | |
- for (i = 0; i < RARRAY(values)->len; i++) { | |
- struct RArray *row = RARRAY(RARRAY(values)->ptr[i]); | |
+ for (i = 0; i < RARRAY_LEN(values); i++) { | |
+ struct RArray *row = RARRAY(RARRAY_PTR(values)[i]); | |
buffer = rb_tainted_str_new(0,0); | |
- for (j = 0; j < row->len; j++) { | |
+ for (j = 0; j < RARRAY_LEN(row); j++) { | |
if (j > 0) rb_str_cat(buffer, "\t", 1); | |
- if (NIL_P(row->ptr[j])) { | |
+ if (NIL_P(RARRAY_PTR(row)[j])) { | |
rb_str_cat(buffer, "\\N",2); | |
} else { | |
- s = rb_obj_as_string(row->ptr[j]); | |
+ s = rb_obj_as_string(RARRAY_PTR(row)[j]); | |
rb_funcall(s,pg_gsub_bang_id,2, | |
rb_str_new("([\\t\\n\\\\])", 10),pg_escape_str); | |
rb_str_cat(buffer, StringValuePtr(s), RSTRING_LEN(s)); | |
@@ -1482,7 +1482,7 @@ fetch_pgrow(self, fields, row_num) | |
PGresult *result = get_pgresult(self); | |
VALUE row = rb_funcall(rb_cPGrow, rb_intern("new"), 1, fields); | |
int field_num; | |
- for (field_num = 0; field_num < RARRAY(fields)->len; field_num++) { | |
+ for (field_num = 0; field_num < RARRAY_LEN(fields); field_num++) { | |
/* don't use push, PGrow is sized with nils in #new */ | |
rb_ary_store(row, field_num, fetch_pgresult(result, row_num, field_num)); | |
} | |
@@ -2417,7 +2417,7 @@ static VALUE | |
pgrow_init(self, keys) | |
VALUE self, keys; | |
{ | |
- VALUE args[1] = { LONG2NUM(RARRAY(keys)->len) }; | |
+ VALUE args[1] = { LONG2NUM(RARRAY_LEN(keys)) }; | |
rb_call_super(1, args); | |
rb_iv_set(self, "@keys", keys); | |
return self; | |
@@ -2501,7 +2501,7 @@ pgrow_each_pair(self) | |
{ | |
VALUE keys = pgrow_keys(self); | |
int i; | |
- for (i = 0; i < RARRAY(keys)->len; ++i) { | |
+ for (i = 0; i < RARRAY_LEN(keys); ++i) { | |
rb_yield(rb_assoc_new(rb_ary_entry(keys, i), rb_ary_entry(self, i))); | |
} | |
return self; | |
@@ -2556,7 +2556,7 @@ pgrow_to_hash(self) | |
VALUE result = rb_hash_new(); | |
VALUE keys = pgrow_keys(self); | |
int i; | |
- for (i = 0; i < RARRAY(self)->len; ++i) { | |
+ for (i = 0; i < RARRAY_LEN(self); ++i) { | |
rb_hash_aset(result, rb_ary_entry(keys, i), rb_ary_entry(self, i)); | |
} | |
return result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment