Merge lp:~linuxjedi/libdrizzle/5.1-malloc-replace into lp:libdrizzle

Proposed by Andrew Hutchings
Status: Merged
Approved by: Andrew Hutchings
Approved revision: 94
Merged at revision: 91
Proposed branch: lp:~linuxjedi/libdrizzle/5.1-malloc-replace
Merge into: lp:libdrizzle
Diff against target: 735 lines (+180/-159)
12 files modified
libdrizzle-5.1/constants.h (+4/-3)
libdrizzle/binlog.cc (+1/-1)
libdrizzle/column.cc (+3/-22)
libdrizzle/command.cc (+1/-1)
libdrizzle/common.h (+1/-0)
libdrizzle/conn.cc (+24/-4)
libdrizzle/drizzle.cc (+3/-51)
libdrizzle/field.cc (+1/-1)
libdrizzle/handshake.cc (+2/-2)
libdrizzle/result.cc (+5/-37)
libdrizzle/statement.cc (+21/-29)
libdrizzle/structs.h (+114/-8)
To merge this branch: bzr merge lp:~linuxjedi/libdrizzle/5.1-malloc-replace
Reviewer Review Type Date Requested Status
Drizzle Trunk Pending
Review via email: mp+143049@code.launchpad.net

Description of the change

* Switches malloc for new/delete
* Make structs initialize (for new)
* Change fixed 32K net buffer to an auto-growing variable net buffer 1MB -> 1GB
  o Starts at 1MB
  o If packet > buffer size (buffer is full) double buffer size
  o If buffer size >= 1GB bail with error (instead of trying to recv 0 bytes as before)

To post a comment you must log in.
94. By Andrew Hutchings

