Merge lp:~chillycreator/drizzle/drizzle-fix into lp:~drizzle-trunk/drizzle/development

Proposed by chico chen
Status: Work in progress
Proposed branch: lp:~chillycreator/drizzle/drizzle-fix
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 128 lines (+27/-16)
1 file modified
drizzled/table.cc (+27/-16)
To merge this branch: bzr merge lp:~chillycreator/drizzle/drizzle-fix
Reviewer Review Type Date Requested Status
Monty Taylor Disapprove
Stewart Smith (community) Disapprove
Review via email: mp+23064@code.launchpad.net

Description of the change

change some "goto label;" to "return function();"

To post a comment you must log in.
Revision history for this message
Stewart Smith (stewart) wrote :

I don't think this especially makes this bit of code easier to read/understand.

create_tmp_table() as a lot of problems, and the gotos aren't anywhere near the top.

the name error_return() is also too generic for a very specific error handling method.

that being said, the code does actually look correct, so good work on that!

review: Disapprove
Revision history for this message
Monty Taylor (mordred) wrote :

I agree with Stewart here. I'm not sure this particularly helps anything.

review: Disapprove

Unmerged revisions

1456. By chillyc <chillyc@chillyc-desktop>

change 'goto err;' to 'return error_return()', make code more OOM

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'drizzled/table.cc'
2--- drizzled/table.cc 2010-03-31 21:15:40 +0000
3+++ drizzled/table.cc 2010-04-09 03:02:15 +0000
4@@ -70,6 +70,7 @@
5 void open_table_error(TableShare *share, int error, int db_errno,
6 myf errortype, int errarg);
7
8+Table* error_return(memory::Root *mem_root_save,Session* session,Table* table);
9 /*************************************************************************/
10
11 /* Get column name from column hash */
12@@ -2351,6 +2352,14 @@
13 internal::fn_format(path, path, drizzle_tmpdir, "", MY_REPLACE_EXT|MY_UNPACK_FILENAME);
14 }
15
16+Table*
17+error_return(memory::Root* mem_root_save,Session * session, Table* table)
18+{
19+ session->mem_root= mem_root_save;
20+ table->free_tmp_table(session);
21+ return NULL;
22+}
23+
24 Table *
25 create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
26 order_st *group, bool distinct, bool save_sum_fields,
27@@ -2535,7 +2544,7 @@
28 false,
29 param->convert_blob_length);
30 if (!new_field)
31- goto err; // Should be OOM
32+ return error_return(mem_root_save,session,table); // Should be OOM
33 tmp_from_field++;
34 reclength+=new_field->pack_length();
35 if (new_field->flags & BLOB_FLAG)
36@@ -2589,7 +2598,7 @@
37 if (!new_field)
38 {
39 if (session->is_fatal_error)
40- goto err; // Got OOM
41+ return error_return(mem_root_save,session,table);
42 continue; // Some kindf of const item
43 }
44 if (type == Item::SUM_FUNC_ITEM)
45@@ -2651,7 +2660,8 @@
46 table->cursor= share->db_type()->getCursor(*share, &table->mem_root);
47 }
48 if (! table->cursor)
49- goto err;
50+ return error_return(mem_root_save,session,table);
51+
52
53
54 if (! using_unique_constraint)
55@@ -2681,8 +2691,8 @@
56 uint32_t alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1);
57 share->rec_buff_length= alloc_length;
58 if (!(table->record[0]= (unsigned char*)
59- alloc_root(&table->mem_root, alloc_length*3)))
60- goto err;
61+ alloc_root(&table->mem_root, alloc_length*3)))
62+ return error_return(mem_root_save,session,table);
63 table->record[1]= table->record[0]+alloc_length;
64 share->default_values= table->record[1]+alloc_length;
65 }
66@@ -2852,7 +2862,8 @@
67 test(maybe_null),
68 field->null_ptr,
69 field->null_bit)))
70- goto err;
71+ return error_return(mem_root_save,session,table);
72+
73 if (maybe_null)
74 {
75 /*
76@@ -2901,7 +2912,8 @@
77 if (!(key_part_info= (KEY_PART_INFO*)
78 alloc_root(&table->mem_root,
79 keyinfo->key_parts * sizeof(KEY_PART_INFO))))
80- goto err;
81+ return error_return(mem_root_save,session,table);
82+
83 memset(key_part_info, 0, keyinfo->key_parts * sizeof(KEY_PART_INFO));
84 table->key_info=keyinfo;
85 keyinfo->key_part=key_part_info;
86@@ -2929,8 +2941,8 @@
87 NULL,
88 table->s,
89 &my_charset_bin);
90- if (!key_part_info->field)
91- goto err;
92+ if (!key_part_info->field)
93+ return error_return(mem_root_save,session,table);
94 key_part_info->field->init(table);
95 key_part_info->key_type= 1; /* binary comparison */
96 key_part_info->type= HA_KEYTYPE_BINARY;
97@@ -2971,25 +2983,24 @@
98 }
99
100 if (session->is_fatal_error) // If end of memory
101- goto err;
102+ return error_return(mem_root_save,session,table);
103+
104 share->db_record_offset= 1;
105 if (share->db_type() == myisam_engine)
106 {
107 if (table->create_myisam_tmp_table(param->keyinfo, param->start_recinfo,
108 &param->recinfo, select_options))
109- goto err;
110+ return error_return(mem_root_save,session,table);
111+
112 }
113 if (table->open_tmp_table())
114- goto err;
115+ return error_return(mem_root_save,session,table);
116+
117
118 session->mem_root= mem_root_save;
119
120 return(table);
121
122-err:
123- session->mem_root= mem_root_save;
124- table->free_tmp_table(session);
125- return NULL;
126 }
127
128 /****************************************************************************/