1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
15 | |
16 | |
17 | #ifdef USE_PRAGMA_IMPLEMENTATION |
18 | #pragma implementation // gcc: Class implementation |
19 | #endif |
20 | |
21 | #include "mariadb.h" |
22 | #include "sql_list.h" |
23 | |
24 | list_node end_of_list; |
25 | |
26 | void free_list(I_List <i_string_pair> *list) |
27 | { |
28 | i_string_pair *tmp; |
29 | while ((tmp= list->get())) |
30 | delete tmp; |
31 | } |
32 | |
33 | |
34 | void free_list(I_List <i_string> *list) |
35 | { |
36 | i_string *tmp; |
37 | while ((tmp= list->get())) |
38 | delete tmp; |
39 | } |
40 | |
41 | |
42 | bool base_list::copy(const base_list *rhs, MEM_ROOT *mem_root) |
43 | { |
44 | bool error= 0; |
45 | if (rhs->elements) |
46 | { |
47 | /* |
48 | It's okay to allocate an array of nodes at once: we never |
49 | call a destructor for list_node objects anyway. |
50 | */ |
51 | if ((first= (list_node*) alloc_root(mem_root, |
52 | sizeof(list_node) * rhs->elements))) |
53 | { |
54 | elements= rhs->elements; |
55 | list_node *dst= first; |
56 | list_node *src= rhs->first; |
57 | for (; dst < first + elements - 1; dst++, src= src->next) |
58 | { |
59 | dst->info= src->info; |
60 | dst->next= dst + 1; |
61 | } |
62 | /* Copy the last node */ |
63 | dst->info= src->info; |
64 | dst->next= &end_of_list; |
65 | /* Setup 'last' member */ |
66 | last= &dst->next; |
67 | return 0; |
68 | } |
69 | error= 1; |
70 | } |
71 | elements= 0; |
72 | first= &end_of_list; |
73 | last= &first; |
74 | return error; |
75 | } |
76 | |