pg 0.12.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data/BSDL +22 -0
  4. data/ChangeLog +1504 -11
  5. data/Contributors.rdoc +7 -0
  6. data/History.rdoc +181 -3
  7. data/LICENSE +12 -14
  8. data/Manifest.txt +29 -15
  9. data/{BSD → POSTGRES} +0 -0
  10. data/{README.OS_X.rdoc → README-OS_X.rdoc} +0 -0
  11. data/{README.windows.rdoc → README-Windows.rdoc} +0 -0
  12. data/README.ja.rdoc +10 -3
  13. data/README.rdoc +54 -28
  14. data/Rakefile +53 -26
  15. data/Rakefile.cross +235 -196
  16. data/ext/errorcodes.def +931 -0
  17. data/ext/errorcodes.rb +45 -0
  18. data/ext/errorcodes.txt +463 -0
  19. data/ext/extconf.rb +37 -7
  20. data/ext/gvl_wrappers.c +19 -0
  21. data/ext/gvl_wrappers.h +211 -0
  22. data/ext/pg.c +317 -4277
  23. data/ext/pg.h +124 -21
  24. data/ext/pg_connection.c +3642 -0
  25. data/ext/pg_errors.c +89 -0
  26. data/ext/pg_result.c +920 -0
  27. data/lib/pg/connection.rb +86 -0
  28. data/lib/pg/constants.rb +11 -0
  29. data/lib/pg/exceptions.rb +11 -0
  30. data/lib/pg/result.rb +16 -0
  31. data/lib/pg.rb +26 -43
  32. data/sample/array_insert.rb +20 -0
  33. data/sample/async_api.rb +21 -24
  34. data/sample/async_copyto.rb +2 -2
  35. data/sample/async_mixed.rb +56 -0
  36. data/sample/check_conn.rb +21 -0
  37. data/sample/copyfrom.rb +1 -1
  38. data/sample/copyto.rb +1 -1
  39. data/sample/cursor.rb +2 -2
  40. data/sample/disk_usage_report.rb +186 -0
  41. data/sample/issue-119.rb +94 -0
  42. data/sample/losample.rb +6 -6
  43. data/sample/minimal-testcase.rb +17 -0
  44. data/sample/notify_wait.rb +51 -22
  45. data/sample/pg_statistics.rb +294 -0
  46. data/sample/replication_monitor.rb +231 -0
  47. data/sample/test_binary_values.rb +4 -6
  48. data/sample/wal_shipper.rb +434 -0
  49. data/sample/warehouse_partitions.rb +320 -0
  50. data/spec/lib/helpers.rb +70 -23
  51. data/spec/pg/connection_spec.rb +1128 -0
  52. data/spec/{pgresult_spec.rb → pg/result_spec.rb} +142 -47
  53. data/spec/pg_spec.rb +44 -0
  54. data.tar.gz.sig +0 -0
  55. metadata +145 -100
  56. metadata.gz.sig +0 -0
  57. data/GPL +0 -340
  58. data/ext/compat.c +0 -541
  59. data/ext/compat.h +0 -184
  60. data/misc/openssl-pg-segfault.rb +0 -31
  61. data/sample/psql.rb +0 -1181
  62. data/sample/psqlHelp.rb +0 -158
  63. data/sample/test1.rb +0 -60
  64. data/sample/test2.rb +0 -44
  65. data/sample/test4.rb +0 -71
  66. data/spec/m17n_spec.rb +0 -151
  67. data/spec/pgconn_spec.rb +0 -643
