git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Conventions on struct copying?

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 20, 2014, 01:26 UTC
Message-ID
<20140620012608.GA856079@vauxhall.crustytoothpaste.net>
In-Reply-To
<5A7F0CEE2DEC4F1B825568DB8358D397@black>
On Thu, Jun 19, 2014 at 01:22:44PM -0400, Jason Pyeron wrote:
Show 11 quoted lines
> > -----Original Message-----
> > From: Junio C Hamano
> > Sent: Thursday, June 19, 2014 13:11
> > 
> > "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> > 
> > > I don't know of any place we explicitly copy structs like
> > > this,...
> > 
> > which should be a reason enough.  The first concrete guideline is
> > "just imitate the existing code".

Right. The reason I asked is that most of our structures end up containing pointers, so it wouldn't make sense to do the equivalent of a memcpy on them anyways. This is just data, so I thought it might be different. I'll implement an oidcpy function to do the work.

Show 5 quoted lines
> > > but I don't know of any prohibition against it, either.
> > 
> > So now you know ;-).
> 
> To expand, on that do not trust the compiler to do deep copies.
I'm not.  The definition looks like;
  struct object_id {
    unsigned char sha1[20];
  };

I only want it to memcpy those 20 bytes; there's no pointers or anything to complicate it.

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
Previous: Jason Pyeron
Message 4 of 4 in “Conventions on struct copying?”
  1. brian m. carlsonJun 18, 2014
  2. Junio C HamanoJun 19, 2014
  3. Jason PyeronJun 19, 2014
  4. brian m. carlsonJun 20, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.