pg 1.2.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.appveyor.yml +42 -0
- data/.gems +6 -0
- data/.github/workflows/binary-gems.yml +117 -0
- data/.github/workflows/source-gem.yml +141 -0
- data/.gitignore +22 -0
- data/.hgsigs +34 -0
- data/.hgtags +41 -0
- data/.irbrc +23 -0
- data/.pryrc +23 -0
- data/.tm_properties +21 -0
- data/.travis.yml +49 -0
- data/Gemfile +14 -0
- data/History.md +884 -0
- data/Manifest.txt +0 -1
- data/README.ja.md +300 -0
- data/README.md +286 -0
- data/Rakefile +33 -135
- data/Rakefile.cross +12 -13
- data/certs/ged.pem +24 -0
- data/certs/larskanis-2022.pem +26 -0
- data/certs/larskanis-2023.pem +24 -0
- data/ext/errorcodes.def +12 -0
- data/ext/errorcodes.rb +0 -0
- data/ext/errorcodes.txt +4 -1
- data/ext/extconf.rb +104 -25
- data/ext/gvl_wrappers.c +4 -0
- data/ext/gvl_wrappers.h +23 -0
- data/ext/pg.c +73 -58
- data/ext/pg.h +28 -5
- data/ext/pg_binary_decoder.c +80 -1
- data/ext/pg_binary_encoder.c +225 -1
- data/ext/pg_coder.c +96 -33
- data/ext/pg_connection.c +1010 -704
- data/ext/pg_copy_coder.c +351 -33
- data/ext/pg_errors.c +1 -1
- data/ext/pg_record_coder.c +50 -19
- data/ext/pg_result.c +177 -64
- data/ext/pg_text_decoder.c +29 -11
- data/ext/pg_text_encoder.c +29 -16
- data/ext/pg_tuple.c +83 -60
- data/ext/pg_type_map.c +44 -10
- data/ext/pg_type_map_all_strings.c +17 -3
- data/ext/pg_type_map_by_class.c +54 -27
- data/ext/pg_type_map_by_column.c +73 -31
- data/ext/pg_type_map_by_mri_type.c +48 -19
- data/ext/pg_type_map_by_oid.c +59 -27
- data/ext/pg_type_map_in_ruby.c +55 -21
- data/ext/pg_util.c +2 -2
- data/lib/pg/basic_type_map_based_on_result.rb +67 -0
- data/lib/pg/basic_type_map_for_queries.rb +198 -0
- data/lib/pg/basic_type_map_for_results.rb +104 -0
- data/lib/pg/basic_type_registry.rb +299 -0
- data/lib/pg/binary_decoder/date.rb +9 -0
- data/lib/pg/binary_decoder/timestamp.rb +26 -0
- data/lib/pg/binary_encoder/timestamp.rb +20 -0
- data/lib/pg/coder.rb +15 -13
- data/lib/pg/connection.rb +743 -83
- data/lib/pg/exceptions.rb +14 -1
- data/lib/pg/text_decoder/date.rb +18 -0
- data/lib/pg/text_decoder/inet.rb +9 -0
- data/lib/pg/text_decoder/json.rb +14 -0
- data/lib/pg/text_decoder/numeric.rb +9 -0
- data/lib/pg/text_decoder/timestamp.rb +30 -0
- data/lib/pg/text_encoder/date.rb +12 -0
- data/lib/pg/text_encoder/inet.rb +28 -0
- data/lib/pg/text_encoder/json.rb +14 -0
- data/lib/pg/text_encoder/numeric.rb +9 -0
- data/lib/pg/text_encoder/timestamp.rb +24 -0
- data/lib/pg/version.rb +4 -0
- data/lib/pg.rb +94 -39
- data/misc/openssl-pg-segfault.rb +31 -0
- data/misc/postgres/History.txt +9 -0
- data/misc/postgres/Manifest.txt +5 -0
- data/misc/postgres/README.txt +21 -0
- data/misc/postgres/Rakefile +21 -0
- data/misc/postgres/lib/postgres.rb +16 -0
- data/misc/ruby-pg/History.txt +9 -0
- data/misc/ruby-pg/Manifest.txt +5 -0
- data/misc/ruby-pg/README.txt +21 -0
- data/misc/ruby-pg/Rakefile +21 -0
- data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
- data/pg.gemspec +34 -0
- data/rakelib/task_extension.rb +46 -0
- data/sample/array_insert.rb +20 -0
- data/sample/async_api.rb +102 -0
- data/sample/async_copyto.rb +39 -0
- data/sample/async_mixed.rb +56 -0
- data/sample/check_conn.rb +21 -0
- data/sample/copydata.rb +71 -0
- data/sample/copyfrom.rb +81 -0
- data/sample/copyto.rb +19 -0
- data/sample/cursor.rb +21 -0
- data/sample/disk_usage_report.rb +177 -0
- data/sample/issue-119.rb +94 -0
- data/sample/losample.rb +69 -0
- data/sample/minimal-testcase.rb +17 -0
- data/sample/notify_wait.rb +72 -0
- data/sample/pg_statistics.rb +285 -0
- data/sample/replication_monitor.rb +222 -0
- data/sample/test_binary_values.rb +33 -0
- data/sample/wal_shipper.rb +434 -0
- data/sample/warehouse_partitions.rb +311 -0
- data/translation/.po4a-version +7 -0
- data/translation/po/all.pot +936 -0
- data/translation/po/ja.po +1036 -0
- data/translation/po4a.cfg +12 -0
- data.tar.gz.sig +0 -0
- metadata +135 -207
- metadata.gz.sig +0 -0
- data/ChangeLog +0 -0
- data/History.rdoc +0 -578
- data/README.ja.rdoc +0 -13
- data/README.rdoc +0 -213
- data/lib/pg/basic_type_mapping.rb +0 -522
- data/lib/pg/binary_decoder.rb +0 -23
- data/lib/pg/constants.rb +0 -12
- data/lib/pg/text_decoder.rb +0 -46
- data/lib/pg/text_encoder.rb +0 -59
- data/spec/data/expected_trace.out +0 -26
- data/spec/data/random_binary_data +0 -0
- data/spec/helpers.rb +0 -380
- data/spec/pg/basic_type_mapping_spec.rb +0 -630
- data/spec/pg/connection_spec.rb +0 -1949
- data/spec/pg/connection_sync_spec.rb +0 -41
- data/spec/pg/result_spec.rb +0 -681
- data/spec/pg/tuple_spec.rb +0 -333
- data/spec/pg/type_map_by_class_spec.rb +0 -138
- data/spec/pg/type_map_by_column_spec.rb +0 -226
- data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
- data/spec/pg/type_map_by_oid_spec.rb +0 -149
- data/spec/pg/type_map_in_ruby_spec.rb +0 -164
- data/spec/pg/type_map_spec.rb +0 -22
- data/spec/pg/type_spec.rb +0 -1123
- data/spec/pg_spec.rb +0 -50
data/ext/pg_type_map_by_class.c
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
#include "pg.h"
|
|
11
11
|
|
|
12
12
|
static VALUE rb_cTypeMapByClass;
|
|
13
|
-
static ID s_id_ancestors;
|
|
14
13
|
|
|
15
14
|
typedef struct {
|
|
16
15
|
t_typemap typemap;
|
|
@@ -48,7 +47,7 @@ pg_tmbk_lookup_klass(t_tmbk *this, VALUE klass, VALUE param_value)
|
|
|
48
47
|
|
|
49
48
|
if( NIL_P(obj) ){
|
|
50
49
|
int i;
|
|
51
|
-
VALUE ancestors =
|
|
50
|
+
VALUE ancestors = rb_mod_ancestors( klass );
|
|
52
51
|
|
|
53
52
|
Check_Type( ancestors, T_ARRAY );
|
|
54
53
|
/* Don't look at the first element, it's expected to equal klass. */
|
|
@@ -63,7 +62,7 @@ pg_tmbk_lookup_klass(t_tmbk *this, VALUE klass, VALUE param_value)
|
|
|
63
62
|
if(NIL_P(obj)){
|
|
64
63
|
p_coder = NULL;
|
|
65
64
|
}else if(rb_obj_is_kind_of(obj, rb_cPG_Coder)){
|
|
66
|
-
|
|
65
|
+
TypedData_Get_Struct(obj, t_pg_coder, &pg_coder_type, p_coder);
|
|
67
66
|
}else{
|
|
68
67
|
if( RB_TYPE_P(obj, T_SYMBOL) ){
|
|
69
68
|
/* A Symbol: Call the method with this name. */
|
|
@@ -75,11 +74,9 @@ pg_tmbk_lookup_klass(t_tmbk *this, VALUE klass, VALUE param_value)
|
|
|
75
74
|
|
|
76
75
|
if( NIL_P(obj) ){
|
|
77
76
|
p_coder = NULL;
|
|
78
|
-
}else if( rb_obj_is_kind_of(obj, rb_cPG_Coder) ){
|
|
79
|
-
Data_Get_Struct(obj, t_pg_coder, p_coder);
|
|
80
77
|
}else{
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
/* Check retrieved coder type */
|
|
79
|
+
TypedData_Get_Struct(obj, t_pg_coder, &pg_coder_type, p_coder);
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
/* We can not cache coders retrieved by ruby code, because we can not anticipate
|
|
@@ -104,7 +101,7 @@ pg_tmbk_typecast_query_param( t_typemap *p_typemap, VALUE param_value, int field
|
|
|
104
101
|
p_coder = pg_tmbk_lookup_klass( this, rb_obj_class(param_value), param_value );
|
|
105
102
|
|
|
106
103
|
if( !p_coder ){
|
|
107
|
-
t_typemap *default_tm =
|
|
104
|
+
t_typemap *default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
108
105
|
return default_tm->funcs.typecast_query_param( default_tm, param_value, field );
|
|
109
106
|
}
|
|
110
107
|
|
|
@@ -114,46 +111,76 @@ pg_tmbk_typecast_query_param( t_typemap *p_typemap, VALUE param_value, int field
|
|
|
114
111
|
static VALUE
|
|
115
112
|
pg_tmbk_fit_to_query( VALUE self, VALUE params )
|
|
116
113
|
{
|
|
117
|
-
t_tmbk *this = (t_tmbk *)
|
|
114
|
+
t_tmbk *this = (t_tmbk *)RTYPEDDATA_DATA(self);
|
|
118
115
|
/* Nothing to check at this typemap, but ensure that the default type map fits. */
|
|
119
|
-
t_typemap *default_tm =
|
|
116
|
+
t_typemap *default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
120
117
|
default_tm->funcs.fit_to_query( this->typemap.default_typemap, params );
|
|
121
118
|
return self;
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
static void
|
|
125
|
-
pg_tmbk_mark(
|
|
122
|
+
pg_tmbk_mark( void *_this )
|
|
126
123
|
{
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
t_tmbk *this = (t_tmbk *)_this;
|
|
125
|
+
pg_typemap_mark(&this->typemap);
|
|
126
|
+
rb_gc_mark_movable(this->klass_to_coder);
|
|
127
|
+
rb_gc_mark_movable(this->self);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static size_t
|
|
131
|
+
pg_tmbk_memsize( const void *_this )
|
|
132
|
+
{
|
|
133
|
+
const t_tmbk *this = (const t_tmbk *)_this;
|
|
134
|
+
return sizeof(*this);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static void
|
|
138
|
+
pg_tmbk_compact(void *ptr)
|
|
139
|
+
{
|
|
140
|
+
t_tmbk *this = (t_tmbk *)ptr;
|
|
141
|
+
|
|
142
|
+
pg_typemap_compact(&this->typemap);
|
|
143
|
+
pg_gc_location(this->klass_to_coder);
|
|
144
|
+
pg_gc_location(this->self);
|
|
145
|
+
|
|
146
|
+
/* Clear the cache, to be safe from changes of klass VALUE by GC.compact. */
|
|
133
147
|
memset(&this->cache_row, 0, sizeof(this->cache_row));
|
|
134
148
|
}
|
|
135
149
|
|
|
150
|
+
static const rb_data_type_t pg_tmbk_type = {
|
|
151
|
+
"PG::TypeMapByClass",
|
|
152
|
+
{
|
|
153
|
+
pg_tmbk_mark,
|
|
154
|
+
RUBY_TYPED_DEFAULT_FREE,
|
|
155
|
+
pg_tmbk_memsize,
|
|
156
|
+
pg_compact_callback(pg_tmbk_compact),
|
|
157
|
+
},
|
|
158
|
+
&pg_typemap_type,
|
|
159
|
+
0,
|
|
160
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | PG_RUBY_TYPED_FROZEN_SHAREABLE,
|
|
161
|
+
};
|
|
162
|
+
|
|
136
163
|
static VALUE
|
|
137
164
|
pg_tmbk_s_allocate( VALUE klass )
|
|
138
165
|
{
|
|
139
166
|
t_tmbk *this;
|
|
140
167
|
VALUE self;
|
|
141
168
|
|
|
142
|
-
self =
|
|
169
|
+
self = TypedData_Make_Struct( klass, t_tmbk, &pg_tmbk_type, this );
|
|
143
170
|
this->typemap.funcs.fit_to_result = pg_typemap_fit_to_result;
|
|
144
171
|
this->typemap.funcs.fit_to_query = pg_tmbk_fit_to_query;
|
|
145
172
|
this->typemap.funcs.fit_to_copy_get = pg_typemap_fit_to_copy_get;
|
|
146
173
|
this->typemap.funcs.typecast_result_value = pg_typemap_result_value;
|
|
147
174
|
this->typemap.funcs.typecast_query_param = pg_tmbk_typecast_query_param;
|
|
148
175
|
this->typemap.funcs.typecast_copy_get = pg_typemap_typecast_copy_get;
|
|
149
|
-
this->typemap.default_typemap
|
|
176
|
+
RB_OBJ_WRITE(self, &this->typemap.default_typemap, pg_typemap_all_strings);
|
|
150
177
|
|
|
151
178
|
/* We need to store self in the this-struct, because pg_tmbk_typecast_query_param(),
|
|
152
179
|
* is called with the this-pointer only. */
|
|
153
180
|
this->self = self;
|
|
154
|
-
this->klass_to_coder
|
|
181
|
+
RB_OBJ_WRITE(self, &this->klass_to_coder, rb_hash_new());
|
|
155
182
|
|
|
156
|
-
/* The cache is properly initialized by
|
|
183
|
+
/* The cache is properly initialized by TypedData_Make_Struct(). */
|
|
157
184
|
|
|
158
185
|
return self;
|
|
159
186
|
}
|
|
@@ -176,7 +203,9 @@ pg_tmbk_s_allocate( VALUE klass )
|
|
|
176
203
|
static VALUE
|
|
177
204
|
pg_tmbk_aset( VALUE self, VALUE klass, VALUE coder )
|
|
178
205
|
{
|
|
179
|
-
t_tmbk *this =
|
|
206
|
+
t_tmbk *this = RTYPEDDATA_DATA( self );
|
|
207
|
+
|
|
208
|
+
rb_check_frozen(self);
|
|
180
209
|
|
|
181
210
|
if(NIL_P(coder)){
|
|
182
211
|
rb_hash_delete( this->klass_to_coder, klass );
|
|
@@ -200,7 +229,7 @@ pg_tmbk_aset( VALUE self, VALUE klass, VALUE coder )
|
|
|
200
229
|
static VALUE
|
|
201
230
|
pg_tmbk_aref( VALUE self, VALUE klass )
|
|
202
231
|
{
|
|
203
|
-
t_tmbk *this =
|
|
232
|
+
t_tmbk *this = RTYPEDDATA_DATA( self );
|
|
204
233
|
|
|
205
234
|
return rb_hash_lookup(this->klass_to_coder, klass);
|
|
206
235
|
}
|
|
@@ -214,16 +243,14 @@ pg_tmbk_aref( VALUE self, VALUE klass )
|
|
|
214
243
|
static VALUE
|
|
215
244
|
pg_tmbk_coders( VALUE self )
|
|
216
245
|
{
|
|
217
|
-
t_tmbk *this =
|
|
246
|
+
t_tmbk *this = RTYPEDDATA_DATA( self );
|
|
218
247
|
|
|
219
248
|
return rb_obj_freeze(rb_hash_dup(this->klass_to_coder));
|
|
220
249
|
}
|
|
221
250
|
|
|
222
251
|
void
|
|
223
|
-
init_pg_type_map_by_class()
|
|
252
|
+
init_pg_type_map_by_class(void)
|
|
224
253
|
{
|
|
225
|
-
s_id_ancestors = rb_intern("ancestors");
|
|
226
|
-
|
|
227
254
|
/*
|
|
228
255
|
* Document-class: PG::TypeMapByClass < PG::TypeMap
|
|
229
256
|
*
|
data/ext/pg_type_map_by_column.c
CHANGED
|
@@ -16,7 +16,7 @@ static VALUE
|
|
|
16
16
|
pg_tmbc_fit_to_result( VALUE self, VALUE result )
|
|
17
17
|
{
|
|
18
18
|
int nfields;
|
|
19
|
-
t_tmbc *this =
|
|
19
|
+
t_tmbc *this = RTYPEDDATA_DATA( self );
|
|
20
20
|
t_typemap *default_tm;
|
|
21
21
|
VALUE sub_typemap;
|
|
22
22
|
|
|
@@ -26,8 +26,8 @@ pg_tmbc_fit_to_result( VALUE self, VALUE result )
|
|
|
26
26
|
nfields, this->nfields );
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/* Ensure that the default type map fits
|
|
30
|
-
default_tm =
|
|
29
|
+
/* Ensure that the default type map fits equally. */
|
|
30
|
+
default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
31
31
|
sub_typemap = default_tm->funcs.fit_to_result( this->typemap.default_typemap, result );
|
|
32
32
|
|
|
33
33
|
/* Did the default type return the same object ? */
|
|
@@ -42,7 +42,7 @@ pg_tmbc_fit_to_result( VALUE self, VALUE result )
|
|
|
42
42
|
|
|
43
43
|
memcpy( p_new_typemap, this, struct_size );
|
|
44
44
|
p_new_typemap->typemap.default_typemap = sub_typemap;
|
|
45
|
-
|
|
45
|
+
RTYPEDDATA_DATA(new_typemap) = p_new_typemap;
|
|
46
46
|
return new_typemap;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -51,7 +51,7 @@ static VALUE
|
|
|
51
51
|
pg_tmbc_fit_to_query( VALUE self, VALUE params )
|
|
52
52
|
{
|
|
53
53
|
int nfields;
|
|
54
|
-
t_tmbc *this =
|
|
54
|
+
t_tmbc *this = RTYPEDDATA_DATA( self );
|
|
55
55
|
t_typemap *default_tm;
|
|
56
56
|
|
|
57
57
|
nfields = (int)RARRAY_LEN( params );
|
|
@@ -60,8 +60,8 @@ pg_tmbc_fit_to_query( VALUE self, VALUE params )
|
|
|
60
60
|
nfields, this->nfields );
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/* Ensure that the default type map fits
|
|
64
|
-
default_tm =
|
|
63
|
+
/* Ensure that the default type map fits equally. */
|
|
64
|
+
default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
65
65
|
default_tm->funcs.fit_to_query( this->typemap.default_typemap, params );
|
|
66
66
|
|
|
67
67
|
return self;
|
|
@@ -70,10 +70,10 @@ pg_tmbc_fit_to_query( VALUE self, VALUE params )
|
|
|
70
70
|
static int
|
|
71
71
|
pg_tmbc_fit_to_copy_get( VALUE self )
|
|
72
72
|
{
|
|
73
|
-
t_tmbc *this =
|
|
73
|
+
t_tmbc *this = RTYPEDDATA_DATA( self );
|
|
74
74
|
|
|
75
|
-
/* Ensure that the default type map fits
|
|
76
|
-
t_typemap *default_tm =
|
|
75
|
+
/* Ensure that the default type map fits equally. */
|
|
76
|
+
t_typemap *default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
77
77
|
default_tm->funcs.fit_to_copy_get( this->typemap.default_typemap );
|
|
78
78
|
|
|
79
79
|
return this->nfields;
|
|
@@ -107,7 +107,7 @@ pg_tmbc_result_value( t_typemap *p_typemap, VALUE result, int tuple, int field )
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
default_tm =
|
|
110
|
+
default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
111
111
|
return default_tm->funcs.typecast_result_value( default_tm, result, tuple, field );
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -120,7 +120,7 @@ pg_tmbc_typecast_query_param( t_typemap *p_typemap, VALUE param_value, int field
|
|
|
120
120
|
t_pg_coder *p_coder = this->convs[field].cconv;
|
|
121
121
|
|
|
122
122
|
if( !p_coder ){
|
|
123
|
-
t_typemap *default_tm =
|
|
123
|
+
t_typemap *default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
124
124
|
return default_tm->funcs.typecast_query_param( default_tm, param_value, field );
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -142,7 +142,7 @@ pg_tmbc_typecast_copy_get( t_typemap *p_typemap, VALUE field_str, int fieldno, i
|
|
|
142
142
|
p_coder = this->convs[fieldno].cconv;
|
|
143
143
|
|
|
144
144
|
if( !p_coder ){
|
|
145
|
-
t_typemap *default_tm =
|
|
145
|
+
t_typemap *default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
146
146
|
return default_tm->funcs.typecast_copy_get( default_tm, field_str, fieldno, format, enc_idx );
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -150,15 +150,17 @@ pg_tmbc_typecast_copy_get( t_typemap *p_typemap, VALUE field_str, int fieldno, i
|
|
|
150
150
|
|
|
151
151
|
/* Is it a pure String conversion? Then we can directly send field_str to the user. */
|
|
152
152
|
if( dec_func == pg_text_dec_string ){
|
|
153
|
+
rb_str_modify(field_str);
|
|
153
154
|
PG_ENCODING_SET_NOCHECK( field_str, enc_idx );
|
|
154
155
|
return field_str;
|
|
155
156
|
}
|
|
156
157
|
if( dec_func == pg_bin_dec_bytea ){
|
|
158
|
+
rb_str_modify(field_str);
|
|
157
159
|
PG_ENCODING_SET_NOCHECK( field_str, rb_ascii8bit_encindex() );
|
|
158
160
|
return field_str;
|
|
159
161
|
}
|
|
160
162
|
|
|
161
|
-
return dec_func( p_coder, RSTRING_PTR(field_str),
|
|
163
|
+
return dec_func( p_coder, RSTRING_PTR(field_str), RSTRING_LENINT(field_str), 0, fieldno, enc_idx );
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
const struct pg_typemap_funcs pg_tmbc_funcs = {
|
|
@@ -171,38 +173,77 @@ const struct pg_typemap_funcs pg_tmbc_funcs = {
|
|
|
171
173
|
};
|
|
172
174
|
|
|
173
175
|
static void
|
|
174
|
-
pg_tmbc_mark(
|
|
176
|
+
pg_tmbc_mark( void *_this )
|
|
175
177
|
{
|
|
178
|
+
t_tmbc *this = (t_tmbc *)_this;
|
|
176
179
|
int i;
|
|
177
180
|
|
|
178
181
|
/* allocated but not initialized ? */
|
|
179
182
|
if( this == (t_tmbc *)&pg_typemap_funcs ) return;
|
|
180
183
|
|
|
181
|
-
|
|
184
|
+
pg_typemap_mark(&this->typemap);
|
|
182
185
|
for( i=0; i<this->nfields; i++){
|
|
183
186
|
t_pg_coder *p_coder = this->convs[i].cconv;
|
|
184
187
|
if( p_coder )
|
|
185
|
-
|
|
188
|
+
rb_gc_mark_movable(p_coder->coder_obj);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static size_t
|
|
193
|
+
pg_tmbc_memsize( const void *_this )
|
|
194
|
+
{
|
|
195
|
+
const t_tmbc *this = (const t_tmbc *)_this;
|
|
196
|
+
return sizeof(t_tmbc) + sizeof(struct pg_tmbc_converter) * this->nfields;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
static void
|
|
200
|
+
pg_tmbc_compact( void *_this )
|
|
201
|
+
{
|
|
202
|
+
t_tmbc *this = (t_tmbc *)_this;
|
|
203
|
+
int i;
|
|
204
|
+
|
|
205
|
+
/* allocated but not initialized ? */
|
|
206
|
+
if( this == (t_tmbc *)&pg_typemap_funcs ) return;
|
|
207
|
+
|
|
208
|
+
pg_typemap_compact(&this->typemap);
|
|
209
|
+
for( i=0; i<this->nfields; i++){
|
|
210
|
+
t_pg_coder *p_coder = this->convs[i].cconv;
|
|
211
|
+
if( p_coder )
|
|
212
|
+
pg_gc_location(p_coder->coder_obj);
|
|
186
213
|
}
|
|
187
214
|
}
|
|
188
215
|
|
|
189
216
|
static void
|
|
190
|
-
pg_tmbc_free(
|
|
217
|
+
pg_tmbc_free( void *_this )
|
|
191
218
|
{
|
|
219
|
+
t_tmbc *this = (t_tmbc *)_this;
|
|
192
220
|
/* allocated but not initialized ? */
|
|
193
221
|
if( this == (t_tmbc *)&pg_typemap_funcs ) return;
|
|
194
222
|
xfree( this );
|
|
195
223
|
}
|
|
196
224
|
|
|
225
|
+
static const rb_data_type_t pg_tmbc_type = {
|
|
226
|
+
"PG::TypeMapByColumn",
|
|
227
|
+
{
|
|
228
|
+
pg_tmbc_mark,
|
|
229
|
+
pg_tmbc_free,
|
|
230
|
+
pg_tmbc_memsize,
|
|
231
|
+
pg_compact_callback(pg_tmbc_compact),
|
|
232
|
+
},
|
|
233
|
+
&pg_typemap_type,
|
|
234
|
+
0,
|
|
235
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | PG_RUBY_TYPED_FROZEN_SHAREABLE,
|
|
236
|
+
};
|
|
237
|
+
|
|
197
238
|
static VALUE
|
|
198
239
|
pg_tmbc_s_allocate( VALUE klass )
|
|
199
240
|
{
|
|
200
241
|
/* Use pg_typemap_funcs as interim struct until #initialize is called. */
|
|
201
|
-
return
|
|
242
|
+
return TypedData_Wrap_Struct( klass, &pg_tmbc_type, (t_tmbc *)&pg_typemap_funcs );
|
|
202
243
|
}
|
|
203
244
|
|
|
204
245
|
VALUE
|
|
205
|
-
pg_tmbc_allocate()
|
|
246
|
+
pg_tmbc_allocate(void)
|
|
206
247
|
{
|
|
207
248
|
return pg_tmbc_s_allocate(rb_cTypeMapByColumn);
|
|
208
249
|
}
|
|
@@ -221,19 +262,19 @@ pg_tmbc_allocate()
|
|
|
221
262
|
static VALUE
|
|
222
263
|
pg_tmbc_init(VALUE self, VALUE conv_ary)
|
|
223
264
|
{
|
|
224
|
-
|
|
265
|
+
long i;
|
|
225
266
|
t_tmbc *this;
|
|
226
267
|
int conv_ary_len;
|
|
227
268
|
|
|
228
|
-
|
|
269
|
+
rb_check_frozen(self);
|
|
229
270
|
Check_Type(conv_ary, T_ARRAY);
|
|
230
|
-
conv_ary_len =
|
|
271
|
+
conv_ary_len = RARRAY_LENINT(conv_ary);
|
|
231
272
|
this = xmalloc(sizeof(t_tmbc) + sizeof(struct pg_tmbc_converter) * conv_ary_len);
|
|
232
273
|
/* Set nfields to 0 at first, so that GC mark function doesn't access uninitialized memory. */
|
|
233
274
|
this->nfields = 0;
|
|
234
275
|
this->typemap.funcs = pg_tmbc_funcs;
|
|
235
|
-
this->typemap.default_typemap
|
|
236
|
-
|
|
276
|
+
RB_OBJ_WRITE(self, &this->typemap.default_typemap, pg_typemap_all_strings);
|
|
277
|
+
RTYPEDDATA_DATA(self) = this;
|
|
237
278
|
|
|
238
279
|
for(i=0; i<conv_ary_len; i++)
|
|
239
280
|
{
|
|
@@ -242,11 +283,12 @@ pg_tmbc_init(VALUE self, VALUE conv_ary)
|
|
|
242
283
|
if( obj == Qnil ){
|
|
243
284
|
/* no type cast */
|
|
244
285
|
this->convs[i].cconv = NULL;
|
|
245
|
-
} else if( rb_obj_is_kind_of(obj, rb_cPG_Coder) ){
|
|
246
|
-
Data_Get_Struct(obj, t_pg_coder, this->convs[i].cconv);
|
|
247
286
|
} else {
|
|
248
|
-
|
|
249
|
-
|
|
287
|
+
t_pg_coder *p_coder;
|
|
288
|
+
/* Check argument type and store the coder pointer */
|
|
289
|
+
TypedData_Get_Struct(obj, t_pg_coder, &pg_coder_type, p_coder);
|
|
290
|
+
RB_OBJ_WRITTEN(self, Qnil, p_coder->coder_obj);
|
|
291
|
+
this->convs[i].cconv = p_coder;
|
|
250
292
|
}
|
|
251
293
|
}
|
|
252
294
|
|
|
@@ -266,7 +308,7 @@ static VALUE
|
|
|
266
308
|
pg_tmbc_coders(VALUE self)
|
|
267
309
|
{
|
|
268
310
|
int i;
|
|
269
|
-
t_tmbc *this =
|
|
311
|
+
t_tmbc *this = RTYPEDDATA_DATA( self );
|
|
270
312
|
VALUE ary_coders = rb_ary_new();
|
|
271
313
|
|
|
272
314
|
for( i=0; i<this->nfields; i++){
|
|
@@ -282,7 +324,7 @@ pg_tmbc_coders(VALUE self)
|
|
|
282
324
|
}
|
|
283
325
|
|
|
284
326
|
void
|
|
285
|
-
init_pg_type_map_by_column()
|
|
327
|
+
init_pg_type_map_by_column(void)
|
|
286
328
|
{
|
|
287
329
|
s_id_decode = rb_intern("decode");
|
|
288
330
|
s_id_encode = rb_intern("encode");
|
|
@@ -71,16 +71,12 @@ pg_tmbmt_typecast_query_param( t_typemap *p_typemap, VALUE param_value, int fiel
|
|
|
71
71
|
|
|
72
72
|
obj = rb_funcall(ask_for_coder, rb_intern("call"), 1, param_value);
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}else{
|
|
77
|
-
rb_raise(rb_eTypeError, "argument %d has invalid type %s (should be nil or some kind of PG::Coder)",
|
|
78
|
-
field+1, rb_obj_classname( obj ));
|
|
79
|
-
}
|
|
74
|
+
/* Check argument type and store the coder pointer */
|
|
75
|
+
TypedData_Get_Struct(obj, t_pg_coder, &pg_coder_type, p_coder);
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
if( !p_coder ){
|
|
83
|
-
t_typemap *default_tm =
|
|
79
|
+
t_typemap *default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
84
80
|
return default_tm->funcs.typecast_query_param( default_tm, param_value, field );
|
|
85
81
|
}
|
|
86
82
|
|
|
@@ -90,24 +86,57 @@ pg_tmbmt_typecast_query_param( t_typemap *p_typemap, VALUE param_value, int fiel
|
|
|
90
86
|
static VALUE
|
|
91
87
|
pg_tmbmt_fit_to_query( VALUE self, VALUE params )
|
|
92
88
|
{
|
|
93
|
-
t_tmbmt *this = (t_tmbmt *)
|
|
89
|
+
t_tmbmt *this = (t_tmbmt *)RTYPEDDATA_DATA(self);
|
|
94
90
|
/* Nothing to check at this typemap, but ensure that the default type map fits. */
|
|
95
|
-
t_typemap *default_tm =
|
|
91
|
+
t_typemap *default_tm = RTYPEDDATA_DATA( this->typemap.default_typemap );
|
|
96
92
|
default_tm->funcs.fit_to_query( this->typemap.default_typemap, params );
|
|
97
93
|
return self;
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
#define GC_MARK_AS_USED(type) \
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
rb_gc_mark_movable( this->coders.ask_##type ); \
|
|
98
|
+
rb_gc_mark_movable( this->coders.coder_obj_##type );
|
|
103
99
|
|
|
104
100
|
static void
|
|
105
|
-
pg_tmbmt_mark(
|
|
101
|
+
pg_tmbmt_mark( void *_this )
|
|
106
102
|
{
|
|
107
|
-
|
|
103
|
+
t_tmbmt *this = (t_tmbmt *)_this;
|
|
104
|
+
pg_typemap_mark(&this->typemap);
|
|
108
105
|
FOR_EACH_MRI_TYPE( GC_MARK_AS_USED );
|
|
109
106
|
}
|
|
110
107
|
|
|
108
|
+
static size_t
|
|
109
|
+
pg_tmbmt_memsize( const void *_this )
|
|
110
|
+
{
|
|
111
|
+
const t_tmbmt *this = (const t_tmbmt *)_this;
|
|
112
|
+
return sizeof(*this);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#define GC_COMPACT(type) \
|
|
116
|
+
pg_gc_location( this->coders.ask_##type ); \
|
|
117
|
+
pg_gc_location( this->coders.coder_obj_##type );
|
|
118
|
+
|
|
119
|
+
static void
|
|
120
|
+
pg_tmbmt_compact( void *_this )
|
|
121
|
+
{
|
|
122
|
+
t_tmbmt *this = (t_tmbmt *)_this;
|
|
123
|
+
pg_typemap_compact(&this->typemap);
|
|
124
|
+
FOR_EACH_MRI_TYPE( GC_COMPACT );
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static const rb_data_type_t pg_tmbmt_type = {
|
|
128
|
+
"PG::TypeMapByMriType",
|
|
129
|
+
{
|
|
130
|
+
pg_tmbmt_mark,
|
|
131
|
+
RUBY_TYPED_DEFAULT_FREE,
|
|
132
|
+
pg_tmbmt_memsize,
|
|
133
|
+
pg_compact_callback(pg_tmbmt_compact),
|
|
134
|
+
},
|
|
135
|
+
&pg_typemap_type,
|
|
136
|
+
0,
|
|
137
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
|
138
|
+
};
|
|
139
|
+
|
|
111
140
|
#define INIT_VARIABLES(type) \
|
|
112
141
|
this->coders.coder_##type = NULL; \
|
|
113
142
|
this->coders.ask_##type = Qnil; \
|
|
@@ -119,7 +148,7 @@ pg_tmbmt_s_allocate( VALUE klass )
|
|
|
119
148
|
t_tmbmt *this;
|
|
120
149
|
VALUE self;
|
|
121
150
|
|
|
122
|
-
self =
|
|
151
|
+
self = TypedData_Make_Struct( klass, t_tmbmt, &pg_tmbmt_type, this );
|
|
123
152
|
this->typemap.funcs.fit_to_result = pg_typemap_fit_to_result;
|
|
124
153
|
this->typemap.funcs.fit_to_query = pg_tmbmt_fit_to_query;
|
|
125
154
|
this->typemap.funcs.fit_to_copy_get = pg_typemap_fit_to_copy_get;
|
|
@@ -140,7 +169,7 @@ pg_tmbmt_s_allocate( VALUE klass )
|
|
|
140
169
|
this->coders.coder_##type = NULL; \
|
|
141
170
|
this->coders.ask_##type = Qnil; \
|
|
142
171
|
}else if(rb_obj_is_kind_of(coder, rb_cPG_Coder)){ \
|
|
143
|
-
|
|
172
|
+
TypedData_Get_Struct(coder, t_pg_coder, &pg_coder_type, this->coders.coder_##type); \
|
|
144
173
|
this->coders.ask_##type = Qnil; \
|
|
145
174
|
}else if(RB_TYPE_P(coder, T_SYMBOL)){ \
|
|
146
175
|
this->coders.coder_##type = NULL; \
|
|
@@ -188,7 +217,7 @@ pg_tmbmt_s_allocate( VALUE klass )
|
|
|
188
217
|
static VALUE
|
|
189
218
|
pg_tmbmt_aset( VALUE self, VALUE mri_type, VALUE coder )
|
|
190
219
|
{
|
|
191
|
-
t_tmbmt *this =
|
|
220
|
+
t_tmbmt *this = RTYPEDDATA_DATA( self );
|
|
192
221
|
char *p_mri_type;
|
|
193
222
|
|
|
194
223
|
p_mri_type = StringValueCStr(mri_type);
|
|
@@ -220,7 +249,7 @@ static VALUE
|
|
|
220
249
|
pg_tmbmt_aref( VALUE self, VALUE mri_type )
|
|
221
250
|
{
|
|
222
251
|
VALUE coder;
|
|
223
|
-
t_tmbmt *this =
|
|
252
|
+
t_tmbmt *this = RTYPEDDATA_DATA( self );
|
|
224
253
|
char *p_mri_type;
|
|
225
254
|
|
|
226
255
|
p_mri_type = StringValueCStr(mri_type);
|
|
@@ -248,7 +277,7 @@ pg_tmbmt_aref( VALUE self, VALUE mri_type )
|
|
|
248
277
|
static VALUE
|
|
249
278
|
pg_tmbmt_coders( VALUE self )
|
|
250
279
|
{
|
|
251
|
-
t_tmbmt *this =
|
|
280
|
+
t_tmbmt *this = RTYPEDDATA_DATA( self );
|
|
252
281
|
VALUE hash_coders = rb_hash_new();
|
|
253
282
|
|
|
254
283
|
FOR_EACH_MRI_TYPE( ADD_TO_HASH );
|
|
@@ -257,7 +286,7 @@ pg_tmbmt_coders( VALUE self )
|
|
|
257
286
|
}
|
|
258
287
|
|
|
259
288
|
void
|
|
260
|
-
init_pg_type_map_by_mri_type()
|
|
289
|
+
init_pg_type_map_by_mri_type(void)
|
|
261
290
|
{
|
|
262
291
|
/*
|
|
263
292
|
* Document-class: PG::TypeMapByMriType < PG::TypeMap
|