Get rid of vector include (no longer needed)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdrizzle-5.1/constants.h'
2--- libdrizzle-5.1/constants.h 2012-12-30 20:08:04 +0000
3+++ libdrizzle-5.1/constants.h 2013-01-13 19:37:21 +0000
4@@ -78,7 +78,8 @@
5 #define DRIZZLE_MAX_COLUMN_NAME_SIZE 2048
6 #define DRIZZLE_MAX_DEFAULT_VALUE_SIZE 2048
7 #define DRIZZLE_MAX_PACKET_SIZE UINT32_MAX
8-#define DRIZZLE_MAX_BUFFER_SIZE 32768
9+#define DRIZZLE_MAX_BUFFER_SIZE 1024*1024*1024
10+#define DRIZZLE_DEFAULT_BUFFER_SIZE 1024*1024
11 #define DRIZZLE_BUFFER_COPY_THRESHOLD 8192
12 #define DRIZZLE_MAX_SERVER_VERSION_SIZE 32
13 #define DRIZZLE_MAX_SERVER_EXTRA_SIZE 32
14@@ -86,8 +87,8 @@
15 #define DRIZZLE_STATE_STACK_SIZE 8
16 #define DRIZZLE_ROW_GROW_SIZE 8192
17 #define DRIZZLE_DEFAULT_SOCKET_TIMEOUT 10
18-#define DRIZZLE_DEFAULT_SOCKET_SEND_SIZE 32768
19-#define DRIZZLE_DEFAULT_SOCKET_RECV_SIZE 32768
20+#define DRIZZLE_DEFAULT_SOCKET_SEND_SIZE DRIZZLE_DEFAULT_BUFFER_SIZE
21+#define DRIZZLE_DEFAULT_SOCKET_RECV_SIZE DRIZZLE_DEFAULT_BUFFER_SIZE
22 #define DRIZZLE_MYSQL_PASSWORD_HASH 41
23 #define DRIZZLE_BINLOG_CRC32_LEN 4
24 // If this version or higher then we are doing checksums
25
26=== modified file 'libdrizzle/binlog.cc'
27--- libdrizzle/binlog.cc 2013-01-12 14:14:18 +0000
28+++ libdrizzle/binlog.cc 2013-01-13 19:37:21 +0000
29@@ -221,7 +221,7 @@
30
31 if (con->result->binlog_event == NULL)
32 {
33- con->result->binlog_event= (drizzle_binlog_st*)malloc(sizeof(drizzle_binlog_st));
34+ con->result->binlog_event= new (std::nothrow) drizzle_binlog_st;
35 con->result->binlog_event->data= NULL;
36 }
37 binlog_event= con->result->binlog_event;
38
39=== modified file 'libdrizzle/column.cc'
40--- libdrizzle/column.cc 2013-01-05 10:27:32 +0000
41+++ libdrizzle/column.cc 2013-01-13 19:37:21 +0000
42@@ -56,32 +56,13 @@
43 return NULL;
44 }
45
46- column= (drizzle_column_st*)malloc(sizeof(drizzle_column_st));
47+ column= new (std::nothrow) drizzle_column_st;
48 if (column == NULL)
49 {
50 drizzle_set_error(result->con, __func__, "Failed to allocate.");
51 return NULL;
52 }
53
54- column->result = result;
55- column->options= DRIZZLE_COLUMN_UNUSED;
56- /* SET BELOW: column->next */
57- column->prev = NULL;
58- column->catalog[0] = '\0';
59- column->db[0] = '\0';
60- column->table[0] = '\0';
61- column->orig_table[0] = '\0';
62- column->name[0] = '\0';
63- column->orig_name[0] = '\0';
64- column->charset = DRIZZLE_CHARSET_NONE;
65- column->size = 0;
66- column->max_size = 0;
67- column->type= (drizzle_column_type_t)0;
68- column->flags = 0;
69- column->decimals = 0;
70- /* UNSET: column->default_value */
71- column->default_value_size = 0;
72-
73 column->result= result;
74
75 if (result->column_list)
76@@ -109,7 +90,7 @@
77 if (column->next)
78 column->next->prev= column->prev;
79
80- free(column);
81+ delete column;
82 }
83
84 drizzle_result_st *drizzle_column_drizzle_result(drizzle_column_st *column)
85@@ -341,7 +322,7 @@
86 return DRIZZLE_RETURN_OK;
87 }
88
89- result->column_buffer= (drizzle_column_st*)calloc(result->column_count, sizeof(drizzle_column_st));
90+ result->column_buffer= new (std::nothrow) drizzle_column_st[result->column_count];
91 if (result->column_buffer == NULL)
92 {
93 drizzle_set_error(result->con, __func__, "Failed to allocate.");
94
95=== modified file 'libdrizzle/command.cc'
96--- libdrizzle/command.cc 2013-01-05 10:27:32 +0000
97+++ libdrizzle/command.cc 2013-01-13 19:37:21 +0000
98@@ -91,7 +91,7 @@
99 + strlen(con->db) + 1;
100
101 /* Flush buffer if there is not enough room. */
102- free_size= (size_t)DRIZZLE_MAX_BUFFER_SIZE - (size_t)(start - con->buffer);
103+ free_size= con->buffer_allocation - (size_t)(start - con->buffer);
104 if (free_size < con->packet_size)
105 {
106 drizzle_state_push(con, drizzle_state_write);
107
108=== modified file 'libdrizzle/common.h'
109--- libdrizzle/common.h 2013-01-10 12:04:23 +0000
110+++ libdrizzle/common.h 2013-01-13 19:37:21 +0000
111@@ -44,6 +44,7 @@
112 #include <libdrizzle-5.1/drizzle_client.h>
113
114 #include <cassert>
115+#include <new>
116
117 #ifdef HAVE_FCNTL_H
118 # include <fcntl.h>
119
120=== modified file 'libdrizzle/conn.cc'
121--- libdrizzle/conn.cc 2013-01-12 13:36:22 +0000
122+++ libdrizzle/conn.cc 2013-01-13 19:37:21 +0000
123@@ -1126,7 +1126,7 @@
124 {
125 con->buffer_ptr= con->buffer;
126 }
127- else if ((con->buffer_ptr - con->buffer) > (DRIZZLE_MAX_BUFFER_SIZE / 2))
128+ else if ((size_t)(con->buffer_ptr - con->buffer) > (con->buffer_allocation / 2))
129 {
130 memmove(con->buffer, con->buffer_ptr, con->buffer_size);
131 con->buffer_ptr= con->buffer;
132@@ -1149,7 +1149,27 @@
133
134 while (1)
135 {
136- size_t available_buffer= (size_t)DRIZZLE_MAX_BUFFER_SIZE - ((size_t)(con->buffer_ptr - con->buffer) + con->buffer_size);
137+ size_t available_buffer= con->buffer_allocation - ((size_t)(con->buffer_ptr - con->buffer) + con->buffer_size);
138+ if (available_buffer == 0)
139+ {
140+ if (con->buffer_allocation >= DRIZZLE_MAX_BUFFER_SIZE)
141+ {
142+ drizzle_set_error(con, __func__,
143+ "buffer too small:%zu", con->packet_size + 4);
144+ return DRIZZLE_RETURN_INTERNAL_ERROR;
145+ }
146+ // Shift data to beginning of the buffer then resize
147+ // This means that buffer_ptr isn't screwed up by realloc pointer move
148+ if (con->buffer_ptr != con->buffer)
149+ {
150+ memmove(con->buffer, con->buffer_ptr, con->buffer_size);
151+ }
152+ con->buffer_allocation= con->buffer_allocation * 2;
153+ con->buffer= (unsigned char*)realloc(con->buffer, con->buffer_allocation);
154+ drizzle_log_debug(con, "buffer resized to: %zu", con->buffer_allocation);
155+ con->buffer_ptr= con->buffer;
156+ available_buffer= con->buffer_allocation - con->buffer_size;
157+ }
158
159 #ifdef USE_OPENSSL
160 if (con->ssl_state == DRIZZLE_SSL_STATE_HANDSHAKE_COMPLETE)
161@@ -1166,8 +1186,8 @@
162 errno= translate_windows_error();
163 #endif // defined _WIN32 || defined __CYGWIN__
164
165- drizzle_log_crazy(con, "read fd=%d recv=%zd ssl= %d errno=%s",
166- con->fd, read_size,
167+ drizzle_log_crazy(con, "read fd=%d avail= %zd recv=%zd ssl= %d errno=%s",
168+ con->fd, available_buffer, read_size,
169 (con->ssl_state == DRIZZLE_SSL_STATE_HANDSHAKE_COMPLETE) ? 1 : 0,
170 strerror(errno));
171
172
173=== modified file 'libdrizzle/drizzle.cc'
174--- libdrizzle/drizzle.cc 2013-01-12 13:36:22 +0000
175+++ libdrizzle/drizzle.cc 2013-01-13 19:37:21 +0000
176@@ -169,61 +169,12 @@
177 {
178 drizzle_st *con;
179
180- con= (drizzle_st*)malloc(sizeof(drizzle_st));
181+ con= new (std::nothrow) drizzle_st;
182 if (con == NULL)
183 {
184 return NULL;
185 }
186
187- con->flags.is_shutdown= false;
188- con->options= DRIZZLE_CON_NONE;
189- con->packet_number= 0;
190- con->protocol_version= 0;
191- con->state_current= 0;
192- con->events= 0;
193- con->revents= 0;
194- con->capabilities= DRIZZLE_CAPABILITIES_NONE;
195- con->charset= DRIZZLE_CHARSET_NONE;
196- con->command= DRIZZLE_COMMAND_SLEEP;
197- con->socket_type= DRIZZLE_CON_SOCKET_TCP;
198- con->status= DRIZZLE_CON_STATUS_NONE;
199- con->max_packet_size= DRIZZLE_MAX_PACKET_SIZE;
200- con->result_count= 0;
201- con->thread_id= 0;
202- con->backlog= DRIZZLE_DEFAULT_BACKLOG;
203- con->fd= -1;
204- con->buffer_size= 0;
205- con->command_offset= 0;
206- con->command_size= 0;
207- con->command_total= 0;
208- con->packet_size= 0;
209- con->addrinfo_next= NULL;
210- con->buffer_ptr= con->buffer;
211- con->command_buffer= NULL;
212- con->command_data= NULL;
213- con->context= NULL;
214- con->context_free_fn= NULL;
215- con->result_list= NULL;
216- con->scramble= NULL;
217- /* con->buffer doesn't need to be set */
218- con->db[0]= 0;
219- con->password[0]= 0;
220- /* con->scramble_buffer doesn't need to be set */
221- con->server_version[0]= 0;
222- /* con->state_stack doesn't need to be set */
223- con->user[0]= 0;
224- con->ssl_context= NULL;
225- con->ssl= NULL;
226- con->ssl_state= DRIZZLE_SSL_STATE_NONE;
227- con->error_code= 0;
228- con->verbose= DRIZZLE_VERBOSE_NEVER;
229- con->last_errno= 0;
230- con->timeout= -1;
231- con->log_fn= NULL;
232- con->log_context= NULL;
233- con->sqlstate[0]= '\0';
234- con->last_error[0]= '\0';
235-
236 return con;
237 }
238
239@@ -256,7 +207,8 @@
240 SSL_CTX_free(con->ssl_context);
241 #endif
242
243- free(con);
244+ free(con->buffer);
245+ delete con;
246 }
247
248 drizzle_return_t drizzle_wait(drizzle_st *con)
249
250=== modified file 'libdrizzle/field.cc'
251--- libdrizzle/field.cc 2012-12-29 20:26:36 +0000
252+++ libdrizzle/field.cc 2013-01-13 19:37:21 +0000
253@@ -305,7 +305,7 @@
254 drizzle_return_t drizzle_state_binary_null_read(drizzle_st *con)
255 {
256 con->result->null_bitmap_length= (con->result->column_count+7+2)/8;
257- con->result->null_bitmap= (uint8_t*)malloc(con->result->null_bitmap_length);
258+ con->result->null_bitmap= new uint8_t[con->result->null_bitmap_length];
259 con->buffer_ptr++;
260
261 memcpy(con->result->null_bitmap, con->buffer_ptr, con->result->null_bitmap_length);
262
263=== modified file 'libdrizzle/handshake.cc'
264--- libdrizzle/handshake.cc 2013-01-05 10:27:32 +0000
265+++ libdrizzle/handshake.cc 2013-01-13 19:37:21 +0000
266@@ -240,7 +240,7 @@
267 + 1; /* NULL */
268
269 /* Assume the entire handshake packet will fit in the buffer. */
270- if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE)
271+ if ((con->packet_size + 4) > con->buffer_allocation)
272 {
273 drizzle_set_error(con, "drizzle_state_handshake_server_write",
274 "buffer too small:%zu", con->packet_size + 4);
275@@ -548,7 +548,7 @@
276 + strlen(con->db) + 1;
277
278 /* Assume the entire handshake packet will fit in the buffer. */
279- if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE)
280+ if ((con->packet_size + 4) > con->buffer_allocation)
281 {
282 drizzle_set_error(con, "drizzle_state_handshake_client_write",
283 "buffer too small:%zu", con->packet_size + 4);
284
285=== modified file 'libdrizzle/result.cc'
286--- libdrizzle/result.cc 2012-12-29 16:29:59 +0000
287+++ libdrizzle/result.cc 2013-01-13 19:37:21 +0000
288@@ -55,45 +55,13 @@
289 return NULL;
290 }
291
292- result= (drizzle_result_st*)malloc(sizeof(drizzle_result_st));
293+ result= new (std::nothrow) drizzle_result_st;
294 if (result == NULL)
295 {
296 drizzle_set_error(con, __func__, "Failed to allocate.");
297 return NULL;
298 }
299
300- result->binlog_checksums= false;
301- result->binlog_event= NULL;
302- result->column_list= NULL;
303- result->options= DRIZZLE_RESULT_NONE;
304- result->prev= NULL;
305- result->column_buffer= NULL;
306- result->row= NULL;
307- result->error_code= 0;
308- result->insert_id= 0;
309- result->warning_count= 0;
310- result->affected_rows= 0;
311- result->column_count= 0;
312- result->column_current= 0;
313- result->column= NULL;
314- result->row_count= 0;
315- result->row_current= 0;
316- result->field_current= 0;
317- result->field_total= 0;
318- result->field_offset= 0;
319- result->field_size= 0;
320- result->field= NULL;
321- result->field_buffer= NULL;
322- result->row_list_size= 0;
323- result->row_list= NULL;
324- result->field_sizes= NULL;
325- result->field_sizes_list= NULL;
326- result->info[0]= '\0';
327- result->sqlstate[0]= '\0';
328- result->null_bitmap_list= NULL;
329- result->null_bitmap= NULL;
330- result->binary_rows= false;
331-
332 result->con= con;
333 con->result= result;
334
335@@ -118,7 +86,7 @@
336 if (result->binlog_event != NULL)
337 {
338 free(result->binlog_event->data);
339- free(result->binlog_event);
340+ delete result->binlog_event;
341 }
342
343 for (column= result->column_list; column != NULL; column= result->column_list)
344@@ -126,7 +94,7 @@
345 drizzle_column_free(column);
346 }
347
348- free(result->column_buffer);
349+ delete[] result->column_buffer;
350
351 if (result->options & DRIZZLE_RESULT_BUFFER_ROW)
352 {
353@@ -136,7 +104,7 @@
354 drizzle_row_free(result, result->row_list[x]);
355 if (result->null_bitmap_list != NULL)
356 {
357- free(result->null_bitmap_list[x]);
358+ delete[] result->null_bitmap_list[x];
359 }
360 }
361 if (result->null_bitmap_list != NULL)
362@@ -163,7 +131,7 @@
363 result->next->prev= result->prev;
364 }
365
366- free(result);
367+ delete result;
368 }
369
370 void drizzle_result_free_all(drizzle_st *con)
371
372=== modified file 'libdrizzle/statement.cc'
373--- libdrizzle/statement.cc 2013-01-12 14:14:18 +0000
374+++ libdrizzle/statement.cc 2013-01-13 19:37:21 +0000
375@@ -40,21 +40,13 @@
376
377 drizzle_stmt_st *drizzle_stmt_prepare(drizzle_st *con, const char *statement, size_t size, drizzle_return_t *ret_ptr)
378 {
379- drizzle_stmt_st *stmt= (drizzle_stmt_st*)malloc(sizeof(drizzle_stmt_st));
380+ drizzle_stmt_st *stmt= new (std::nothrow) drizzle_stmt_st;
381 if (stmt == NULL)
382 {
383 *ret_ptr= DRIZZLE_RETURN_MEMORY;
384- drizzle_set_error(con, __func__, "malloc");
385+ drizzle_set_error(con, __func__, "new");
386 return NULL;
387 }
388- stmt->execute_result= NULL;
389- stmt->param_count= 0;
390- stmt->id= 0;
391- stmt->query_params= NULL;
392- stmt->result_params= NULL;
393- stmt->null_bitmap_length= 0;
394- stmt->null_bitmap= NULL;
395- stmt->new_bind= true;
396 con->stmt= stmt;
397 stmt->con= con;
398
399@@ -62,7 +54,7 @@
400 statement, size, size, ret_ptr);
401 if (*ret_ptr != DRIZZLE_RETURN_OK)
402 {
403- free(stmt);
404+ delete stmt;
405 con->stmt= NULL;
406 return NULL;
407 }
408@@ -77,7 +69,7 @@
409 *ret_ptr= drizzle_column_skip(stmt->prepare_result);
410 if ((*ret_ptr != DRIZZLE_RETURN_OK) && (*ret_ptr != DRIZZLE_RETURN_EOF))
411 {
412- free(stmt);
413+ delete stmt;
414 return NULL;
415 }
416 }
417@@ -93,17 +85,17 @@
418 * bitmap mask */
419
420 stmt->null_bitmap_length= (stmt->param_count + 7) / 8;
421- stmt->null_bitmap= (uint8_t*)calloc(stmt->null_bitmap_length, 1);
422+ stmt->null_bitmap= new (std::nothrow) uint8_t[stmt->null_bitmap_length]();
423 if (stmt->null_bitmap == NULL)
424 {
425- free(stmt);
426+ delete stmt;
427 *ret_ptr= DRIZZLE_RETURN_MEMORY;
428- drizzle_set_error(con, __func__, "malloc");
429+ drizzle_set_error(con, __func__, "new");
430 return NULL;
431 }
432
433 /* Also use the parameter count to allocate the parameters */
434- stmt->query_params= (drizzle_bind_st*)calloc(stmt->param_count, sizeof(drizzle_bind_st));
435+ stmt->query_params= new (std::nothrow) drizzle_bind_st[stmt->param_count];
436 stmt->state= DRIZZLE_STMT_PREPARED;
437 stmt->fields= stmt->prepare_result->column_buffer;
438
439@@ -141,10 +133,10 @@
440 + (stmt->param_count * 2) /* Parameter type data */
441 + param_lengths; /* Parameter data */
442
443- buffer = (unsigned char*)malloc(buffer_size);
444+ buffer = new (std::nothrow) unsigned char[buffer_size];
445 if (buffer == NULL)
446 {
447- drizzle_set_error(stmt->con, __func__, "malloc");
448+ drizzle_set_error(stmt->con, __func__, "new");
449 return DRIZZLE_RETURN_MEMORY;
450 }
451 buffer_pos= buffer;
452@@ -274,7 +266,7 @@
453 case DRIZZLE_COLUMN_TYPE_TIME2:
454 default:
455 drizzle_set_error(stmt->con, __func__, "unknown type when filling buffer");
456- free(buffer);
457+ delete[] buffer;
458 return DRIZZLE_RETURN_UNEXPECTED_DATA;
459 break;
460 }
461@@ -296,7 +288,7 @@
462 }
463 else
464 {
465- free(buffer);
466+ delete[] buffer;
467 return ret;
468 }
469
470@@ -309,10 +301,10 @@
471 if (stmt->execute_result->column_count > 0)
472 {
473 ret= drizzle_column_buffer(stmt->execute_result);
474- stmt->result_params= (drizzle_bind_st*)calloc(stmt->execute_result->column_count, sizeof(drizzle_bind_st));
475+ stmt->result_params= new (std::nothrow) drizzle_bind_st[stmt->execute_result->column_count];
476 }
477
478- free(buffer);
479+ delete[] buffer;
480 return ret;
481 }
482
483@@ -336,7 +328,7 @@
484 /* TODO: rework drizzle_command_write so we can send a header and we don't
485 * need this copy
486 * */
487- buffer= (unsigned char*)malloc(len + 6);
488+ buffer= new (std::nothrow) unsigned char[len + 6];
489
490 drizzle_set_byte4(buffer, stmt->id);
491 drizzle_set_byte2(&buffer[4], param_num);
492@@ -348,7 +340,7 @@
493 stmt->con->options= (drizzle_options_t)((uint8_t)stmt->con->options & (uint8_t)~DRIZZLE_CON_NO_RESULT_READ);
494 stmt->query_params[param_num].options.is_long_data= true;
495
496- free(buffer);
497+ delete[] buffer;
498 return ret;
499 }
500
501@@ -379,7 +371,7 @@
502 stmt->execute_result= NULL;
503 }
504 stmt->state= DRIZZLE_STMT_PREPARED;
505- free(stmt->result_params);
506+ delete[] stmt->result_params;
507
508 return ret;
509 }
510@@ -552,7 +544,7 @@
511 return DRIZZLE_RETURN_INVALID_ARGUMENT;
512 }
513
514- free(stmt->null_bitmap);
515+ delete[] stmt->null_bitmap;
516 for (uint16_t x= 0; x < stmt->param_count; x++)
517 {
518 if (stmt->query_params[x].options.is_allocated)
519@@ -560,7 +552,7 @@
520 free(stmt->query_params[x].data);
521 }
522 }
523- free(stmt->query_params);
524+ delete[] stmt->query_params;
525 if (stmt->execute_result)
526 {
527 for (uint16_t x= 0; x < stmt->execute_result->column_count; x++)
528@@ -568,7 +560,7 @@
529 free(stmt->result_params[x].data);
530 free(stmt->result_params[x].converted_data);
531 }
532- free(stmt->result_params);
533+ delete[] stmt->result_params;
534 drizzle_result_free(stmt->execute_result);
535 }
536 if (stmt->prepare_result)
537@@ -581,7 +573,7 @@
538 drizzle_command_write(stmt->con, NULL, DRIZZLE_COMMAND_STMT_CLOSE, buffer, 4,
539 4, &ret);
540 stmt->con->options= (drizzle_options_t)((uint8_t)stmt->con->options & (uint8_t)~DRIZZLE_CON_NO_RESULT_READ);
541- free(stmt);
542+ delete stmt;
543 return ret;
544 }
545
546
547=== modified file 'libdrizzle/structs.h'
548--- libdrizzle/structs.h 2013-01-05 15:56:07 +0000
549+++ libdrizzle/structs.h 2013-01-13 19:37:21 +0000
550@@ -149,8 +149,12 @@
551 */
552 struct drizzle_st
553 {
554- struct {
555+ struct flags_t{
556 bool is_shutdown;
557+
558+ flags_t() :
559+ is_shutdown(false)
560+ { }
561 } flags;
562 uint8_t packet_number;
563 uint8_t protocol_version;
564@@ -187,7 +191,8 @@
565 drizzle_tcp_st tcp;
566 drizzle_uds_st uds;
567 } socket;
568- unsigned char buffer[DRIZZLE_MAX_BUFFER_SIZE];
569+ unsigned char *buffer;
570+ size_t buffer_allocation;
571 char db[DRIZZLE_MAX_DB_SIZE];
572 char password[DRIZZLE_MAX_PASSWORD_SIZE];
573 unsigned char scramble_buffer[DRIZZLE_MAX_SCRAMBLE_SIZE];
574@@ -213,6 +218,58 @@
575 char sqlstate[DRIZZLE_MAX_SQLSTATE_SIZE + 1];
576 char last_error[DRIZZLE_MAX_ERROR_SIZE];
577 drizzle_stmt_st *stmt;
578+
579+ drizzle_st() :
580+ packet_number(0),
581+ protocol_version(0),
582+ state_current(0),
583+ events(0),
584+ revents(0),
585+ capabilities(DRIZZLE_CAPABILITIES_NONE),
586+ charset(DRIZZLE_CHARSET_NONE),
587+ command(DRIZZLE_COMMAND_SLEEP),
588+ options(DRIZZLE_CON_NONE),
589+ socket_type(DRIZZLE_CON_SOCKET_TCP),
590+ status(DRIZZLE_CON_STATUS_NONE),
591+ max_packet_size(DRIZZLE_MAX_PACKET_SIZE),
592+ result_count(0),
593+ thread_id(0),
594+ backlog(DRIZZLE_DEFAULT_BACKLOG),
595+ fd(-1),
596+ buffer_size(0),
597+ command_offset(0),
598+ command_size(0),
599+ command_total(0),
600+ packet_size(0),
601+ addrinfo_next(NULL),
602+ command_buffer(NULL),
603+ command_data(NULL),
604+ context(NULL),
605+ context_free_fn(NULL),
606+ result(NULL),
607+ result_list(NULL),
608+ scramble(NULL),
609+ buffer_allocation(DRIZZLE_DEFAULT_BUFFER_SIZE),
610+ ssl_context(NULL),
611+ ssl(NULL),
612+ ssl_state(DRIZZLE_SSL_STATE_NONE),
613+ error_code(0),
614+ verbose(DRIZZLE_VERBOSE_NEVER),
615+ last_errno(0),
616+ timeout(-1),
617+ log_fn(NULL),
618+ log_context(NULL),
619+ stmt(NULL)
620+ {
621+ db[0]= '\0';
622+ password[0]= '\0';
623+ server_version[0]= '\0';
624+ user[0]= '\0';
625+ sqlstate[0]= '\0';
626+ last_error[0]= '\0';
627+ buffer= (unsigned char*)malloc(DRIZZLE_DEFAULT_BUFFER_SIZE);
628+ buffer_ptr= buffer;
629+ }
630 };
631
632 /**
633@@ -282,10 +339,10 @@
634 field_total(0),
635 field_offset(0),
636 field_size(0),
637- field(),
638- field_buffer(),
639+ field(NULL),
640+ field_buffer(NULL),
641 row_list_size(0),
642- row(),
643+ row(NULL),
644 row_list(NULL),
645 field_sizes(NULL),
646 field_sizes_list(NULL),
647@@ -296,8 +353,8 @@
648 null_bitmap_length(0),
649 binary_rows(false)
650 {
651- info[0]= 0;
652- sqlstate[0]= 0;
653+ info[0]= '\0';
654+ sqlstate[0]= '\0';
655 }
656
657 #endif
658@@ -341,6 +398,26 @@
659 uint8_t decimals;
660 unsigned char default_value[DRIZZLE_MAX_DEFAULT_VALUE_SIZE];
661 size_t default_value_size;
662+
663+ drizzle_column_st() :
664+ result(NULL),
665+ next(NULL),
666+ prev(NULL),
667+ options(DRIZZLE_COLUMN_UNUSED),
668+ charset(DRIZZLE_CHARSET_NONE),
669+ size(0),
670+ max_size(0),
671+ type(DRIZZLE_COLUMN_TYPE_NONE),
672+ flags(DRIZZLE_COLUMN_FLAGS_NONE),
673+ decimals(0),
674+ default_value_size(0)
675+ {
676+ catalog[0]= '\0';
677+ db[0]= '\0';
678+ table[0]= '\0';
679+ orig_table[0] ='\0';
680+ name[0]= '\0';
681+ }
682 };
683
684 struct drizzle_stmt_st
685@@ -357,6 +434,21 @@
686 drizzle_result_st *prepare_result;
687 drizzle_result_st *execute_result;
688 drizzle_column_st *fields;
689+
690+ drizzle_stmt_st() :
691+ con(NULL),
692+ state(DRIZZLE_STMT_NONE),
693+ id(0),
694+ param_count(0),
695+ query_params(NULL),
696+ result_params(NULL),
697+ null_bitmap_length(0),
698+ null_bitmap(NULL),
699+ new_bind(true),
700+ prepare_result(NULL),
701+ execute_result(NULL),
702+ fields(NULL)
703+ { }
704 };
705
706 struct drizzle_bind_st
707@@ -366,13 +458,27 @@
708 uint32_t length;
709 bool is_bound;
710 char *converted_data;
711- struct
712+ struct options_t
713 {
714 bool is_null;
715 bool is_unsigned;
716 bool is_long_data;
717 bool is_allocated;
718+
719+ options_t() :
720+ is_null(false),
721+ is_unsigned(false),
722+ is_long_data(false),
723+ is_allocated(false)
724+ { }
725 } options;
726+ drizzle_bind_st() :
727+ type(DRIZZLE_COLUMN_TYPE_NONE),
728+ data(NULL),
729+ length(0),
730+ is_bound(false),
731+ converted_data(NULL)
732+ { }
733 };
734
735 #ifdef __cplusplus

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: