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

Re: [PATCH 1/4] add generic, type aware object chain walker

From
Nicolas Pitre <nico@cam.org>
Date
Feb 25, 2008, 17:49 UTC
Message-ID
<alpine.LFD.1.00.0802251235510.3167@xanadu.home>
In-Reply-To
<20080225080445.GM8410@spearce.org>
On Mon, 25 Feb 2008, Shawn O. Pearce wrote:
Show 17 quoted lines
> > No, it wouldn't, as object->type is never initialized to OBJ_BAD:
> > $ grep "OBJ_BAD" *.c *.h
> > cache.h:        OBJ_BAD = -1,
> 
> Today that may be true.  OBJ_BAD was created for cases where the
> internal object header parsing code in say sha1_file.c finds a type
> code it doesn't recognize and wants to return it back to the caller.
> This grew out of some of the early pack v4 work.
> 
> It actually happens today when a function that returns an object
> type enum returns failure.  sha1_object_info() is one such function.
> It returns "int" but that int is also really an enum object_type.
> When that function fails it returns -1, which has it happens
> is OBJ_BAD.
> 
> Subtle, yes.  But OBJ_BAD has meaning and is in use today.  Please do
> not use it for "we don't care what it is".

Actually, the reason for OBJ_BAD is possibly even more subtle than that. It is "documented" in commit fef742c4ed though.

The idea is for some function returning an object type to also be able to return an error condition without the overhead and/or hassle of a separate argument. So the object space is returned as a positive value, and error space is negative. The only purpose of OBJ_BAD was to make sure object_type is a signed type in order to avoid issues with compilers which might interpret the C standard in a way that would reduce the enum to its minimal expression such as some "signedlessness".

Nicolas
Previous: Shawn O. PearceNext: Junio C Hamano
Message 14 of 19 in “add generic, type aware object chain walker”
  1. 1/4 add generic, type aware object chain walkerMartin Koegler, Feb 24, 2008
  2. 2/4 builtin-fsck: move away from object-refsMartin Koegler, Feb 24, 2008
  3. 3/4 Remove unused object-ref codeMartin Koegler, Feb 24, 2008
  4. 4/4 builtin-fsck: reports missing parent commitsMartin Koegler, Feb 24, 2008
  5. Shawn O. PearceFeb 25, 2008
  6. Martin KoeglerFeb 25, 2008
  7. Junio C HamanoFeb 25, 2008
  8. Martin KoeglerFeb 25, 2008
  9. Junio C HamanoFeb 25, 2008
  10. Martin KoeglerFeb 25, 2008
  11. Shawn O. PearceFeb 25, 2008
  12. Nicolas PitreFeb 25, 2008
  13. Shawn O. PearceFeb 25, 2008
  14. Nicolas PitreFeb 25, 2008
  15. Junio C HamanoFeb 25, 2008
  16. Martin KoeglerFeb 25, 2008
  17. Junio C HamanoFeb 25, 2008
  18. Martin KoeglerFeb 25, 2008
  19. Shawn O. PearceFeb 25, 2008

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.