From 13173213010c96f06b9165b4889ef25e4ad95405 Mon Sep 17 00:00:00 2001 From: "Thien K. M. Bui" Date: Sun, 13 Feb 2022 21:00:16 -0600 Subject: [PATCH] need to fix tfree() --- assignment11-starter/linkedlist | Bin 27520 -> 27440 bytes assignment11-starter/linkedlist.c | 32 ++++++++++-------------------- assignment11-starter/linkedlist.o | Bin 7240 -> 7240 bytes assignment11-starter/talloc.c | 32 ++++-------------------------- assignment11-starter/talloc.o | Bin 6464 -> 5488 bytes 5 files changed, 14 insertions(+), 50 deletions(-) diff --git a/assignment11-starter/linkedlist b/assignment11-starter/linkedlist index b93ae871ec207b7058cb6546a2d186cefb954379..ef261989292ddc251081aa3d677043cb10dc0cc2 100755 GIT binary patch delta 2068 zcmY*aZA?>V6n@{^zPC_HX$6srtTH!?P@yP@fel*(EeL`RYQdpp1Nrb{2u!<=q)gO6 zn9lnCm^zo>vMr0z1iec}B2(Oln$1l7G3SiKZkos@+v<#p#_jH$%N1jj_kGTD&U2o7 z?q@rHqWzcXo)jVcN-%XKk|h!4$GDkhM0Sf4teY3pQ)b8f3FesZR00RL2q)qWh2@<| z?Nc4)-+pYR56=Y;ANjIN8Wl#OBg1wlai2ZiX_qdTKCuV`ly6D(3cIN^oH~V;YGZbo z!N%QNH16&>JDPVxmVZxuoal8%U~)Dj6+y2*V$|}4m`0DtQ0e-{RQvV17;7Q_!Ja5| z$^4dmPF@PgVyxSh3Gc)_^U$@bbk~br$%ME(#XXl?RmDAbU6rn$M^)}!b2}jYQt6z3 z-Cbi5qvhA7^0~(Z9%6mR9S%)^CTjAIfK42%@Ksq319tu*%jW?50j~nKj>vKXC8Q5< zA>c5e7tnD{mi>U8fcpT400#iWAz8i*==)Wc$1x9>AVB{p^aFPO4gG-q_hp;x$HF)m z0Fnn_0O$a`3|Ij;4mk9H$7iL|e(uVOoq8UoWT3_0bFd0wjq~O#8?E5MEGzZ#W3adK zi?H|e+pveYIos+YFtr1wAugk7r?5C$)TB{^E`rQ}lpXRWn7#$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QK2Fh0M{@$#(WRp@8FF^uWk^si@i4_?PH`5(+R zDE%vFT(;sq<-)gk_SAW0vqSnSSBm~%s;2U^;6dpQ)#Nq9QskAPkvUklM#e0Hn@8&8 z!=W8~l{^)a4X?3De(XXp6T|+bh;=?YlU$G0`uNuFYLKaMEfp7e8Q?blR!m zHPX=DzK_^%<;2>xm3tBX0cq}L-g@Ah6lXB+T;MRp9_HmhS|ayhNuELsL$pG>eT9sz z+ol|XMY()uU5E!?T%S|$7@22anuNK^jL*TrI_aE?j0ubmETLIetj{fYnsVi{wdJ?f zmfx!V`TAU4Qf-Tsn|T9!sUB_*n%*6j7CS+e2P`d`B9^dN{SdKki-q4N_PoWk_lWiG z!IL^{eM9;%(O;XQt#7bSrxPenSo}5pJkgXzkLhDX&sely{}<6wi}vc5h+ed4mwrvg zs`9)<#U&aU!@EpYt-Xh~BSx><%`#~_XffE1Oxlh^6nj`Ems3?Ocicqf%MSd~&^%G7 zkq29e3SpD`H`JR(Um*n}m5gpuoWWEwQqc+{mCGv|s+>V&9QKSAvh=>6>P~XFg9^Mj zW(!R=4VHy13lUqe21a19YGQX2^Q~U00T`>p4Jo>bq{SpL<{!00`d#u!7D*NGo;e&9 zW>NO2^^Gm5HH+p^Q45?B=0R;Ui~J0K9_gBon@1K<%>fuazTJ$jl4Q3dUWMCMoUu3+ z4!){>ktvg%T?ne$DY~3%PZ7h&OjbEgWM^Ez|D z#rU54qw_?dEL9kd2>yZmMblyArkhGcZ%`KAKSp(;`5itg-)(+D1cGwY_HX&LtbU+C zuwd%o1LF?h#`L+_*t^a&nd&=E`GL1HgVYZq*9|_d>JIY;$ fwwOuQA{#o&`30HmSR+bz$g>@l!m~@d_x<<>!bo|C diff --git a/assignment11-starter/linkedlist.c b/assignment11-starter/linkedlist.c index 687e7d6..f048cf4 100644 --- a/assignment11-starter/linkedlist.c +++ b/assignment11-starter/linkedlist.c @@ -129,35 +129,23 @@ void display(Value *list) } } -// Return a new list that is the reverse of the one that is passed in. All -// content within the list should be duplicated; there should be no shared -// memory whatsoever between the original list and the new one. Use your -// cons(), car(), and cdr() functions from above -- but be sure that you -// don't end up pointing to memory used by the old list! Hint: this means -// that you'll need to make copies of the Value structs that serve as car -// values for the cons cells in the original list; more specifically, you'll -// want to talloc new space for them on the heap. In the case of a string, -// the strlen() function will come in handy, in addition to strcpy(); note -// that strlen() will not include the null terminator in its count. To use -// these functions, you'll need to include above. - -// FAQ: What if there are nested lists inside that list? - -// ANS: There won't be for this assignment. There will be later, but that will -// be after we've set up an easier way of managing memory. +// Return a new list that is the reverse of the one that is passed in. None of +// the values in the original linked list should be copied this time. Instead, +// create a new linked list of CONS_TYPE nodes whose car values point to the +// corresponding car values in the original list. Value *reverse(Value *list) { // copy over the current values into heap - Value *head = list; - Value *new_head = makeNull(); + Value *current = list; + Value *reverse_list = makeNull(); // at the last node of the list - while (!isNull(head)) + while (!isNull(current)) { - new_head = cons(car(head), new_head); - head = cdr(head); + reverse_list = cons(car(current), reverse_list); + current = cdr(current); } - return new_head; + return reverse_list; } // Return the length of the given list, i.e., the number of cons cells. diff --git a/assignment11-starter/linkedlist.o b/assignment11-starter/linkedlist.o index f156155a37938a07d1787e176df2f9ba7de5dbdb..bab06ac218b9896ba7e03d0776972f16b677a3a6 100644 GIT binary patch delta 241 zcmX?Mal&GQ3afB(X;D#XUI{}{YFTPgacX={X7OeV)-_Dp9VSc+3>-`oD;R))3Cv?- znpgnlb%W%9ybLg}XEHyBr1s3U$m(Z8Rg{2L%mK;4)z6(A%<*=!J*Oliqv7UAuGNg( zxvXMbdsuncyjZ0t3-X9cDYBhnl?C#&BUmN8SjC!H#o4@Bg@FQslO1?6HZS9u#Ln0^ y*;1sOv2F84k?kyuvnOXtnloBXUMOkLs66?hWIdzgkFmJ|WJ`PFkrE8JZFNLZo0jpR6l7p*XIXQ^q?Pdo~2}VZa&5>NI8F`t7 z(^!SM_OSA>d9jL5=I0TWl4U!^DhcGNM6il@u?jV@im-XJ3IGN8Cfo63Y+k`Lft|5? zvZY8ltype == CONS_TYPE) + if (head->type == NULL_TYPE) { - cleanup(head->c.car); - cleanup(head->c.cdr); free(head); } else { - // need to free up the NODES too - switch (head->type) - { - // go inside the address stored at the ptr, and free those as well - case PTR_TYPE: - cleanup(head->p); - free(head); - break; - case INT_TYPE: - free(head); - break; - - case DOUBLE_TYPE: - free(head); - break; - case STR_TYPE: - free(head->s); - free(head); - break; - case NULL_TYPE: - free(head); - break; - default: - printf("what the fuck\n"); - } + free(head->c.car); + free(head->p); + cleanup(head->c.cdr); } } diff --git a/assignment11-starter/talloc.o b/assignment11-starter/talloc.o index 770f60f0c9db55d0cfa6a6b673c674ecd054079c..3ddb030a0993c4e4b22246c53c6cff23b4b91ab3 100644 GIT binary patch delta 1693 zcmZ{kOK2295Qe9FGqXFpnc1Dq&i1aa#X}?-VtjxilDIx1F+PZbkE{yjphQHCg6P3u z7V(7&iKP-0K|LrQf{z>&MM!+$DWV_}1rb3+4~l{Z1x352Yjj4iV5YkNuez#wnx4UF zpC|RyxKkYMj}^U9QFE?0=&ZUTc>r1S(WY=Kcq%_4hX= z3kzT}ZyC7B4{_ed28#MN#!7J2m|VXk$$R%;0={exx<55@a>7=j#M^A%yH|~%GCCWY zqYIKHoX@pW2l;%<;49&5w274m-b8EIG~4LVO`}EEjs3d4R?o_z*`nKWmQh2;Xw&m* z$c&P%4MLCE6uTl5R%l;-L78XZt2v74a^yxLnnB)z?eX!l?cR8S^}_YI$e)%=9J$E1 z7!58WWoN-j6!P6niMSuM9{Hp-uC>CV#OQon&VKw-HW9Hj%om5Qgb2~)9@Dgh^d|KG zLr;e2tAwaFNkKOpqygQ5sg;6F@ZQt$y{|~!Vh@IV{NC1)?o|(D*!-XP9sh|x7Kpb3 z`A;f+hPU}>0ALen_@VxOXicm1RHa9t%NABdDg{!ru)`K`%dTV*cxcz>k!>M1lRQ>5 z!Ac5`ekZk+Jl2aq1JT{2c82IyqR&V@9HQrlz9sd1hz=8dK*WRQ~`~S9K}X z^JSthLT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