* equal? and smob flags
@ 2004-09-06 7:52 Andreas Vögele
2004-09-21 21:40 ` Marius Vollmer
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Vögele @ 2004-09-06 7:52 UTC (permalink / raw)
When comparing smobs of the same type but with different smob flags the
procedure scm_equal_p in eq.c returns #f since the cell types, which
include the smob flags, are not equal.
I'm wondering if this behaviour is really intended. IMHO it would be
more useful to ignore the flags in scm_equal_p when comparing smobs.
Instead developers could decide on their own whether to ignore or
consider the smob flags in their custom comparison function.
The macros SCM_CELL_TYPE and SCM_SMOB_FLAGS are defined in gc.h and
smob.h respectively:
#define SCM_CELL_TYPE(x) SCM_CELL_WORD_0 (x)
#define SCM_SMOB_FLAGS(SCM_CELL_WORD_0 (x) >> 16)
The comparison of smobs with different flags fails because of the
following conditional in scm_equal_p:
if (SCM_CELL_TYPE (x) != SCM_CELL_TYPE (y))
{
...
return SCM_BOOL_F;
}
I don't know if there's existing third-party code that relies on the
fact that the smob flags aren't ignored by scm_equal_p. But if such
code existed it code could be updated easily by adding two lines of
code to the comparison function:
SCM_SMOB_EQUALP (my_tag, my_equalp, x ,y)
{
if (SCM_SMOB_FLAGS (x) != SCM_SMOB_FLAGS (y))
return SCM_BOOL_F;
/* Existing code follows here */
...
}
I've included a patch that changes scm_equal_p so that smobs that
provide their own comparison function are compared before the cell type
is compared:
Index: libguile/eq.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/eq.c,v
retrieving revision 1.51
diff -u -r1.51 eq.c
--- libguile/eq.c 17 Aug 2004 23:19:04 -0000 1.51
+++ libguile/eq.c 6 Sep 2004 07:03:46 -0000
@@ -157,6 +157,15 @@
}
if (SCM_TYP7 (x) == scm_tc7_string && SCM_TYP7 (y) == scm_tc7_string)
return scm_string_equal_p (x, y);
+ if (SCM_TYP7 (x) == scm_tc7_smob && SCM_TYP7 (y) == scm_tc7_smob
+ && SCM_SMOBNUM (x) == SCM_SMOBNUM (y))
+ {
+ int i = SCM_SMOBNUM (x);
+ if (!(i < scm_numsmob))
+ return SCM_BOOL_F;
+ if (scm_smobs[i].equalp)
+ return (scm_smobs[i].equalp) (x, y);
+ }
/* This ensures that types and scm_length are the same. */
if (SCM_CELL_TYPE (x) != SCM_CELL_TYPE (y))
{
@@ -194,16 +203,6 @@
case scm_tc7_vector:
case scm_tc7_wvect:
return scm_vector_equal_p (x, y);
- case scm_tc7_smob:
- {
- int i = SCM_SMOBNUM (x);
- if (!(i < scm_numsmob))
- return SCM_BOOL_F;
- if (scm_smobs[i].equalp)
- return (scm_smobs[i].equalp) (x, y);
- else
- break;
- }
#if SCM_HAVE_ARRAYS
case scm_tc7_bvect: case scm_tc7_uvect: case scm_tc7_ivect:
case scm_tc7_fvect: case scm_tc7_cvect: case scm_tc7_dvect:
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: equal? and smob flags
2004-09-06 7:52 equal? and smob flags Andreas Vögele
@ 2004-09-21 21:40 ` Marius Vollmer
0 siblings, 0 replies; 2+ messages in thread
From: Marius Vollmer @ 2004-09-21 21:40 UTC (permalink / raw)
Cc: guile-devel
Andreas Vögele <voegelas@gmx.net> writes:
> When comparing smobs of the same type but with different smob flags
> the procedure scm_equal_p in eq.c returns #f since the cell types,
> which include the smob flags, are not equal.
>
> I'm wondering if this behaviour is really intended.
No, definitely not. Good catch. I applied your patch.
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-09-21 21:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-06 7:52 equal? and smob flags Andreas Vögele
2004-09-21 21:40 ` Marius Vollmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).