chiark
/
gitweb
/
~mdw
/
mLib
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
buf: Fix two embarassing bugs found while writing Lisp bindings.
[mLib]
/
atom.c
diff --git
a/atom.c
b/atom.c
index 66e9b570613851d6d21922a7aa807a465dd050f1..ce8295c131c2fdb3f92fdc32c8b99f49f411ccf4 100644
(file)
--- a/
atom.c
+++ b/
atom.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id
: atom.c,v 1.1 2001/01/20 11:50:16 mdw Exp
$
+ * $Id$
*
* Atom management
*
*
* Atom management
*
@@
-27,14
+27,6
@@
* MA 02111-1307, USA.
*/
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: atom.c,v $
- * Revision 1.1 2001/01/20 11:50:16 mdw
- * Implementation of atom tables (for example, as found in X11).
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
@@
-44,6
+36,7
@@
#include "atom.h"
#include "hash.h"
#include "sym.h"
#include "atom.h"
#include "hash.h"
#include "sym.h"
+#include "unihash.h"
/*----- Static variables --------------------------------------------------*/
/*----- Static variables --------------------------------------------------*/
@@
-101,10
+94,11
@@
void atom_destroytable(atom_table *t)
sym_destroy(&t->t);
}
sym_destroy(&t->t);
}
-/* --- @atom_intern@ --- *
+/* --- @atom_intern@
, @atom_nintern@
--- *
*
* Arguments: @atom_table *t@ = pointer to an atom table
* @const char *p@ = pointer to the string to intern
*
* Arguments: @atom_table *t@ = pointer to an atom table
* @const char *p@ = pointer to the string to intern
+ * @size_t n@ = size of the string (for @atom_nintern)
*
* Returns: A pointer to the atom block for the given symbol string.
*
*
* Returns: A pointer to the atom block for the given symbol string.
*
@@
-124,6
+118,18
@@
atom *atom_intern(atom_table *t, const char *p)
return (a);
}
return (a);
}
+atom *atom_nintern(atom_table *t, const char *p, size_t n)
+{
+ atom *a;
+ unsigned f;
+
+ ATOM_RESOLVE(t);
+ a = sym_find(&t->t, p, n, sizeof(atom), &f);
+ if (!f)
+ a->f = 0;
+ return (a);
+}
+
/* --- @atom_gensym@ --- *
*
* Arguments: @atom_table *t@ = pointer to a symbol table
/* --- @atom_gensym@ --- *
*
* Arguments: @atom_table *t@ = pointer to a symbol table
@@
-147,8
+153,8
@@
atom *atom_gensym(atom_table *t)
a = x_alloc(t->t.t.a, sizeof(atom) + sz);
a->b.name = (char *)(a + 1);
memcpy(a->b.name, buf, sz);
a = x_alloc(t->t.t.a, sizeof(atom) + sz);
a->b.name = (char *)(a + 1);
memcpy(a->b.name, buf, sz);
- a->b.len = sz;
-
CRC32(a->b.b.hash, 0
, buf, sz);
+ a->b.len = sz
- 1
;
+
a->b.b.hash = UNIHASH(&unihash_global
, buf, sz);
a->f = ATOMF_GENSYM;
a->b.b.next = t->g;
t->g = &a->b.b;
a->f = ATOMF_GENSYM;
a->b.b.next = t->g;
t->g = &a->b.b;