@@ -0,0 +1,211 @@
1
+ /*
2
+ * gvl_wrappers.h - Wrapper functions for locking/unlocking the Ruby GVL
3
+ *
4
+ * These are some obscure preprocessor directives that allow to generate
5
+ * drop-in replacement wrapper functions in a declarative manner.
6
+ * These wrapper functions ensure that ruby's GVL is released on each
7
+ * function call and reacquired at the end of the call or in callbacks.
8
+ * This way blocking functions calls don't block concurrent ruby threads.
9
+ *
10
+ * The wrapper of each function is prefixed by "gvl_".
11
+ *
12
+ * Use "gcc -E" to retrieve the generated code.
13
+ */
14
+
15
+ #ifndef __gvl_wrappers_h
16
+ #define __gvl_wrappers_h
17
+
18
+ #if defined(HAVE_RB_THREAD_CALL_WITH_GVL)
19
+ extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
20
+ #endif
21
+
22
+ #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
23
+ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
24
+ rb_unblock_function_t *ubf, void *data2);
25
+ #endif
26
+
27
+ void ubf_cancel_running_command(void *c);
28
+
29
+ #define DEFINE_PARAM_LIST1(type, name) \
30
+ name,
31
+
32
+ #define DEFINE_PARAM_LIST2(type, name) \
33
+ p->params.name,
34
+
35
+ #define DEFINE_PARAM_LIST3(type, name) \
36
+ type name,
37
+
38
+ #define DEFINE_PARAM_DECL(type, name) \
39
+ type name;
40
+
41
+ #define DEFINE_GVL_WRAPPER_STRUCT(name, cancel_params, when_non_void, rettype, lastparamtype, lastparamname) \
42
+ struct gvl_wrapper_##name##_params { \
43
+ struct { \
44
+ FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_DECL) \
45
+ lastparamtype lastparamname; \
46
+ } params; \
47
+ when_non_void( rettype retval; ) \
48
+ };
49
+
50
+ #define DEFINE_GVL_SKELETON(name, cancel_params, when_non_void, rettype, lastparamtype, lastparamname) \
51
+ static void * gvl_##name##_skeleton( void *data ){ \
52
+ struct gvl_wrapper_##name##_params *p = (struct gvl_wrapper_##name##_params*)data; \
53
+ when_non_void( p->retval = ) \
54
+ name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST2) p->params.lastparamname ); \
55
+ return NULL; \
56
+ }
57
+
58
+ #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
59
+ #define DEFINE_GVL_STUB(name, cancel_params, when_non_void, rettype, lastparamtype, lastparamname) \
60
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
61
+ struct gvl_wrapper_##name##_params params = { \
62
+ {FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
63
+ }; \
64
+ rb_thread_call_without_gvl(gvl_##name##_skeleton, &params, cancel_params); \
65
+ when_non_void( return params.retval; ) \
66
+ }
67
+ #else
68
+ #define DEFINE_GVL_STUB(name, cancel_params, when_non_void, rettype, lastparamtype, lastparamname) \
69
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
70
+ return name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
71
+ }
72
+ #endif
73
+
74
+ #define DEFINE_GVL_STUB_DECL(name, cancel_params, when_non_void, rettype, lastparamtype, lastparamname) \
75
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname);
76
+
77
+ #define DEFINE_GVLCB_SKELETON(name, cancel_params, when_non_void, rettype, lastparamtype, lastparamname) \
78
+ static void * gvl_##name##_skeleton( void *data ){ \
79
+ struct gvl_wrapper_##name##_params *p = (struct gvl_wrapper_##name##_params*)data; \
80
+ when_non_void( p->retval = ) \
81
+ name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST2) p->params.lastparamname ); \
82
+ return NULL; \
83
+ }
84
+
85
+ #if defined(HAVE_RB_THREAD_CALL_WITH_GVL)
86
+ #define DEFINE_GVLCB_STUB(name, cancel_params, when_non_void, rettype, lastparamtype, lastparamname) \
87
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
88
+ struct gvl_wrapper_##name##_params params = { \
89
+ {FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
90
+ }; \
91
+ rb_thread_call_with_gvl(gvl_##name##_skeleton, &params); \
92
+ when_non_void( return params.retval; ) \
93
+ }
94
+ #else
95
+ #define DEFINE_GVLCB_STUB(name, cancel_params, when_non_void, rettype, lastparamtype, lastparamname) \
96
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
97
+ return name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
98
+ }
99
+ #endif
100
+
101
+ #define GVL_TYPE_VOID(string)
102
+ #define GVL_TYPE_NONVOID(string) string
103
+
104
+ #define GVL_CANCELABLE ubf_cancel_running_command, conn
105
+ #define GVL_NONCANCELABLE RUBY_UBF_IO, 0
106
+
107
+
108
+ /*
109
+ * Definitions of blocking functions and their parameters
110
+ */
111
+
112
+ #define FOR_EACH_PARAM_OF_PQconnectdb(param)
113
+
114
+ #define FOR_EACH_PARAM_OF_PQconnectStart(param)
115
+
116
+ #define FOR_EACH_PARAM_OF_PQconnectPoll(param)
117
+
118
+ #define FOR_EACH_PARAM_OF_PQreset(param)
119
+
120
+ #define FOR_EACH_PARAM_OF_PQresetStart(param)
121
+
122
+ #define FOR_EACH_PARAM_OF_PQresetPoll(param)
123
+
124
+ #define FOR_EACH_PARAM_OF_PQexec(param) \
125
+ param(PGconn *, conn)
126
+
127
+ #define FOR_EACH_PARAM_OF_PQexecParams(param) \
128
+ param(PGconn *, conn) \
129
+ param(const char *, command) \
130
+ param(int, nParams) \
131
+ param(const Oid *, paramTypes) \
132
+ param(const char * const *, paramValues) \
133
+ param(const int *, paramLengths) \
134
+ param(const int *, paramFormats)
135
+
136
+ #define FOR_EACH_PARAM_OF_PQexecPrepared(param) \
137
+ param(PGconn *, conn) \
138
+ param(const char *, stmtName) \
139
+ param(int, nParams) \
140
+ param(const char * const *, paramValues) \
141
+ param(const int *, paramLengths) \
142
+ param(const int *, paramFormats)
143
+
144
+ #define FOR_EACH_PARAM_OF_PQprepare(param) \
145
+ param(PGconn *, conn) \
146
+ param(const char *, stmtName) \
147
+ param(const char *, query) \
148
+ param(int, nParams)
149
+
150
+ #define FOR_EACH_PARAM_OF_PQdescribePrepared(param) \
151
+ param(PGconn *, conn)
152
+
153
+ #define FOR_EACH_PARAM_OF_PQdescribePortal(param) \
154
+ param(PGconn *, conn)
155
+
156
+ #define FOR_EACH_PARAM_OF_PQgetResult(param)
157
+
158
+ #define FOR_EACH_PARAM_OF_PQputCopyData(param) \
159
+ param(PGconn *, conn) \
160
+ param(const char *, buffer)
161
+
162
+ #define FOR_EACH_PARAM_OF_PQputCopyEnd(param) \
163
+ param(PGconn *, conn)
164
+
165
+ #define FOR_EACH_PARAM_OF_PQgetCopyData(param) \
166
+ param(PGconn *, conn) \
167
+ param(char **, buffer)
168
+
169
+ #define FOR_EACH_PARAM_OF_PQnotifies(param)
170
+
171
+ /* function( name, void_or_nonvoid, returntype, lastparamtype, lastparamname ) */
172
+ #define FOR_EACH_BLOCKING_FUNCTION(function) \
173
+ function(PQconnectdb, GVL_NONCANCELABLE, GVL_TYPE_NONVOID, PGconn *, const char *, conninfo) \
174
+ function(PQconnectStart, GVL_NONCANCELABLE, GVL_TYPE_NONVOID, PGconn *, const char *, conninfo) \
175
+ function(PQconnectPoll, GVL_CANCELABLE, GVL_TYPE_NONVOID, PostgresPollingStatusType, PGconn *, conn) \
176
+ function(PQreset, GVL_CANCELABLE, GVL_TYPE_VOID, void, PGconn *, conn) \
177
+ function(PQresetStart, GVL_CANCELABLE, GVL_TYPE_NONVOID, int, PGconn *, conn) \
178
+ function(PQresetPoll, GVL_CANCELABLE, GVL_TYPE_NONVOID, PostgresPollingStatusType, PGconn *, conn) \
179
+ function(PQexec, GVL_CANCELABLE, GVL_TYPE_NONVOID, PGresult *, const char *, command) \
180
+ function(PQexecParams, GVL_CANCELABLE, GVL_TYPE_NONVOID, PGresult *, int, resultFormat) \
181
+ function(PQexecPrepared, GVL_CANCELABLE, GVL_TYPE_NONVOID, PGresult *, int, resultFormat) \
182
+ function(PQprepare, GVL_CANCELABLE, GVL_TYPE_NONVOID, PGresult *, const Oid *, paramTypes) \
183
+ function(PQdescribePrepared, GVL_CANCELABLE, GVL_TYPE_NONVOID, PGresult *, const char *, stmtName) \
184
+ function(PQdescribePortal, GVL_CANCELABLE, GVL_TYPE_NONVOID, PGresult *, const char *, portalName) \
185
+ function(PQgetResult, GVL_CANCELABLE, GVL_TYPE_NONVOID, PGresult *, PGconn *, conn) \
186
+ function(PQputCopyData, GVL_CANCELABLE, GVL_TYPE_NONVOID, int, int, nbytes) \
187
+ function(PQputCopyEnd, GVL_CANCELABLE, GVL_TYPE_NONVOID, int, const char *, errormsg) \
188
+ function(PQgetCopyData, GVL_CANCELABLE, GVL_TYPE_NONVOID, int, int, async) \
189
+ function(PQnotifies, GVL_CANCELABLE, GVL_TYPE_NONVOID, PGnotify *, PGconn *, conn);
190
+
191
+ FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_STUB_DECL );
192
+
193
+
194
+ /*
195
+ * Definitions of callback functions and their parameters
196
+ */
197
+
198
+ #define FOR_EACH_PARAM_OF_notice_processor_proxy(param) \
199
+ param(void *, arg)
200
+
201
+ #define FOR_EACH_PARAM_OF_notice_receiver_proxy(param) \
202
+ param(void *, arg)
203
+
204
+ /* function( name, void_or_nonvoid, returntype, lastparamtype, lastparamname ) */
205
+ #define FOR_EACH_CALLBACK_FUNCTION(function) \
206
+ function(notice_processor_proxy,, GVL_TYPE_VOID, void, const char *, message) \
207
+ function(notice_receiver_proxy,, GVL_TYPE_VOID, void, const PGresult *, result) \
208
+
209
+ FOR_EACH_CALLBACK_FUNCTION( DEFINE_GVL_STUB_DECL );
210
+
211
+ #endif /* end __gvl_wrappers_h */