Changeset: f32ed4206dcb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f32ed4206dcb
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk.h
        gdk/gdk_atoms.c
        monetdb5/mal/mal_atom.c
Branch: default
Log Message:

Cleanup: replace ATOMproperty with new ATOMallocate.
ATOMproperty was called in one place with a fixed set of parameter
beyond the first, so we can simplify that.


diffs (229 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -8,16 +8,16 @@ stdout of test 'exports` in directory 'c
 # gdk
 int ALIGNsetH(BAT *b1, BAT *b2);
 int ALIGNsynced(BAT *b1, BAT *b2);
+int ATOMallocate(const char *nme);
 int ATOMcmp(int id, const void *v_1, const void *v_2);
 ptr ATOMdup(int id, const void *val);
 bte ATOMelmshift(int sz);
 int ATOMformat(int id, const void *val, char **buf);
-int ATOMindex(char *nme);
+int ATOMindex(const char *nme);
 int ATOMlen(int id, const void *v);
 str ATOMname(int id);
 ptr ATOMnil(int id);
 int ATOMprint(int id, const void *val, stream *fd);
-void ATOMproperty(char *nme, char *property, GDKfcn fcn, int val);
 BAT *BATalpha(BAT *b);
 BAT *BATantijoin(BAT *l, BAT *r);
 BAT *BATantiuselect_(BAT *b, const void *tl, const void *th, bit li, bit hi);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1905,7 +1905,7 @@ gdk_export BAT *BBPquickdesc(bat b, int 
  * are described by an atom descriptor.
  *  @multitable @columnfractions 0.08 0.7
  * @item void
- * @tab ATOMproperty    (str   nme, char *property, int (*fcn)(), int val);
+ * @tab ATOMallocate    (str   nme);
  * @item int
  * @tab ATOMindex       (char *nme);
  * @item int
@@ -1957,11 +1957,8 @@ gdk_export BAT *BBPquickdesc(bat b, int 
  * following interface:.
  *
  * @itemize
- * @item @emph{ATOMproperty()} registers a new atom definition, if
- * there is no atom registered yet under that name.  It then installs
- * the attribute of the named property.  Valid names are "size",
- * "align", "null", "fromstr", "tostr", "cmp", "hash", "put", "get",
- * "del", "length" and "heap".
+ * @item @emph{ATOMallocate()} registers a new atom definition if
+ * there is no atom registered yet under that name.
  *
  * @item @emph{ATOMdelete()} unregisters an atom definition.
  *
@@ -2079,8 +2076,8 @@ typedef struct {
 gdk_export atomDesc BATatoms[];
 gdk_export int GDKatomcnt;
 
-gdk_export void ATOMproperty(char *nme, char *property, GDKfcn fcn, int val);
-gdk_export int ATOMindex(char *nme);
+gdk_export int ATOMallocate(const char *nme);
+gdk_export int ATOMindex(const char *nme);
 
 gdk_export str ATOMname(int id);
 gdk_export int ATOMlen(int id, const void *v);
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -124,11 +124,8 @@ batUnfix(const bat *b)
  * support the BAT administration.
  *
  * A new type is incrementally build using the routine
- * ATOMproperty(id, property, function, value).  The parameter id
- * denotes the type name; an entry is created if the type is so far
- * unknown. The property argument is a string identifying the type
- * description property to be updated. Valid property names are size,
- * tostr, fromstr, put, get, cmp, eq, del, hash, null, new, and heap.
+ * ATOMallocate(id).  The parameter id denotes the type name; an entry
+ * is created if the type is so far unknown.
  *
  * The size describes the amount of space to be reserved in the BUN.
  *
@@ -152,27 +149,12 @@ batUnfix(const bat *b)
  * The incremental atom construction uses hardwired properties.  This
  * should be improved later on.
  */
-static int
-align(int n)
-{
-       if (n == 0)
-               return 0;
-       /* successively check bits from the bottom to see if one is set */
-       if (n & 1)
-               return 1;
-       if (n & 2)
-               return 2;
-       if (n & 4)
-               return 4;
-       return 8;
-}
-
-void
-ATOMproperty(str id, str property, GDKfcn arg, int val)
+int
+ATOMallocate(const char *id)
 {
        int t;
 
-       MT_lock_set(&GDKthreadLock, "ATOMproperty");
+       MT_lock_set(&GDKthreadLock, "ATOMallocate");
        t = ATOMindex(id);
 
        if (t < 0) {
@@ -181,92 +163,22 @@ ATOMproperty(str id, str property, GDKfc
                        GDKatomcnt++;
                }
                if (GDKatomcnt == MAXATOMS)
-                       GDKfatal("ATOMproperty: too many types");
+                       GDKfatal("ATOMallocate: too many types");
                if (strlen(id) >= IDLENGTH)
-                       GDKfatal("ATOMproperty: name too long");
+                       GDKfatal("ATOMallocate: name too long");
                memset(BATatoms + t, 0, sizeof(atomDesc));
                strncpy(BATatoms[t].name, id, IDLENGTH);
                BATatoms[t].size = sizeof(int);         /* default */
-               assert_shift_width(ATOMelmshift(BATatoms[t].size), 
BATatoms[t].size);
                BATatoms[t].align = sizeof(int);        /* default */
                BATatoms[t].linear = 1;                 /* default */
                BATatoms[t].storage = t;                /* default */
        }
-       if (strcmp("size", property) == 0) {
-               if (val) {
-                       assert(val <= SHRT_MAX);
-                       BATatoms[t].size = val;
-                       assert_shift_width(ATOMelmshift(BATatoms[t].size), 
BATatoms[t].size);
-                       BATatoms[t].varsized = 0;
-                       BATatoms[t].align = align(val);
-               } else {
-                       BATatoms[t].size = sizeof(var_t);
-                       assert_shift_width(ATOMelmshift(BATatoms[t].size), 
BATatoms[t].size);
-                       BATatoms[t].varsized = 1;
-                       BATatoms[t].align = sizeof(var_t);
-               }
-       } else if (strcmp("linear", property) == 0) {
-               BATatoms[t].linear = val;
-       } else if (strcmp("align", property) == 0) {
-               BATatoms[t].align = val;
-       } else if (strcmp("storage", property) == 0) {
-               BATatoms[t] = BATatoms[val];    /* copy from example */
-               strncpy(BATatoms[t].name, id, IDLENGTH); /* restore name */
-               BATatoms[t].name[IDLENGTH - 1] = 0;
-       } else if (strcmp("fromstr", property) == 0) {
-               BATatoms[t].atomFromStr = (int (*)(const char *, int *, void 
**)) arg;
-       } else if (strcmp("tostr", property) == 0) {
-               BATatoms[t].atomToStr = (int (*)(char **, int *, const void *)) 
arg;
-       } else if (strcmp("read", property) == 0) {
-               BATatoms[t].atomRead = (void *(*)(void *, stream *, size_t)) 
arg;
-       } else if (strcmp("write", property) == 0) {
-               BATatoms[t].atomWrite = (int (*)(const void *, stream *, 
size_t)) arg;
-       } else if (strcmp("fix", property) == 0) {
-               BATatoms[t].atomFix = (int (*)(const void *)) arg;
-       } else if (strcmp("unfix", property) == 0) {
-               BATatoms[t].atomUnfix = (int (*)(const void *)) arg;
-       } else {
-#define atomset(dst,val) oldval = (ptr) dst; if (val == NULL || dst == val) 
goto out; dst = val;
-               ptr oldval = NULL;
-
-               if (strcmp("heap", property) == 0) {
-                       BATatoms[t].size = sizeof(var_t);
-                       assert_shift_width(ATOMelmshift(BATatoms[t].size), 
BATatoms[t].size);
-                       BATatoms[t].varsized = 1;
-                       BATatoms[t].align = sizeof(var_t);
-                       atomset(BATatoms[t].atomHeap, (void (*)(Heap *, 
size_t)) arg);
-               } else if (strcmp("del", property) == 0) {
-                       atomset(BATatoms[t].atomDel, (void (*)(Heap *, var_t 
*)) arg);
-               } else if (strcmp("put", property) == 0) {
-                       atomset(BATatoms[t].atomPut, (var_t (*)(Heap *, var_t 
*, const void *)) arg);
-               } else if (strcmp("null", property) == 0) {
-                       ptr atmnull = ((ptr (*)(void)) arg) ();
-
-                       atomset(BATatoms[t].atomNull, atmnull);
-               }
-               if (oldval)
-                       goto out;
-
-               /* these ADT functions *must* be equal for overloaded types */
-               if (strcmp("cmp", property) == 0) {
-                       atomset(BATatoms[t].atomCmp, (int (*)(const void *, 
const void *)) arg);
-               } else if (strcmp("hash", property) == 0) {
-                       atomset(BATatoms[t].atomHash, (BUN (*)(const void *)) 
arg);
-               } else if (strcmp("length", property) == 0) {
-                       atomset(BATatoms[t].atomLen, (int (*)(const void *)) 
arg);
-               }
-               if (BATatoms[t].storage != t)
-                       GDKerror("ATOMproperty: %s overload of %s violates "
-                                "inheritance from %s.\n", ATOMname(t),
-                                property, ATOMname(BATatoms[t].storage));
-               BATatoms[t].storage = t;        /* critical redefine: undo 
remapping */
-       }
-      out:
-       MT_lock_unset(&GDKthreadLock, "ATOMproperty");
+       MT_lock_unset(&GDKthreadLock, "ATOMallocate");
+       return t;
 }
 
 int
-ATOMindex(str nme)
+ATOMindex(const char *nme)
 {
        int t, j = GDKatomcnt;
 
diff --git a/monetdb5/mal/mal_atom.c b/monetdb5/mal/mal_atom.c
--- a/monetdb5/mal/mal_atom.c
+++ b/monetdb5/mal/mal_atom.c
@@ -234,7 +234,7 @@ int malAtomProperty(MalBlkPtr mb, InstrP
 /*
  * @-
  * Atoms are constructed incrementally in the kernel using the
- * ATOMproperty function. It takes an existing type as a base
+ * ATOMallocate function. It takes an existing type as a base
  * to derive a new one.
  * The most tedisous work is to check the signature types of the functions
  * acceptable for the kernel.
@@ -257,10 +257,9 @@ void malAtomDefinition(stream *out, str 
                return;
        }
 
-       ATOMproperty(name, "", (int (*)()) 0, 0);
        if (strlen(name) >= sizeof(BATatoms[0].name))
                return;
-       i = ATOMindex(name);
+       i = ATOMallocate(name);
        /* overload atom ? */
        if (tpe) {
                BATatoms[i] = BATatoms[tpe];
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to