From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: hash-table-{to, from}-alist Date: Wed, 26 Nov 2008 15:16:41 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <861vwygpc6.fsf@lifelogs.com> References: <863aknitfg.fsf@lifelogs.com> <20080830051807.GB9625@tomas> <86bpwe9su5.fsf@lifelogs.com> <867i6z1jo5.fsf_-_@lifelogs.com> <86ej14vhvg.fsf@lifelogs.com> <20081122054510.GA28298@tomas> <873ahkkkt5.fsf@xemacs.org> <20081122152126.GA4142@tomas> <87vdufk6do.fsf@xemacs.org> <867i6tt4yz.fsf@lifelogs.com> <87bpw4k1z6.fsf@xemacs.org> <86bpw3d829.fsf@lifelogs.com> <87k5ari5jh.fsf@xemacs.org> <86prkiiia2.fsf@lifelogs.com> <86ej0ygr5j.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1227734294 15425 80.91.229.12 (26 Nov 2008 21:18:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Nov 2008 21:18:14 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 26 22:19:17 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L5Rmu-00075E-4s for ged-emacs-devel@m.gmane.org; Wed, 26 Nov 2008 22:19:08 +0100 Original-Received: from localhost ([127.0.0.1]:52563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5Rlk-0006Wd-2w for ged-emacs-devel@m.gmane.org; Wed, 26 Nov 2008 16:17:56 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L5Rlf-0006WQ-RS for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:17:51 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L5Rle-0006W4-W1 for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:17:51 -0500 Original-Received: from [199.232.76.173] (port=35939 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5Rle-0006W0-Qm for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:17:50 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:55947 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L5Rle-00072F-C1 for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:17:50 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L5RlX-00080n-BL for emacs-devel@gnu.org; Wed, 26 Nov 2008 21:17:43 +0000 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 26 Nov 2008 21:17:43 +0000 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 26 Nov 2008 21:17:43 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 125 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:/OBddmr7WS004+p9WOpT2/oo1LQ= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:106209 Archived-At: On Wed, 26 Nov 2008 14:37:28 -0600 Ted Zlatanov wrote: TZ> On Wed, 26 Nov 2008 13:10:38 -0500 Stefan Monnier wrote: SM> The print code does 2 passes over the data: a first one to collect the SM> set of objects it's going to print, and a second to do the actual print. SM> This 2-pass approach is done to handle cycles and sharing (so that when SM> an object appears several times in the output, we know it right when we SM> print the first occurrence). IIUC your patch only patches the second SM> pass, but not the first. TZ> I'll research this, thanks for explaining. The patch below does all the previously discussed formatting plus detection of circular references and Davis Herring's suggestion of skipping the first preliminary space. The old-style hashtable printout is disabled with an #ifdef, so only the new style is available. I tested it quite a bit, especially with compound data members, and it seems to work all right. If this patch is OK (Stefan, please make the call since you've been looking at it) I'll go on to the reading code. Thanks Ted Index: print.c =================================================================== RCS file: /sources/emacs/emacs/src/print.c,v retrieving revision 1.253 diff -c -r1.253 print.c *** print.c 31 Jul 2008 05:33:53 -0000 1.253 --- print.c 26 Nov 2008 21:15:18 -0000 *************** *** 1341,1346 **** --- 1341,1347 ---- loop: if (STRINGP (obj) || CONSP (obj) || VECTORP (obj) || COMPILEDP (obj) || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) + || HASH_TABLE_P (obj) || (! NILP (Vprint_gensym) && SYMBOLP (obj) && !SYMBOL_INTERNED_P (obj))) *************** *** 1536,1541 **** --- 1537,1543 ---- /* Detect circularities and truncate them. */ if (STRINGP (obj) || CONSP (obj) || VECTORP (obj) || COMPILEDP (obj) || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) + || HASH_TABLE_P (obj) || (! NILP (Vprint_gensym) && SYMBOLP (obj) && !SYMBOL_INTERNED_P (obj))) *************** *** 2036,2041 **** --- 2038,2044 ---- else if (HASH_TABLE_P (obj)) { struct Lisp_Hash_Table *h = XHASH_TABLE (obj); + #if 0 strout ("#test)) { *************** *** 2052,2057 **** --- 2055,2115 ---- sprintf (buf, " 0x%lx", (unsigned long) h); strout (buf, -1, -1, printcharfun, 0); PRINTCHAR ('>'); + #endif + /* + implement a readable output, e.g.: + #s(hash-table size 2 test equal data (k1 v1 k2 v2)) + */ + /* always print the size */ + sprintf (buf, "#s(hash-table size %ld", (long) XVECTOR (h->next)->size); + strout (buf, -1, -1, printcharfun, 0); + + if (!NILP(h->test)) + { + strout (" test ", -1, -1, printcharfun, 0); + print_object (h->test, printcharfun, 0); + } + + if (!NILP(h->weak)) + { + strout (" weakness ", -1, -1, printcharfun, 0); + print_object (h->weak, printcharfun, 0); + } + + if (!NILP(h->rehash_size)) + { + strout (" rehash-size ", -1, -1, printcharfun, 0); + print_object (h->rehash_size, printcharfun, 0); + } + + if (!NILP(h->rehash_threshold)) + { + strout (" rehash-threshold ", -1, -1, printcharfun, 0); + print_object (h->rehash_threshold, printcharfun, 0); + } + + strout (" data ", -1, -1, printcharfun, 0); + + /* print the data here as a plist */ + int i; + int printed=0; + + PRINTCHAR ('('); + for (i = 0; i < HASH_TABLE_SIZE (h); ++i) + if (!NILP (HASH_HASH (h, i))) + { + if (printed) + { + PRINTCHAR (' '); + } + print_object (HASH_KEY (h, i), printcharfun, 0); + PRINTCHAR (' '); + print_object (HASH_VALUE (h, i), printcharfun, 0); + printed = 1; + } + PRINTCHAR (')'); + PRINTCHAR (')'); + } else if (BUFFERP (obj)) {