From: Michal Rokos Date: 2002-08-27T22:59:00+09:00 Subject: Re: [Cleanup?] File (struct stat handling) Hello, On Sat, Aug 24, 2002 at 09:33:35AM +0900, Yukihiro Matsumoto wrote: > Why should we use memcpy instead of struct assigmnent? > The concept of the second chunk is accepted. > The third chunk is not. Now, I see what's wrong on my patch. Thanks nobu, matz. (Sometimes I need to think more before sending...) Let me know, please, if it is OK to commit: Index: file.c =================================================================== RCS file: /src/ruby/file.c,v retrieving revision 1.105 diff -u -p -r1.105 file.c --- file.c 2002/08/21 15:47:54 1.105 +++ file.c 2002/08/23 12:46:08 @@ -2007,8 +2007,12 @@ rb_stat_init(obj, fname) if (stat(RSTRING(fname)->ptr, &st) == -1) { rb_sys_fail(RSTRING(fname)->ptr); } + if (DATA_PTR(obj)) { + free(DATA_PTR(obj)); + DATA_PTR(obj) = NULL; + } nst = ALLOC(struct stat); - *nst = st; + memcpy(nst, &st, sizeof(struct stat)); DATA_PTR(obj) = nst; return Qnil; Thank you Michal -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Michal Rokos Czech Technical University, Prague E-mail:m.rokos@sh.cvut.cz ICQ:36118339 Jabber:majkl@jabber.cz -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-