]> arthur.barton.de Git - netatalk.git/commitdiff
Rename dalloc_add to dalloc_add_copy
authorFrank Lahm <franklahm@googlemail.com>
Tue, 25 Sep 2012 18:48:55 +0000 (20:48 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 25 Sep 2012 18:48:55 +0000 (20:48 +0200)
etc/afpd/spotlight.c
etc/afpd/spotlight_marshalling.c
etc/afpd/spotlight_module.c
include/atalk/dalloc.h
libatalk/talloc/dalloc.c

index a57a15f45ad7eaee7f9720b9088ddbd099b1b631..4b5fdd248d5363c78c85547b1870532456bc9f98 100644 (file)
@@ -159,36 +159,36 @@ static int sl_rpc_fetchPropertiesForContext(const AFPObj *obj, const DALLOC_CTX
 
     /* key/val 1 */
     s = talloc_strdup(dict, "kMDSStoreMetaScopes");
-    dalloc_add(dict, &s, char *);
+    dalloc_add_copy(dict, &s, char *);
 
     array = talloc_zero(dict, sl_array_t);
     s = talloc_strdup(array, "kMDQueryScopeComputer");
-    dalloc_add(array, &s, char *);
-    dalloc_add(dict, array, sl_array_t);
+    dalloc_add_copy(array, &s, char *);
+    dalloc_add_copy(dict, array, sl_array_t);
 
     /* key/val 2 */
     s = talloc_strdup(dict, "kMDSStorePathScopes");
-    dalloc_add(dict, &s, char *);
+    dalloc_add_copy(dict, &s, char *);
 
     array = talloc_zero(dict, sl_array_t);
     s = talloc_strdup(array, v->v_path);
-    dalloc_add(array, &s, char *);
-    dalloc_add(dict, array, sl_array_t);
+    dalloc_add_copy(array, &s, char *);
+    dalloc_add_copy(dict, array, sl_array_t);
 
     /* key/val 3 */
     s = talloc_strdup(dict, "kMDSStoreUUID");
-    dalloc_add(dict, &s, char *);
+    dalloc_add_copy(dict, &s, char *);
 
     memcpy(uuid.sl_uuid, v->v_uuid, 16);
-    dalloc_add(dict, &uuid, sl_uuid_t);
+    dalloc_add_copy(dict, &uuid, sl_uuid_t);
 
     /* key/val 4 */
     s = talloc_strdup(dict, "kMDSStoreHasPersistentUUID");
-    dalloc_add(dict, &s, char *);
+    dalloc_add_copy(dict, &s, char *);
     sl_bool_t b = true;
-    dalloc_add(dict, &b, sl_bool_t);
+    dalloc_add_copy(dict, &b, sl_bool_t);
 
-    dalloc_add(reply, dict, sl_dict_t);
+    dalloc_add_copy(reply, dict, sl_dict_t);
 
 EC_CLEANUP:
     EC_EXIT;
@@ -231,8 +231,8 @@ static int sl_rpc_openQuery(AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *re
 EC_CLEANUP:
     array = talloc_zero(reply, sl_array_t);
     uint64_t sl_res = ret == 0 ? 0 : UINT64_MAX;
-    dalloc_add(array, &sl_res, uint64_t);
-    dalloc_add(reply, array, sl_array_t);
+    dalloc_add_copy(array, &sl_res, uint64_t);
+    dalloc_add_copy(reply, array, sl_array_t);
 
     EC_EXIT;
 }
@@ -246,7 +246,7 @@ static int sl_rpc_fetchQueryResultsForContext(const AFPObj *obj, const DALLOC_CT
 
     array = talloc_zero(reply, sl_array_t);
     uint64_t sl_res = 0;
-    dalloc_add(array, &sl_res, uint64_t);
+    dalloc_add_copy(array, &sl_res, uint64_t);
     
     /* Context */
     EC_NULL_LOG (uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1) );
@@ -265,7 +265,7 @@ static int sl_rpc_fetchQueryResultsForContext(const AFPObj *obj, const DALLOC_CT
 
 EC_CLEANUP:
 
-    dalloc_add(reply, array, sl_array_t);
+    dalloc_add_copy(reply, array, sl_array_t);
 
     EC_EXIT;
 }
@@ -409,61 +409,42 @@ int main(int argc, char **argv)
 
     LOG(log_info, logtype_sl, "Start");
 
-    i = 2;
-    dalloc_add(dd, &i, uint64_t);
-
     i = 1;
-    dalloc_add(dd, &i, uint64_t);
-
-
+    dalloc_add_copy(dd, &i, uint64_t);
     char *str = talloc_strdup(dd, "hello world");
-    dalloc_add(dd, &str, char *);
-
+    dalloc_add_copy(dd, &str, char *);
     sl_bool_t b = true;
-    dalloc_add(dd, &b, sl_bool_t);
-
-    b = false;
-    dalloc_add(dd, &b, sl_bool_t);
-
+    dalloc_add_copy(dd, &b, sl_bool_t);
 
     /* add a nested array */
     DALLOC_CTX *nested = talloc_zero(dd, DALLOC_CTX);
     i = 3;
-    dalloc_add(nested, &i, uint64_t);
-    dalloc_add(dd, nested, DALLOC_CTX);
+    dalloc_add_copy(nested, &i, uint64_t);
+    dalloc_add_copy(dd, nested, DALLOC_CTX);
 
-#if 0
     /* test an allocated CNID array */
     uint64_t id = 16;
     sl_cnids_t *cnids = talloc_zero(dd, sl_cnids_t);
     cnids->ca_cnids = talloc_zero(cnids, DALLOC_CTX);
     cnids->ca_unkn1 = 1;
-    dalloc_add(cnids->ca_cnids, &id, uint64_t);
-    dalloc_add(dd, cnids, sl_cnids_t);
-#endif
+    dalloc_add_copy(cnids->ca_cnids, &id, uint64_t);
+    dalloc_add_copy(dd, cnids, sl_cnids_t);
 
     /* Now the Spotlight types */
-    sl_array_t *sl_arrary = talloc_zero(dd, sl_array_t);
+    sl_array_t *sl_array = talloc_zero(dd, sl_array_t);
     i = 0x1234;
-    dalloc_add(sl_arrary, &i, uint64_t);
+    dalloc_add_copy(sl_array, &i, uint64_t);
     i = 0x5678;
-    dalloc_add(sl_arrary, &i, uint64_t);
+    dalloc_add_copy(sl_array, &i, uint64_t);
 
-#if 0
     sl_dict_t *sl_dict = talloc_zero(dd, sl_dict_t);
     i = 0xffff;
-    dalloc_add(sl_dict, &i, uint64_t);
-    dalloc_add(sl_arrary, sl_dict, sl_dict_t);
-#endif
+    dalloc_add_copy(sl_dict, &i, uint64_t);
+    dalloc_add_copy(sl_array, sl_dict, sl_dict_t);
 
-    dalloc_add(dd, sl_arrary, sl_array_t);
+    dalloc_add_copy(dd, sl_array, sl_array_t);
     dd_dump(dd, 0);
 
-    uint64_t *int1, *int2;
-    EC_NULL_LOG (int1 = dalloc_get(dd, "DALLOC_CTX", 6, "uint64_t", 0) );
-    EC_NULL_LOG (int2 = dalloc_get(dd, "DALLOC_CTX", 6, "uint64_t", 1) );
-    LOG(log_debug, logtype_sl, "ctx1: 0x%" PRIx64 ", ctx2: 0x%" PRIx64, *int1, *int2);
-
     /* now parse a real spotlight packet */
     if (argc > 1) {
         char ibuf[8192];
index b74b4f9c925fd40f7a6a2c198b8d2f160c88f863..f291fc1cc4c555760846eca69538a0e3149c555a 100644 (file)
@@ -328,7 +328,7 @@ static int sl_unpack_ints(DALLOC_CTX *query, const char *buf, int offset, uint e
     i = 0;
     while (i++ < count) {
         query_data64 = sl_unpack_uint64(buf, offset, encoding);
-        dalloc_add(query, &query_data64, uint64_t);
+        dalloc_add_copy(query, &query_data64, uint64_t);
         offset += 8;
     }
 
@@ -350,7 +350,7 @@ static int sl_unpack_date(DALLOC_CTX *query, const char *buf, int offset, uint e
         query_data64 = sl_unpack_uint64(buf, offset, encoding) >> 24;
         t.tv_sec = query_data64 - SPOTLIGHT_TIME_DELTA;
         t.tv_usec = 0;
-        dalloc_add(query, &t, sl_time_t);
+        dalloc_add_copy(query, &t, sl_time_t);
         offset += 8;
     }
 
@@ -369,7 +369,7 @@ static int sl_unpack_uuid(DALLOC_CTX *query, const char *buf, int offset, uint e
     i = 0;
     while (i++ < count) {
         memcpy(uuid.sl_uuid, buf + offset, 16);
-        dalloc_add(query, &uuid, sl_uuid_t);
+        dalloc_add_copy(query, &uuid, sl_uuid_t);
         offset += 16;
     }
 
@@ -409,7 +409,7 @@ static int sl_unpack_floats(DALLOC_CTX *query, const char *buf, int offset, uint
             ieee_fp_union.w[1] = RIVAL(buf, offset);
 #endif
         }
-        dalloc_add(query, &ieee_fp_union.d, double);
+        dalloc_add_copy(query, &ieee_fp_union.d, double);
         offset += 8;
     }
 
@@ -439,11 +439,11 @@ static int sl_unpack_CNID(DALLOC_CTX *query, const char *buf, int offset, int le
 
     while (count --) {
         query_data64 = sl_unpack_uint64(buf, offset, encoding);
-        dalloc_add(cnids.ca_cnids, &query_data64, uint64_t);
+        dalloc_add_copy(cnids.ca_cnids, &query_data64, uint64_t);
         offset += 8;
     }
 
-    dalloc_add(query, &cnids, sl_cnids_t);
+    dalloc_add_copy(query, &cnids, sl_cnids_t);
 
 EC_CLEANUP:
     EC_EXIT;
@@ -515,13 +515,13 @@ static int sl_unpack_cpx(DALLOC_CTX *query,
     case SQ_CPX_TYPE_ARRAY:
         sl_array = talloc_zero(query, sl_array_t);
         EC_NEG1_LOG( roffset = sl_unpack_loop(sl_array, buf, offset, cpx_query_count, toc_offset, encoding) );
-        dalloc_add(query, sl_array, sl_array_t);
+        dalloc_add_copy(query, sl_array, sl_array_t);
         break;
 
     case SQ_CPX_TYPE_DICT:
         sl_dict = talloc_zero(query, sl_dict_t);
         EC_NEG1_LOG( roffset = sl_unpack_loop(sl_dict, buf, offset, cpx_query_count, toc_offset, encoding) );
-        dalloc_add(query, sl_dict, sl_dict_t);
+        dalloc_add_copy(query, sl_dict, sl_dict_t);
         break;
 
     case SQ_CPX_TYPE_STRING:
@@ -540,7 +540,7 @@ static int sl_unpack_cpx(DALLOC_CTX *query,
             EC_NEG1( convert_string_allocate(CH_UCS2, CH_UTF8, buf + offset + (mark_exists ? 18 : 16), slen, &p) );
         }
 
-        dalloc_add(query, &p, char *);
+        dalloc_add_copy(query, &p, char *);
         roffset += qlen;
         break;
 
@@ -552,7 +552,7 @@ static int sl_unpack_cpx(DALLOC_CTX *query,
         } else {
             sl_fm = talloc_zero(query, sl_filemeta_t);
             EC_NEG1_LOG( sl_unpack(sl_fm, buf + offset + 8) );
-            dalloc_add(query, sl_fm, sl_filemeta_t);
+            dalloc_add_copy(query, sl_fm, sl_filemeta_t);
         }
         roffset += qlen;
         break;
@@ -612,13 +612,13 @@ static int sl_unpack_loop(DALLOC_CTX *query,
                 EC_FAIL;
             nil = 0;
             for (i = 0; i < subcount; i++)
-                dalloc_add(query, &nil, sl_nil_t);
+                dalloc_add_copy(query, &nil, sl_nil_t);
             offset += query_length;
             count -= subcount;
             break;
         case SQ_TYPE_BOOL:
             b = query_data64 >> 32;
-            dalloc_add(query, &b, sl_bool_t);
+            dalloc_add_copy(query, &b, sl_bool_t);
             offset += query_length;
             count--;
             break;
index 1d19a32218581c556b69534c5def045f851a58ce..df914a3f2b069fe19a09fc3567a9d13b3892b931 100644 (file)
@@ -148,10 +148,10 @@ static int add_filemeta(DALLOC_CTX *reqinfo, const int metacount, sl_array_t *fm
     meta = talloc_zero(fm_array, sl_array_t);
 
     while (i--) {
-        dalloc_add(meta, &nil, sl_nil_t);
+        dalloc_add_copy(meta, &nil, sl_nil_t);
     }
 
-    dalloc_add(fm_array, meta, sl_array_t);
+    dalloc_add_copy(fm_array, meta, sl_array_t);
 
 EC_CLEANUP:
     EC_EXIT;
@@ -184,7 +184,7 @@ static int sl_mod_fetch_result(void *p)
     /* Prepare FileMeta */
     fm = talloc_zero(slq->slq_reply, sl_filemeta_t);
     fm_array = talloc_zero(fm, sl_array_t);
-    dalloc_add(fm, fm_array, sl_array_t);
+    dalloc_add_copy(fm, fm_array, sl_array_t);
 
     while (tracker_sparql_cursor_next(slq->slq_tracker_cursor, NULL, &error)) {
         EC_NULL_LOG( path = tracker_sparql_cursor_get_string(slq->slq_tracker_cursor, 0, NULL) );
@@ -196,11 +196,11 @@ static int sl_mod_fetch_result(void *p)
         }
         LOG(log_debug, logtype_sl, "Result %d: CNID: %" PRIu32 ", path: \"%s\"", i++, ntohl(id), path);
         uint64 = ntohl(id);
-        dalloc_add(cnids->ca_cnids, &uint64, uint64_t);
+        dalloc_add_copy(cnids->ca_cnids, &uint64, uint64_t);
         add_filemeta(slq->slq_reqinfo, slq->slq_metacount, fm_array, id, path);
     }
-    dalloc_add(slq->slq_reply, cnids, sl_cnids_t);
-    dalloc_add(slq->slq_reply, fm, sl_filemeta_t);
+    dalloc_add_copy(slq->slq_reply, cnids, sl_cnids_t);
+    dalloc_add_copy(slq->slq_reply, fm, sl_filemeta_t);
 
 EC_CLEANUP:
     if (slq->slq_tracker_cursor)
index a9ce782d23fff166ce42181b8f354f05fe631d5c..8784f9eb0f16911010fc98ef361ea29da3f73264 100644 (file)
@@ -26,10 +26,11 @@ typedef struct {
     void **dd_talloc_array;
 } DALLOC_CTX;
 
-/* Use dalloc_add() macro, not this function */
+/* Use dalloc_add_copy() macro, not this function */
 extern int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size);
 
-#define dalloc_add(d, obj, type) dalloc_add_talloc_chunk((d), talloc((d), type), (obj), sizeof(type));
+#define dalloc_add_copy(d, obj, type) dalloc_add_talloc_chunk((d), talloc((d), type), (obj), sizeof(type));
+#define dalloc_add(d, obj, type) dalloc_add_talloc_chunk((d), NULL, (obj), 0);
 extern void *dalloc_get(const DALLOC_CTX *d, ...);
 extern void *dalloc_value_for_key(const DALLOC_CTX *d, ...);
 extern int dalloc_size(DALLOC_CTX *d);
index 7f4ffd36a1f5d16e307f6cd950fa1a63057834cf..37af665c1b8556a09f608ea6578b8a4d9287decf 100644 (file)
 #include <atalk/bstrlib.h>
 #include <atalk/dalloc.h>
 
-/* Use dalloc_add() macro, not this function */
+/* Use dalloc_add_copy() macro, not this function */
 int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size)
 {
-    AFP_ASSERT(talloc_chunk);
-
-    dd->dd_talloc_array = talloc_realloc(dd, dd->dd_talloc_array, void *, talloc_array_length(dd->dd_talloc_array) + 1);
-    memcpy(talloc_chunk, obj, size);
-    dd->dd_talloc_array[talloc_array_length(dd->dd_talloc_array) - 1] = talloc_chunk;
+    if (talloc_chunk) {
+        /* Called from dalloc_add_copy() macro */
+        dd->dd_talloc_array = talloc_realloc(dd,
+                                             dd->dd_talloc_array,
+                                             void *,
+                                             talloc_array_length(dd->dd_talloc_array) + 1);
+        memcpy(talloc_chunk, obj, size);
+        dd->dd_talloc_array[talloc_array_length(dd->dd_talloc_array) - 1] = talloc_chunk;
+    } else {
+        /* Called from dalloc_add() macro */
+        dd->dd_talloc_array = talloc_realloc(dd,
+                                             dd->dd_talloc_array,
+                                             void *,
+                                             talloc_array_length(dd->dd_talloc_array) + 1);
+        dd->dd_talloc_array[talloc_array_length(dd->dd_talloc_array) - 1] = obj;
 
+    }
     return 0;
 }