From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 2776EBC6B for ; Thu, 10 Jan 2008 22:41:07 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAADIghkfC2fJWnmdsb2JhbACQHwEBAQEHBAYHChiBFJd5 X-IronPort-AV: E=Sophos;i="4.24,268,1196636400"; d="scan'208";a="7656963" Received: from anchor-post-36.mail.demon.net ([194.217.242.86]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Jan 2008 22:41:06 +0100 Received: from orion.metastack.com ([80.177.38.218]) by anchor-post-36.mail.demon.net with esmtp (Exim 4.67) id 1JD598-000Cxr-Jy for caml-list@yquem.inria.fr; Thu, 10 Jan 2008 21:41:06 +0000 Received: from countertenor (cpc3-cmbg6-0-0-cust100.cmbg.cable.ntl.com [81.101.140.101]) (authenticated bits=0) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id m0ALS6cS030989 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Thu, 10 Jan 2008 21:28:07 GMT From: "David Allsopp" To: References: <200801101709.14110.jon@ffconsultancy.com><20080110203534.GB12491@stratocaster.home> <200801102124.26245.jon@ffconsultancy.com> Subject: RE: [Caml-list] Hash clash in polymorphic variants Date: Thu, 10 Jan 2008 21:40:38 -0000 Organization: MetaStack Solutions Ltd. Message-ID: <003a01c853d1$718d8730$9201a8c0@countertenor> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AchTzodlVKLw48txRcungf+iqbuigQAAj7gQ In-Reply-To: <200801102124.26245.jon@ffconsultancy.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Scanned-By: MIMEDefang 2.63 on 172.16.28.218 X-Spam: no; 0.00; hash:01 variants:01 constructors:01 avoided:01 clashing:01 hash:01 variants:01 translating:01 enum:01 bindings:01 clashing:01 clashes:01 bindings:01 10,:98 polymorphic:01 Jon Harrop wrote: > On Thursday 10 January 2008 20:35:34 Eric Cooper wrote: > > On Thu, Jan 10, 2008 at 05:09:13PM +0000, Jon Harrop wrote: > > > ISTR advice that constructors sharing the first few characters should > > > be avoided in order to reduce the likelihood of clashing hash values > > > for polymorphic variants. Is that right? > > > > I don't think it's worth worrying about. > > > > I wrote a program a while ago to look into this. I never saw any > > "human-sensible" collisions (between two identifiers that a person > > might have chosen). And if you're producing gensyms in a program, you > > can just check ahead of time. > > I'm interested in automatically translating the GL_* enum from OpenGL into > polymorphic variants. So although it is generated code I have little > control over it, e.g. I cannot change the translation as OpenGL gets > extended because > code will already be using the existing names. > > Still, maybe I'm over-reacting. ;-) I presume you're worried about the bindings clashing internally rather than someone who uses the library happening to use a variant that clashes? You can do something about it - when you're generating your bindings, you can use the hash_variant() C function to detect the collisions yourself. If you detect one, you can either issue *your own* warning while generating the bindings allowing you to specify specific renaming for the program generating your bindings or you could append digits to the names until the collisions disappear (which is likely, though not guaranteed, to happen quickly). It's slightly ugly, but then the possibility of collisions in the first place is IMHO ugly too! David