diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-09-04 16:13:21 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-09-04 16:13:21 +0000 |
commit | a194122be492fbddd8748fe323a648434a866c36 (patch) | |
tree | f39293588b7922faa40f0c6b985a031f8f5cf0ae /girepository | |
parent | 8a2a9f9db169eaaf2a7eede18e0ceba0af44345f (diff) | |
parent | 85d02d59f101f9eb37829b16a81890ef9801824a (diff) | |
download | gobject-introspection-a194122be492fbddd8748fe323a648434a866c36.tar.gz |
merge with GOBJECT_INTROSPECTION_1_37_6baserock/jonathan/fix-giscanner
Diffstat (limited to 'girepository')
30 files changed, 807 insertions, 331 deletions
diff --git a/girepository/cmph-bdz-test.c b/girepository/cmph-bdz-test.c index fdff9d17..92c445f8 100644 --- a/girepository/cmph-bdz-test.c +++ b/girepository/cmph-bdz-test.c @@ -128,7 +128,6 @@ main(int argc, char **argv) { gint ret; - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add_func ("/cmph-bdz/search", test_search); diff --git a/girepository/cmph/bdz.c b/girepository/cmph/bdz.c index a385b152..81cd7151 100755 --- a/girepository/cmph/bdz.c +++ b/girepository/cmph/bdz.c @@ -489,6 +489,10 @@ int bdz_dump(cmph_t *mphf, FILE *fd) cmph_uint32 buflen; register size_t nbytes; bdz_data_t *data = (bdz_data_t *)mphf->data; + cmph_uint32 sizeg; +#ifdef DEBUG + cmph_uint32 i; +#endif __cmph_dump(mphf, fd); hash_state_dump(data->hl, &buf, &buflen); @@ -501,7 +505,7 @@ int bdz_dump(cmph_t *mphf, FILE *fd) nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd); nbytes = fwrite(&(data->r), sizeof(cmph_uint32), (size_t)1, fd); - cmph_uint32 sizeg = (cmph_uint32)ceil(data->n/4.0); + sizeg = (cmph_uint32)ceil(data->n/4.0); nbytes = fwrite(data->g, sizeof(cmph_uint8)*sizeg, (size_t)1, fd); nbytes = fwrite(&(data->k), sizeof(cmph_uint32), (size_t)1, fd); @@ -509,12 +513,11 @@ int bdz_dump(cmph_t *mphf, FILE *fd) nbytes = fwrite(&(data->ranktablesize), sizeof(cmph_uint32), (size_t)1, fd); nbytes = fwrite(data->ranktable, sizeof(cmph_uint32)*(data->ranktablesize), (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } #ifdef DEBUG - cmph_uint32 i; fprintf(stderr, "G: "); for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", GETVALUE(data->g, i)); fprintf(stderr, "\n"); @@ -528,6 +531,9 @@ void bdz_load(FILE *f, cmph_t *mphf) cmph_uint32 buflen, sizeg; register size_t nbytes; bdz_data_t *bdz = (bdz_data_t *)malloc(sizeof(bdz_data_t)); +#ifdef DEBUG + cmph_uint32 i = 0; +#endif DEBUGP("Loading bdz mphf\n"); mphf->data = bdz; @@ -554,13 +560,13 @@ void bdz_load(FILE *f, cmph_t *mphf) bdz->ranktable = (cmph_uint32 *)calloc((size_t)bdz->ranktablesize, sizeof(cmph_uint32)); nbytes = fread(bdz->ranktable, sizeof(cmph_uint32)*(bdz->ranktablesize), (size_t)1, f); - if (nbytes == 0 && ferror(f)) { + if (nbytes == 0 && ferror(f)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return; } #ifdef DEBUG - cmph_uint32 i = 0; + i = 0; fprintf(stderr, "G: "); for (i = 0; i < bdz->n; ++i) fprintf(stderr, "%u ", GETVALUE(bdz->g,i)); fprintf(stderr, "\n"); @@ -639,6 +645,7 @@ void bdz_pack(cmph_t *mphf, void *packed_mphf) { bdz_data_t *data = (bdz_data_t *)mphf->data; cmph_uint8 * ptr = packed_mphf; + cmph_uint32 sizeg; // packing hl type CMPH_HASH hl_type = hash_get_type(data->hl); @@ -665,7 +672,7 @@ void bdz_pack(cmph_t *mphf, void *packed_mphf) *ptr++ = data->b; // packing g - cmph_uint32 sizeg = (cmph_uint32)ceil(data->n/4.0); + sizeg = (cmph_uint32)ceil(data->n/4.0); memcpy(ptr, data->g, sizeof(cmph_uint8)*sizeg); } diff --git a/girepository/cmph/bdz_ph.c b/girepository/cmph/bdz_ph.c index 2e986071..2095f116 100755 --- a/girepository/cmph/bdz_ph.c +++ b/girepository/cmph/bdz_ph.c @@ -452,6 +452,10 @@ int bdz_ph_dump(cmph_t *mphf, FILE *fd) cmph_uint32 sizeg = 0; register size_t nbytes; bdz_ph_data_t *data = (bdz_ph_data_t *)mphf->data; +#ifdef DEBUG + cmph_uint32 i; +#endif + __cmph_dump(mphf, fd); hash_state_dump(data->hl, &buf, &buflen); @@ -466,12 +470,11 @@ int bdz_ph_dump(cmph_t *mphf, FILE *fd) sizeg = (cmph_uint32)ceil(data->n/5.0); nbytes = fwrite(data->g, sizeof(cmph_uint8)*sizeg, (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } #ifdef DEBUG - cmph_uint32 i; fprintf(stderr, "G: "); for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", GETVALUE(data->g, i)); fprintf(stderr, "\n"); @@ -506,7 +509,7 @@ void bdz_ph_load(FILE *f, cmph_t *mphf) bdz_ph->g = (cmph_uint8 *)calloc((size_t)sizeg, sizeof(cmph_uint8)); nbytes = fread(bdz_ph->g, sizeg*sizeof(cmph_uint8), (size_t)1, f); - if (nbytes == 0 && ferror(f)) { + if (nbytes == 0 && ferror(f)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); } return; @@ -556,6 +559,7 @@ void bdz_ph_pack(cmph_t *mphf, void *packed_mphf) { bdz_ph_data_t *data = (bdz_ph_data_t *)mphf->data; cmph_uint8 * ptr = packed_mphf; + cmph_uint32 sizeg; // packing hl type CMPH_HASH hl_type = hash_get_type(data->hl); @@ -571,7 +575,7 @@ void bdz_ph_pack(cmph_t *mphf, void *packed_mphf) ptr += sizeof(data->r); // packing g - cmph_uint32 sizeg = (cmph_uint32)ceil(data->n/5.0); + sizeg = (cmph_uint32)ceil(data->n/5.0); memcpy(ptr, data->g, sizeof(cmph_uint8)*sizeg); } diff --git a/girepository/cmph/bmz.c b/girepository/cmph/bmz.c index 9c6cea00..9573825a 100644 --- a/girepository/cmph/bmz.c +++ b/girepository/cmph/bmz.c @@ -450,6 +450,10 @@ int bmz_dump(cmph_t *mphf, FILE *fd) cmph_uint32 two = 2; //number of hash functions bmz_data_t *data = (bmz_data_t *)mphf->data; register size_t nbytes; +#ifdef DEBUG + cmph_uint32 i; +#endif + __cmph_dump(mphf, fd); nbytes = fwrite(&two, sizeof(cmph_uint32), (size_t)1, fd); @@ -470,12 +474,11 @@ int bmz_dump(cmph_t *mphf, FILE *fd) nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd); nbytes = fwrite(data->g, sizeof(cmph_uint32)*(data->n), (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } #ifdef DEBUG - cmph_uint32 i; fprintf(stderr, "G: "); for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]); fprintf(stderr, "\n"); @@ -515,10 +518,11 @@ void bmz_load(FILE *f, cmph_t *mphf) bmz->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*bmz->n); nbytes = fread(bmz->g, bmz->n*sizeof(cmph_uint32), (size_t)1, f); - if (nbytes == 0 && ferror(f)) { + if (nbytes == 0 && ferror(f)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return; } + #ifdef DEBUG fprintf(stderr, "G: "); for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]); @@ -559,6 +563,7 @@ void bmz_pack(cmph_t *mphf, void *packed_mphf) bmz_data_t *data = (bmz_data_t *)mphf->data; cmph_uint8 * ptr = packed_mphf; + CMPH_HASH h2_type; // packing h1 type CMPH_HASH h1_type = hash_get_type(data->hashes[0]); @@ -570,7 +575,7 @@ void bmz_pack(cmph_t *mphf, void *packed_mphf) ptr += hash_state_packed_size(h1_type); // packing h2 type - CMPH_HASH h2_type = hash_get_type(data->hashes[1]); + h2_type = hash_get_type(data->hashes[1]); *((cmph_uint32 *) ptr) = h2_type; ptr += sizeof(cmph_uint32); @@ -612,18 +617,22 @@ cmph_uint32 bmz_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke { register cmph_uint8 *h1_ptr = packed_mphf; register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr); + register cmph_uint8 *h2_ptr; + register CMPH_HASH h2_type; + register cmph_uint32 *g_ptr, n, h1, h2; + h1_ptr += 4; - register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type); - register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr); + h2_ptr = h1_ptr + hash_state_packed_size(h1_type); + h2_type = *((cmph_uint32 *)h2_ptr); h2_ptr += 4; - register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type)); + g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type)); - register cmph_uint32 n = *g_ptr++; + n = *g_ptr++; - register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n; - register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n; + h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n; + h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n; if (h1 == h2 && ++h2 > n) h2 = 0; return (g_ptr[h1] + g_ptr[h2]); } diff --git a/girepository/cmph/bmz8.c b/girepository/cmph/bmz8.c index 206c48c4..15853c00 100644 --- a/girepository/cmph/bmz8.c +++ b/girepository/cmph/bmz8.c @@ -483,7 +483,7 @@ int bmz8_dump(cmph_t *mphf, FILE *fd) nbytes = fwrite(&(data->m), sizeof(cmph_uint8), (size_t)1, fd); nbytes = fwrite(data->g, sizeof(cmph_uint8)*(data->n), (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } @@ -528,10 +528,11 @@ void bmz8_load(FILE *f, cmph_t *mphf) bmz8->g = (cmph_uint8 *)malloc(sizeof(cmph_uint8)*bmz8->n); nbytes = fread(bmz8->g, bmz8->n*sizeof(cmph_uint8), (size_t)1, f); - if (nbytes == 0 && ferror(f)) { + if (nbytes == 0 && ferror(f)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return; } + #ifdef DEBUG fprintf(stderr, "G: "); for (i = 0; i < bmz8->n; ++i) fprintf(stderr, "%u ", bmz8->g[i]); @@ -571,6 +572,7 @@ void bmz8_pack(cmph_t *mphf, void *packed_mphf) { bmz8_data_t *data = (bmz8_data_t *)mphf->data; cmph_uint8 * ptr = packed_mphf; + CMPH_HASH h2_type; // packing h1 type CMPH_HASH h1_type = hash_get_type(data->hashes[0]); @@ -582,7 +584,7 @@ void bmz8_pack(cmph_t *mphf, void *packed_mphf) ptr += hash_state_packed_size(h1_type); // packing h2 type - CMPH_HASH h2_type = hash_get_type(data->hashes[1]); + h2_type = hash_get_type(data->hashes[1]); *((cmph_uint32 *) ptr) = h2_type; ptr += sizeof(cmph_uint32); @@ -623,18 +625,22 @@ cmph_uint8 bmz8_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke { register cmph_uint8 *h1_ptr = packed_mphf; register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr); + register cmph_uint8 *h2_ptr; + register CMPH_HASH h2_type; + register cmph_uint8 *g_ptr, n, h1, h2; + h1_ptr += 4; - register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type); - register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr); + h2_ptr = h1_ptr + hash_state_packed_size(h1_type); + h2_type = *((cmph_uint32 *)h2_ptr); h2_ptr += 4; - register cmph_uint8 *g_ptr = h2_ptr + hash_state_packed_size(h2_type); + g_ptr = h2_ptr + hash_state_packed_size(h2_type); - register cmph_uint8 n = *g_ptr++; + n = *g_ptr++; - register cmph_uint8 h1 = (cmph_uint8)(hash_packed(h1_ptr, h1_type, key, keylen) % n); - register cmph_uint8 h2 = (cmph_uint8)(hash_packed(h2_ptr, h2_type, key, keylen) % n); + h1 = (cmph_uint8)(hash_packed(h1_ptr, h1_type, key, keylen) % n); + h2 = (cmph_uint8)(hash_packed(h2_ptr, h2_type, key, keylen) % n); DEBUGP("key: %s h1: %u h2: %u\n", key, h1, h2); if (h1 == h2 && ++h2 > n) h2 = 0; return (cmph_uint8)(g_ptr[h1] + g_ptr[h2]); diff --git a/girepository/cmph/brz.c b/girepository/cmph/brz.c index f0c91c4b..cd35c8d8 100755 --- a/girepository/cmph/brz.c +++ b/girepository/cmph/brz.c @@ -128,9 +128,10 @@ cmph_t *brz_new(cmph_config_t *mph, double c) brz_data_t *brzf = NULL; cmph_uint32 i; cmph_uint32 iterations = 20; + brz_config_data_t *brz; DEBUGP("c: %f\n", c); - brz_config_data_t *brz = (brz_config_data_t *)mph->data; + brz = (brz_config_data_t *)mph->data; switch(brz->algo) // validating restrictions over parameter c. { case CMPH_BMZ8: @@ -252,13 +253,14 @@ static int brz_gen_mphf(cmph_config_t *mph) /* Buffers management */ if (memory_usage + keylen + sizeof(keylen) > brz->memory_availability) // flush buffers { + cmph_uint32 value, sum, keylen1; if(mph->verbosity) { fprintf(stderr, "Flushing %u\n", nkeys_in_buffer); } - cmph_uint32 value = buckets_size[0]; - cmph_uint32 sum = 0; - cmph_uint32 keylen1 = 0; + value = buckets_size[0]; + sum = 0; + keylen1 = 0; buckets_size[0] = 0; for(i = 1; i < brz->k; i++) { @@ -312,14 +314,16 @@ static int brz_gen_mphf(cmph_config_t *mph) mph->key_source->dispose(mph->key_source->data, key, keylen); } if (memory_usage != 0) // flush buffers - { + { + cmph_uint32 value; + cmph_uint32 sum, keylen1; if(mph->verbosity) { fprintf(stderr, "Flushing %u\n", nkeys_in_buffer); } - cmph_uint32 value = buckets_size[0]; - cmph_uint32 sum = 0; - cmph_uint32 keylen1 = 0; + value = buckets_size[0]; + sum = 0; + keylen1 = 0; buckets_size[0] = 0; for(i = 1; i < brz->k; i++) { @@ -371,7 +375,7 @@ static int brz_gen_mphf(cmph_config_t *mph) nbytes = fwrite(&(brz->algo), sizeof(brz->algo), (size_t)1, brz->mphf_fd); nbytes = fwrite(&(brz->k), sizeof(cmph_uint32), (size_t)1, brz->mphf_fd); // number of MPHFs nbytes = fwrite(brz->size, sizeof(cmph_uint8)*(brz->k), (size_t)1, brz->mphf_fd); - if (nbytes == 0 && ferror(brz->mphf_fd)) { + if (nbytes == 0 && ferror(brz->mphf_fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } @@ -579,7 +583,7 @@ int brz_dump(cmph_t *mphf, FILE *fd) // Dumping m and the vector offset. nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd); nbytes = fwrite(data->offset, sizeof(cmph_uint32)*(data->k), (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } @@ -648,24 +652,26 @@ void brz_load(FILE *f, cmph_t *mphf) nbytes = fread(&(brz->m), sizeof(cmph_uint32), (size_t)1, f); brz->offset = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*brz->k); nbytes = fread(brz->offset, sizeof(cmph_uint32)*(brz->k), (size_t)1, f); - if (nbytes == 0 && ferror(f)) { + if (nbytes == 0 && ferror(f)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); } + return; } static cmph_uint32 brz_bmz8_search(brz_data_t *brz, const char *key, cmph_uint32 keylen, cmph_uint32 * fingerprint) { register cmph_uint32 h0; + register cmph_uint32 m, n, h1, h2; + register cmph_uint8 mphf_bucket; hash_vector(brz->h0, key, keylen, fingerprint); h0 = fingerprint[2] % brz->k; - register cmph_uint32 m = brz->size[h0]; - register cmph_uint32 n = (cmph_uint32)ceil(brz->c * m); - register cmph_uint32 h1 = hash(brz->h1[h0], key, keylen) % n; - register cmph_uint32 h2 = hash(brz->h2[h0], key, keylen) % n; - register cmph_uint8 mphf_bucket; + m = brz->size[h0]; + n = (cmph_uint32)ceil(brz->c * m); + h1 = hash(brz->h1[h0], key, keylen) % n; + h2 = hash(brz->h2[h0], key, keylen) % n; if (h1 == h2 && ++h2 >= n) h2 = 0; mphf_bucket = (cmph_uint8)(brz->g[h0][h1] + brz->g[h0][h2]); @@ -678,17 +684,20 @@ static cmph_uint32 brz_bmz8_search(brz_data_t *brz, const char *key, cmph_uint32 static cmph_uint32 brz_fch_search(brz_data_t *brz, const char *key, cmph_uint32 keylen, cmph_uint32 * fingerprint) { register cmph_uint32 h0; + register cmph_uint32 m, b, h1, h2; + register double p1, p2; + register cmph_uint8 mphf_bucket; hash_vector(brz->h0, key, keylen, fingerprint); h0 = fingerprint[2] % brz->k; - register cmph_uint32 m = brz->size[h0]; - register cmph_uint32 b = fch_calc_b(brz->c, m); - register double p1 = fch_calc_p1(m); - register double p2 = fch_calc_p2(b); - register cmph_uint32 h1 = hash(brz->h1[h0], key, keylen) % m; - register cmph_uint32 h2 = hash(brz->h2[h0], key, keylen) % m; - register cmph_uint8 mphf_bucket = 0; + m = brz->size[h0]; + b = fch_calc_b(brz->c, m); + p1 = fch_calc_p1(m); + p2 = fch_calc_p2(b); + h1 = hash(brz->h1[h0], key, keylen) % m; + h2 = hash(brz->h2[h0], key, keylen) % m; + mphf_bucket = 0; h1 = mixh10h11h12(b, p1, p2, h1); mphf_bucket = (cmph_uint8)((h2 + brz->g[h0][h1]) % m); return (mphf_bucket + brz->offset[h0]); @@ -741,13 +750,20 @@ void brz_pack(cmph_t *mphf, void *packed_mphf) brz_data_t *data = (brz_data_t *)mphf->data; cmph_uint8 * ptr = packed_mphf; cmph_uint32 i,n; + CMPH_HASH h0_type, h1_type, h2_type; +#if defined (__ia64) || defined (__x86_64__) + cmph_uint64 * g_is_ptr; +#else + cmph_uint32 * g_is_ptr; +#endif + cmph_uint8 * g_i; // packing internal algo type memcpy(ptr, &(data->algo), sizeof(data->algo)); ptr += sizeof(data->algo); // packing h0 type - CMPH_HASH h0_type = hash_get_type(data->h0); + h0_type = hash_get_type(data->h0); memcpy(ptr, &h0_type, sizeof(h0_type)); ptr += sizeof(h0_type); @@ -764,12 +780,12 @@ void brz_pack(cmph_t *mphf, void *packed_mphf) ptr += sizeof(data->c); // packing h1 type - CMPH_HASH h1_type = hash_get_type(data->h1[0]); + h1_type = hash_get_type(data->h1[0]); memcpy(ptr, &h1_type, sizeof(h1_type)); ptr += sizeof(h1_type); // packing h2 type - CMPH_HASH h2_type = hash_get_type(data->h2[0]); + h2_type = hash_get_type(data->h2[0]); memcpy(ptr, &h2_type, sizeof(h2_type)); ptr += sizeof(h2_type); @@ -782,12 +798,12 @@ void brz_pack(cmph_t *mphf, void *packed_mphf) ptr += sizeof(cmph_uint32)*data->k; #if defined (__ia64) || defined (__x86_64__) - cmph_uint64 * g_is_ptr = (cmph_uint64 *)ptr; + g_is_ptr = (cmph_uint64 *)ptr; #else - cmph_uint32 * g_is_ptr = (cmph_uint32 *)ptr; + g_is_ptr = (cmph_uint32 *)ptr; #endif - cmph_uint8 * g_i = (cmph_uint8 *) (g_is_ptr + data->k); + g_i = (cmph_uint8 *) (g_is_ptr + data->k); for(i = 0; i < data->k; i++) { @@ -835,6 +851,7 @@ cmph_uint32 brz_packed_size(cmph_t *mphf) CMPH_HASH h0_type = hash_get_type(data->h0); CMPH_HASH h1_type = hash_get_type(data->h1[0]); CMPH_HASH h2_type = hash_get_type(data->h2[0]); + cmph_uint32 n; size = (cmph_uint32)(2*sizeof(CMPH_ALGO) + 3*sizeof(CMPH_HASH) + hash_state_packed_size(h0_type) + sizeof(cmph_uint32) + sizeof(double) + sizeof(cmph_uint8)*data->k + sizeof(cmph_uint32)*data->k); // pointers to g_is @@ -847,7 +864,7 @@ cmph_uint32 brz_packed_size(cmph_t *mphf) size += hash_state_packed_size(h1_type) * data->k; size += hash_state_packed_size(h2_type) * data->k; - cmph_uint32 n = 0; + n = 0; for(i = 0; i < data->k; i++) { switch(data->algo) @@ -871,47 +888,57 @@ static cmph_uint32 brz_bmz8_search_packed(cmph_uint32 *packed_mphf, const char * { register CMPH_HASH h0_type = *packed_mphf++; register cmph_uint32 *h0_ptr = packed_mphf; + register cmph_uint32 k, h0, m, n, h1, h2; + register cmph_uint32 *offset; + register double c; + register CMPH_HASH h1_type, h2_type; + register cmph_uint8 * size; +#if defined (__ia64) || defined (__x86_64__) + register cmph_uint64 * g_is_ptr; +#else + register cmph_uint32 * g_is_ptr; +#endif + register cmph_uint8 *h1_ptr, *h2_ptr, *g; + register cmph_uint8 mphf_bucket; + packed_mphf = (cmph_uint32 *)(((cmph_uint8 *)packed_mphf) + hash_state_packed_size(h0_type)); - register cmph_uint32 k = *packed_mphf++; + k = *packed_mphf++; - register double c = (double)(*((cmph_uint64*)packed_mphf)); + c = (double)(*((cmph_uint64*)packed_mphf)); packed_mphf += 2; - register CMPH_HASH h1_type = *packed_mphf++; + h1_type = *packed_mphf++; - register CMPH_HASH h2_type = *packed_mphf++; + h2_type = *packed_mphf++; - register cmph_uint8 * size = (cmph_uint8 *) packed_mphf; + size = (cmph_uint8 *) packed_mphf; packed_mphf = (cmph_uint32 *)(size + k); - register cmph_uint32 * offset = packed_mphf; + offset = packed_mphf; packed_mphf += k; - register cmph_uint32 h0; hash_vector_packed(h0_ptr, h0_type, key, keylen, fingerprint); h0 = fingerprint[2] % k; - register cmph_uint32 m = size[h0]; - register cmph_uint32 n = (cmph_uint32)ceil(c * m); + m = size[h0]; + n = (cmph_uint32)ceil(c * m); #if defined (__ia64) || defined (__x86_64__) - register cmph_uint64 * g_is_ptr = (cmph_uint64 *)packed_mphf; + g_is_ptr = (cmph_uint64 *)packed_mphf; #else - register cmph_uint32 * g_is_ptr = packed_mphf; + g_is_ptr = packed_mphf; #endif - register cmph_uint8 * h1_ptr = (cmph_uint8 *) g_is_ptr[h0]; + h1_ptr = (cmph_uint8 *) g_is_ptr[h0]; - register cmph_uint8 * h2_ptr = h1_ptr + hash_state_packed_size(h1_type); + h2_ptr = h1_ptr + hash_state_packed_size(h1_type); - register cmph_uint8 * g = h2_ptr + hash_state_packed_size(h2_type); + g = h2_ptr + hash_state_packed_size(h2_type); - register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n; - register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n; - - register cmph_uint8 mphf_bucket; + h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n; + h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n; if (h1 == h2 && ++h2 >= n) h2 = 0; mphf_bucket = (cmph_uint8)(g[h1] + g[h2]); @@ -925,49 +952,59 @@ static cmph_uint32 brz_fch_search_packed(cmph_uint32 *packed_mphf, const char *k register CMPH_HASH h0_type = *packed_mphf++; register cmph_uint32 *h0_ptr = packed_mphf; + register cmph_uint32 k, h0, m, b, h1, h2; + register double c, p1, p2; + register CMPH_HASH h1_type, h2_type; + register cmph_uint8 *size, *h1_ptr, *h2_ptr, *g; + register cmph_uint32 *offset; +#if defined (__ia64) || defined (__x86_64__) + register cmph_uint64 * g_is_ptr; +#else + register cmph_uint32 * g_is_ptr; +#endif + register cmph_uint8 mphf_bucket; + packed_mphf = (cmph_uint32 *)(((cmph_uint8 *)packed_mphf) + hash_state_packed_size(h0_type)); - register cmph_uint32 k = *packed_mphf++; + k = *packed_mphf++; - register double c = (double)(*((cmph_uint64*)packed_mphf)); + c = (double)(*((cmph_uint64*)packed_mphf)); packed_mphf += 2; - register CMPH_HASH h1_type = *packed_mphf++; + h1_type = *packed_mphf++; - register CMPH_HASH h2_type = *packed_mphf++; + h2_type = *packed_mphf++; - register cmph_uint8 * size = (cmph_uint8 *) packed_mphf; + size = (cmph_uint8 *) packed_mphf; packed_mphf = (cmph_uint32 *)(size + k); - register cmph_uint32 * offset = packed_mphf; + offset = packed_mphf; packed_mphf += k; - register cmph_uint32 h0; - hash_vector_packed(h0_ptr, h0_type, key, keylen, fingerprint); h0 = fingerprint[2] % k; - register cmph_uint32 m = size[h0]; - register cmph_uint32 b = fch_calc_b(c, m); - register double p1 = fch_calc_p1(m); - register double p2 = fch_calc_p2(b); + m = size[h0]; + b = fch_calc_b(c, m); + p1 = fch_calc_p1(m); + p2 = fch_calc_p2(b); #if defined (__ia64) || defined (__x86_64__) - register cmph_uint64 * g_is_ptr = (cmph_uint64 *)packed_mphf; + g_is_ptr = (cmph_uint64 *)packed_mphf; #else - register cmph_uint32 * g_is_ptr = packed_mphf; + g_is_ptr = packed_mphf; #endif - register cmph_uint8 * h1_ptr = (cmph_uint8 *) g_is_ptr[h0]; + h1_ptr = (cmph_uint8 *) g_is_ptr[h0]; - register cmph_uint8 * h2_ptr = h1_ptr + hash_state_packed_size(h1_type); + h2_ptr = h1_ptr + hash_state_packed_size(h1_type); - register cmph_uint8 * g = h2_ptr + hash_state_packed_size(h2_type); + g = h2_ptr + hash_state_packed_size(h2_type); - register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % m; - register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % m; + h1 = hash_packed(h1_ptr, h1_type, key, keylen) % m; + h2 = hash_packed(h2_ptr, h2_type, key, keylen) % m; - register cmph_uint8 mphf_bucket = 0; + mphf_bucket = 0; h1 = mixh10h11h12(b, p1, p2, h1); mphf_bucket = (cmph_uint8)((h2 + g[h1]) % m); return (mphf_bucket + offset[h0]); diff --git a/girepository/cmph/chd.c b/girepository/cmph/chd.c index 71579ee3..46aec52d 100644 --- a/girepository/cmph/chd.c +++ b/girepository/cmph/chd.c @@ -190,9 +190,10 @@ void chd_load(FILE *fd, cmph_t *mphf) DEBUGP("Loading Compressed rank structure, which has %u bytes\n", chd->packed_cr_size); chd->packed_cr = (cmph_uint8 *) calloc((size_t)chd->packed_cr_size, (size_t)1); nbytes = fread(chd->packed_cr, chd->packed_cr_size, (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); } + } int chd_dump(cmph_t *mphf, FILE *fd) @@ -207,13 +208,14 @@ int chd_dump(cmph_t *mphf, FILE *fd) nbytes = fwrite(&data->packed_chd_phf_size, sizeof(cmph_uint32), (size_t)1, fd); nbytes = fwrite(data->packed_chd_phf, data->packed_chd_phf_size, (size_t)1, fd); - DEBUGP("Dumping compressed rank structure with %u bytes to disk\n", buflen); + DEBUGP("Dumping compressed rank structure with %u bytes to disk\n", data->packed_cr_size); nbytes = fwrite(&data->packed_cr_size, sizeof(cmph_uint32), (size_t)1, fd); nbytes = fwrite(data->packed_cr, data->packed_cr_size, (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } + return 1; } diff --git a/girepository/cmph/chd_ph.c b/girepository/cmph/chd_ph.c index 6cd9437a..8356bded 100644 --- a/girepository/cmph/chd_ph.c +++ b/girepository/cmph/chd_ph.c @@ -193,8 +193,9 @@ void chd_ph_config_set_hashfuncs(cmph_config_t *mph, CMPH_HASH *hashfuncs) void chd_ph_config_set_b(cmph_config_t *mph, cmph_uint32 keys_per_bucket) { + chd_ph_config_data_t *chd_ph; assert(mph); - chd_ph_config_data_t *chd_ph = (chd_ph_config_data_t *)mph->data; + chd_ph = (chd_ph_config_data_t *)mph->data; if(keys_per_bucket < 1 || keys_per_bucket >= 15) { keys_per_bucket = 4; @@ -205,8 +206,9 @@ void chd_ph_config_set_b(cmph_config_t *mph, cmph_uint32 keys_per_bucket) void chd_ph_config_set_keys_per_bin(cmph_config_t *mph, cmph_uint32 keys_per_bin) { + chd_ph_config_data_t *chd_ph; assert(mph); - chd_ph_config_data_t *chd_ph = (chd_ph_config_data_t *)mph->data; + chd_ph = (chd_ph_config_data_t *)mph->data; if(keys_per_bin <= 1 || keys_per_bin >= 128) { keys_per_bin = 1; @@ -860,9 +862,10 @@ void chd_ph_load(FILE *fd, cmph_t *mphf) DEBUGP("Reading n and nbuckets\n"); nbytes = fread(&(chd_ph->n), sizeof(cmph_uint32), (size_t)1, fd); nbytes = fread(&(chd_ph->nbuckets), sizeof(cmph_uint32), (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); } + } int chd_ph_dump(cmph_t *mphf, FILE *fd) @@ -889,7 +892,7 @@ int chd_ph_dump(cmph_t *mphf, FILE *fd) // dumping n and nbuckets nbytes = fwrite(&(data->n), sizeof(cmph_uint32), (size_t)1, fd); nbytes = fwrite(&(data->nbuckets), sizeof(cmph_uint32), (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } diff --git a/girepository/cmph/chm.c b/girepository/cmph/chm.c index 3af8c806..36a07a0d 100644 --- a/girepository/cmph/chm.c +++ b/girepository/cmph/chm.c @@ -226,7 +226,7 @@ int chm_dump(cmph_t *mphf, FILE *fd) nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd); nbytes = fwrite(data->g, sizeof(cmph_uint32)*data->n, (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } @@ -270,7 +270,7 @@ void chm_load(FILE *f, cmph_t *mphf) chm->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*chm->n); nbytes = fread(chm->g, chm->n*sizeof(cmph_uint32), (size_t)1, f); - if (nbytes == 0 && ferror(f)) { + if (nbytes == 0 && ferror(f)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return; } @@ -313,6 +313,7 @@ void chm_pack(cmph_t *mphf, void *packed_mphf) { chm_data_t *data = (chm_data_t *)mphf->data; cmph_uint8 * ptr = packed_mphf; + CMPH_HASH h2_type; // packing h1 type CMPH_HASH h1_type = hash_get_type(data->hashes[0]); @@ -324,7 +325,7 @@ void chm_pack(cmph_t *mphf, void *packed_mphf) ptr += hash_state_packed_size(h1_type); // packing h2 type - CMPH_HASH h2_type = hash_get_type(data->hashes[1]); + h2_type = hash_get_type(data->hashes[1]); *((cmph_uint32 *) ptr) = h2_type; ptr += sizeof(cmph_uint32); @@ -370,19 +371,24 @@ cmph_uint32 chm_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke { register cmph_uint8 *h1_ptr = packed_mphf; register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr); + register cmph_uint8 *h2_ptr; + register CMPH_HASH h2_type; + register cmph_uint32 *g_ptr; + register cmph_uint32 n, m, h1, h2; + h1_ptr += 4; - register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type); - register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr); + h2_ptr = h1_ptr + hash_state_packed_size(h1_type); + h2_type = *((cmph_uint32 *)h2_ptr); h2_ptr += 4; - register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type)); + g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type)); - register cmph_uint32 n = *g_ptr++; - register cmph_uint32 m = *g_ptr++; + n = *g_ptr++; + m = *g_ptr++; - register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n; - register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n; + h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n; + h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n; DEBUGP("key: %s h1: %u h2: %u\n", key, h1, h2); if (h1 == h2 && ++h2 >= n) h2 = 0; DEBUGP("key: %s g[h1]: %u g[h2]: %u edges: %u\n", key, g_ptr[h1], g_ptr[h2], m); diff --git a/girepository/cmph/compressed_rank.c b/girepository/cmph/compressed_rank.c index 822b2e15..8019dbe5 100644 --- a/girepository/cmph/compressed_rank.c +++ b/girepository/cmph/compressed_rank.c @@ -83,9 +83,9 @@ cmph_uint32 compressed_rank_query(compressed_rank_t * cr, cmph_uint32 idx) return cr->n; } - val_quot = idx >> cr->rem_r; - rems_mask = (1U << cr->rem_r) - 1U; - val_rem = idx & rems_mask; + val_quot = idx >> cr->rem_r; + rems_mask = (1U << cr->rem_r) - 1U; + val_rem = idx & rems_mask; if(val_quot == 0) { rank = sel_res = 0; @@ -128,6 +128,9 @@ void compressed_rank_dump(compressed_rank_t * cr, char **buf, cmph_uint32 *bufle register cmph_uint32 pos = 0; char * buf_sel = 0; cmph_uint32 buflen_sel = 0; +#ifdef DEBUG + cmph_uint32 i; +#endif *buflen = 4*(cmph_uint32)sizeof(cmph_uint32) + sel_size + vals_rems_size; @@ -164,7 +167,7 @@ void compressed_rank_dump(compressed_rank_t * cr, char **buf, cmph_uint32 *bufle memcpy(*buf + pos, buf_sel, buflen_sel); #ifdef DEBUG - cmph_uint32 i = 0; + i = 0; for(i = 0; i < buflen_sel; i++) { DEBUGP("pos = %u -- buf_sel[%u] = %u\n", pos, i, *(*buf + pos + i)); @@ -192,6 +195,9 @@ void compressed_rank_load(compressed_rank_t * cr, const char *buf, cmph_uint32 b register cmph_uint32 pos = 0; cmph_uint32 buflen_sel = 0; register cmph_uint32 vals_rems_size = 0; +#ifdef DEBUG + cmph_uint32 i; +#endif // loading max_val, n, and rem_r memcpy(&(cr->max_val), buf, sizeof(cmph_uint32)); @@ -213,7 +219,7 @@ void compressed_rank_load(compressed_rank_t * cr, const char *buf, cmph_uint32 b select_load(&cr->sel, buf + pos, buflen_sel); #ifdef DEBUG - cmph_uint32 i = 0; + i = 0; for(i = 0; i < buflen_sel; i++) { DEBUGP("pos = %u -- buf_sel[%u] = %u\n", pos, i, *(buf + pos + i)); diff --git a/girepository/cmph/compressed_seq.c b/girepository/cmph/compressed_seq.c index e558196d..e5191fd5 100644 --- a/girepository/cmph/compressed_seq.c +++ b/girepository/cmph/compressed_seq.c @@ -167,6 +167,9 @@ void compressed_seq_dump(compressed_seq_t * cs, char ** buf, cmph_uint32 * bufle register cmph_uint32 pos = 0; char * buf_sel = 0; cmph_uint32 buflen_sel = 0; +#ifdef DEBUG + cmph_uint32 i; +#endif *buflen = 4*(cmph_uint32)sizeof(cmph_uint32) + sel_size + length_rems_size + store_table_size; @@ -202,8 +205,8 @@ void compressed_seq_dump(compressed_seq_t * cs, char ** buf, cmph_uint32 * bufle DEBUGP("buflen_sel = %u\n", buflen_sel); memcpy(*buf + pos, buf_sel, buflen_sel); - #ifdef DEBUG - cmph_uint32 i = 0; + #ifdef DEBUG + i = 0; for(i = 0; i < buflen_sel; i++) { DEBUGP("pos = %u -- buf_sel[%u] = %u\n", pos, i, *(*buf + pos + i)); @@ -215,7 +218,7 @@ void compressed_seq_dump(compressed_seq_t * cs, char ** buf, cmph_uint32 * bufle // dumping length_rems memcpy(*buf + pos, cs->length_rems, length_rems_size); - #ifdef DEBUG + #ifdef DEBUG for(i = 0; i < length_rems_size; i++) { DEBUGP("pos = %u -- length_rems_size = %u -- length_rems[%u] = %u\n", pos, length_rems_size, i, *(*buf + pos + i)); @@ -226,7 +229,7 @@ void compressed_seq_dump(compressed_seq_t * cs, char ** buf, cmph_uint32 * bufle // dumping store_table memcpy(*buf + pos, cs->store_table, store_table_size); - #ifdef DEBUG + #ifdef DEBUG for(i = 0; i < store_table_size; i++) { DEBUGP("pos = %u -- store_table_size = %u -- store_table[%u] = %u\n", pos, store_table_size, i, *(*buf + pos + i)); @@ -241,6 +244,9 @@ void compressed_seq_load(compressed_seq_t * cs, const char * buf, cmph_uint32 bu cmph_uint32 buflen_sel = 0; register cmph_uint32 length_rems_size = 0; register cmph_uint32 store_table_size = 0; +#ifdef DEBUG + cmph_uint32 i; +#endif // loading n, rem_r and total_length memcpy(&(cs->n), buf, sizeof(cmph_uint32)); @@ -261,8 +267,8 @@ void compressed_seq_load(compressed_seq_t * cs, const char * buf, cmph_uint32 bu DEBUGP("buflen_sel = %u\n", buflen_sel); select_load(&cs->sel, buf + pos, buflen_sel); - #ifdef DEBUG - cmph_uint32 i = 0; + #ifdef DEBUG + i = 0; for(i = 0; i < buflen_sel; i++) { DEBUGP("pos = %u -- buf_sel[%u] = %u\n", pos, i, *(buf + pos + i)); @@ -280,7 +286,7 @@ void compressed_seq_load(compressed_seq_t * cs, const char * buf, cmph_uint32 bu length_rems_size *= 4; memcpy(cs->length_rems, buf + pos, length_rems_size); - #ifdef DEBUG + #ifdef DEBUG for(i = 0; i < length_rems_size; i++) { DEBUGP("pos = %u -- length_rems_size = %u -- length_rems[%u] = %u\n", pos, length_rems_size, i, *(buf + pos + i)); @@ -298,7 +304,7 @@ void compressed_seq_load(compressed_seq_t * cs, const char * buf, cmph_uint32 bu store_table_size *= 4; memcpy(cs->store_table, buf + pos, store_table_size); - #ifdef DEBUG + #ifdef DEBUG for(i = 0; i < store_table_size; i++) { DEBUGP("pos = %u -- store_table_size = %u -- store_table[%u] = %u\n", pos, store_table_size, i, *(buf + pos + i)); @@ -336,19 +342,19 @@ cmph_uint32 compressed_seq_query_packed(void * cs_packed, cmph_uint32 idx) register cmph_uint32 *ptr = (cmph_uint32 *)cs_packed; register cmph_uint32 n = *ptr++; register cmph_uint32 rem_r = *ptr++; + register cmph_uint32 buflen_sel, length_rems_size, enc_idx, enc_length; + // compressed sequence query computation + register cmph_uint32 rems_mask, stored_value, sel_res; + register cmph_uint32 *sel_packed, *length_rems, *store_table; + ptr++; // skipping total_length // register cmph_uint32 total_length = *ptr++; - register cmph_uint32 buflen_sel = *ptr++; - register cmph_uint32 * sel_packed = ptr; - register cmph_uint32 * length_rems = (ptr += (buflen_sel >> 2)); - register cmph_uint32 length_rems_size = BITS_TABLE_SIZE(n, rem_r); - register cmph_uint32 * store_table = (ptr += length_rems_size); + buflen_sel = *ptr++; + sel_packed = ptr; + length_rems = (ptr += (buflen_sel >> 2)); + length_rems_size = BITS_TABLE_SIZE(n, rem_r); + store_table = (ptr += length_rems_size); - // compressed sequence query computation - register cmph_uint32 enc_idx, enc_length; - register cmph_uint32 rems_mask; - register cmph_uint32 stored_value; - register cmph_uint32 sel_res; rems_mask = (1U << rem_r) - 1U; diff --git a/girepository/cmph/fch.c b/girepository/cmph/fch.c index f6e16e34..33b959e2 100644 --- a/girepository/cmph/fch.c +++ b/girepository/cmph/fch.c @@ -10,6 +10,7 @@ #include <assert.h> #include <string.h> #include <errno.h> + #define INDEX 0 /* alignment index within a bucket */ //#define DEBUG #include "debug.h" @@ -320,6 +321,10 @@ int fch_dump(cmph_t *mphf, FILE *fd) register size_t nbytes; fch_data_t *data = (fch_data_t *)mphf->data; + +#ifdef DEBUG + cmph_uint32 i; +#endif __cmph_dump(mphf, fd); hash_state_dump(data->h1, &buf, &buflen); @@ -340,12 +345,11 @@ int fch_dump(cmph_t *mphf, FILE *fd) nbytes = fwrite(&(data->p1), sizeof(double), (size_t)1, fd); nbytes = fwrite(&(data->p2), sizeof(double), (size_t)1, fd); nbytes = fwrite(data->g, sizeof(cmph_uint32)*(data->b), (size_t)1, fd); - if (nbytes == 0 && ferror(fd)) { + if (nbytes == 0 && ferror(fd)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return 0; } #ifdef DEBUG - cmph_uint32 i; fprintf(stderr, "G: "); for (i = 0; i < data->b; ++i) fprintf(stderr, "%u ", data->g[i]); fprintf(stderr, "\n"); @@ -359,6 +363,9 @@ void fch_load(FILE *f, cmph_t *mphf) cmph_uint32 buflen; register size_t nbytes; fch_data_t *fch = (fch_data_t *)malloc(sizeof(fch_data_t)); +#ifdef DEBUG + cmph_uint32 i; +#endif //DEBUGP("Loading fch mphf\n"); mphf->data = fch; @@ -392,12 +399,12 @@ void fch_load(FILE *f, cmph_t *mphf) fch->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*fch->b); nbytes = fread(fch->g, fch->b*sizeof(cmph_uint32), (size_t)1, f); - if (nbytes == 0 && ferror(f)) { + if (nbytes == 0 && ferror(f)) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); return; } + #ifdef DEBUG - cmph_uint32 i; fprintf(stderr, "G: "); for (i = 0; i < fch->b; ++i) fprintf(stderr, "%u ", fch->g[i]); fprintf(stderr, "\n"); @@ -436,6 +443,7 @@ void fch_pack(cmph_t *mphf, void *packed_mphf) // packing h1 type CMPH_HASH h1_type = hash_get_type(data->h1); + CMPH_HASH h2_type; *((cmph_uint32 *) ptr) = h1_type; ptr += sizeof(cmph_uint32); @@ -444,7 +452,7 @@ void fch_pack(cmph_t *mphf, void *packed_mphf) ptr += hash_state_packed_size(h1_type); // packing h2 type - CMPH_HASH h2_type = hash_get_type(data->h2); + h2_type = hash_get_type(data->h2); *((cmph_uint32 *) ptr) = h2_type; ptr += sizeof(cmph_uint32); @@ -499,27 +507,32 @@ cmph_uint32 fch_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke { register cmph_uint8 *h1_ptr = packed_mphf; register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr); + register cmph_uint8 *h2_ptr; + register CMPH_HASH h2_type; + register cmph_uint32 *g_ptr; + register cmph_uint32 m, b, h1, h2; + register double p1, p2; + h1_ptr += 4; - register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type); - register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr); + h2_ptr = h1_ptr + hash_state_packed_size(h1_type); + h2_type = *((cmph_uint32 *)h2_ptr); h2_ptr += 4; - register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type)); + g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type)); - register cmph_uint32 m = *g_ptr++; + m = *g_ptr++; - register cmph_uint32 b = *g_ptr++; + b = *g_ptr++; - register double p1 = (double)(*((cmph_uint64 *)g_ptr)); + p1 = (double)(*((cmph_uint64 *)g_ptr)); g_ptr += 2; - register double p2 = (double)(*((cmph_uint64 *)g_ptr)); + p2 = (double)(*((cmph_uint64 *)g_ptr)); g_ptr += 2; - register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % m; - register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % m; - + h1 = hash_packed(h1_ptr, h1_type, key, keylen) % m; + h2 = hash_packed(h2_ptr, h2_type, key, keylen) % m; h1 = mixh10h11h12 (b, p1, p2, h1); return (h2 + g_ptr[h1]) % m; } diff --git a/girepository/gdump.c b/girepository/gdump.c index 7e02d391..a72841fe 100644 --- a/girepository/gdump.c +++ b/girepository/gdump.c @@ -38,6 +38,9 @@ #include <string.h> static void +escaped_printf (GOutputStream *out, const char *fmt, ...) G_GNUC_PRINTF (2, 3); + +static void escaped_printf (GOutputStream *out, const char *fmt, ...) { char *str; @@ -422,8 +425,10 @@ dump_error_quark (GQuark quark, const char *symbol, GOutputStream *out) * * Argument specified is a comma-separated pair of filenames; i.e. of * the form "input.txt,output.xml". The input file should be a - * UTF-8 Unix-line-ending text file, with each line containing the name - * of a GType _get_type function. + * UTF-8 Unix-line-ending text file, with each line containing either + * "get-type:" followed by the name of a GType _get_type function, or + * "error-quark:" followed by the name of an error quark function. No + * extra whitespace is allowed. * * The output file should already exist, but be empty. This function will * overwrite its contents. diff --git a/girepository/gi-dump-types.c b/girepository/gi-dump-types.c index 13e7ae68..69d8b12d 100644 --- a/girepository/gi-dump-types.c +++ b/girepository/gi-dump-types.c @@ -10,8 +10,6 @@ main (int argc, GOutputStream *stdout; GModule *self; - g_type_init (); - stdout = g_unix_output_stream_new (1, FALSE); self = g_module_open (NULL, 0); diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index ff9c9395..37893e6c 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -226,7 +226,7 @@ g_base_info_ref (GIBaseInfo *info) GIRealInfo *rinfo = (GIRealInfo*)info; g_assert (rinfo->ref_count != INVALID_REFCOUNT); - ((GIRealInfo*)info)->ref_count++; + g_atomic_int_inc (&rinfo->ref_count); return info; } @@ -244,21 +244,20 @@ g_base_info_unref (GIBaseInfo *info) GIRealInfo *rinfo = (GIRealInfo*)info; g_assert (rinfo->ref_count > 0 && rinfo->ref_count != INVALID_REFCOUNT); - rinfo->ref_count--; - if (!rinfo->ref_count) - { - if (rinfo->container && ((GIRealInfo *) rinfo->container)->ref_count != INVALID_REFCOUNT) - g_base_info_unref (rinfo->container); + if (!g_atomic_int_dec_and_test (&rinfo->ref_count)) + return; - if (rinfo->repository) - g_object_unref (rinfo->repository); + if (rinfo->container && ((GIRealInfo *) rinfo->container)->ref_count != INVALID_REFCOUNT) + g_base_info_unref (rinfo->container); - if (rinfo->type == GI_INFO_TYPE_UNRESOLVED) - g_slice_free (GIUnresolvedInfo, (GIUnresolvedInfo *) rinfo); - else - g_slice_free (GIRealInfo, rinfo); - } + if (rinfo->repository) + g_object_unref (rinfo->repository); + + if (rinfo->type == GI_INFO_TYPE_UNRESOLVED) + g_slice_free (GIUnresolvedInfo, (GIUnresolvedInfo *) rinfo); + else + g_slice_free (GIRealInfo, rinfo); } /** diff --git a/girepository/gienuminfo.c b/girepository/gienuminfo.c index a9b7c1df..400a56d6 100644 --- a/girepository/gienuminfo.c +++ b/girepository/gienuminfo.c @@ -67,6 +67,18 @@ g_enum_info_get_n_values (GIEnumInfo *info) return blob->n_values; } +/** + * g_enum_info_get_error_domain: + * @info: a #GIEnumInfo + * + * Obtain the string form of the quark for the error domain associated with + * this enum, if any. + * + * Returns: (transfer none): the string form of the error domain associated + * with this enum, or %NULL. + * + * Since: 1.29.17 + */ const gchar * g_enum_info_get_error_domain (GIEnumInfo *info) { diff --git a/girepository/girepository-private.h b/girepository/girepository-private.h index 275776d8..bbd34e3e 100644 --- a/girepository/girepository-private.h +++ b/girepository/girepository-private.h @@ -33,6 +33,11 @@ typedef struct _GIRealInfo GIRealInfo; +/* We changed a gint32 -> gint in the structure below, which should be + * valid everywhere we care about. + */ +G_STATIC_ASSERT (sizeof (int) == sizeof (gint32)); + /* * We just use one structure for all of the info object * types; in general, we should be reading data directly @@ -43,7 +48,7 @@ struct _GIRealInfo { /* Keep this part in sync with GIUnresolvedInfo below */ gint32 type; - gint32 ref_count; + volatile gint ref_count; GIRepository *repository; GIBaseInfo *container; @@ -62,7 +67,7 @@ struct _GIUnresolvedInfo { /* Keep this part in sync with GIBaseInfo above */ gint32 type; - gint32 ref_count; + volatile gint ref_count; GIRepository *repository; GIBaseInfo *container; diff --git a/girepository/girepository.c b/girepository/girepository.c index b5c30297..0922fb09 100644 --- a/girepository/girepository.c +++ b/girepository/girepository.c @@ -35,7 +35,6 @@ #include "config.h" -static GStaticMutex globals_lock = G_STATIC_MUTEX_INIT; static GIRepository *default_repository = NULL; static GSList *search_path = NULL; static GSList *override_search_path = NULL; @@ -134,12 +133,13 @@ g_irepository_class_init (GIRepositoryClass *class) static void init_globals (void) { - g_static_mutex_lock (&globals_lock); + static gsize initialized = 0; + + if (!g_once_init_enter (&initialized)) + return; if (default_repository == NULL) - { - default_repository = g_object_new (G_TYPE_IREPOSITORY, NULL); - } + default_repository = g_object_new (G_TYPE_IREPOSITORY, NULL); if (search_path == NULL) { @@ -184,7 +184,7 @@ init_globals (void) search_path = g_slist_reverse (search_path); } - g_static_mutex_unlock (&globals_lock); + g_once_init_leave (&initialized, 1); } void @@ -593,28 +593,39 @@ g_irepository_get_info (GIRepository *repository, } typedef struct { - GIRepository *repository; - GType type; - - gboolean fastpass; + const gchar *gtype_name; GITypelib *result_typelib; - DirEntry *result; + gboolean found_prefix; } FindByGTypeData; -static void -find_by_gtype_foreach (gpointer key, - gpointer value, - gpointer datap) +static DirEntry * +find_by_gtype (GHashTable *table, FindByGTypeData *data, gboolean check_prefix) { - GITypelib *typelib = (GITypelib*)value; - FindByGTypeData *data = datap; + GHashTableIter iter; + gpointer key, value; + DirEntry *ret; - if (data->result != NULL) - return; + g_hash_table_iter_init (&iter, table); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + GITypelib *typelib = (GITypelib*)value; + if (check_prefix) + { + if (!g_typelib_matches_gtype_name_prefix (typelib, data->gtype_name)) + continue; - data->result = g_typelib_get_dir_entry_by_gtype (typelib, data->fastpass, data->type); - if (data->result) - data->result_typelib = typelib; + data->found_prefix = TRUE; + } + + ret = g_typelib_get_dir_entry_by_gtype_name (typelib, data->gtype_name); + if (ret) + { + data->result_typelib = typelib; + return ret; + } + } + + return NULL; } /** @@ -637,6 +648,7 @@ g_irepository_find_by_gtype (GIRepository *repository, { FindByGTypeData data; GIBaseInfo *cached; + DirEntry *entry; repository = get_repository (repository); @@ -646,30 +658,55 @@ g_irepository_find_by_gtype (GIRepository *repository, if (cached != NULL) return g_base_info_ref (cached); - data.repository = repository; - data.fastpass = TRUE; - data.type = gtype; + data.gtype_name = g_type_name (gtype); data.result_typelib = NULL; - data.result = NULL; + data.found_prefix = FALSE; + + /* There is a corner case regarding GdkRectangle. GdkRectangle is a + * boxed type, but it is just an alias to boxed struct + * CairoRectangleInt. Scanner automatically converts all references + * to GdkRectangle to CairoRectangleInt, so GdkRectangle does not + * appear in the typelibs at all, although user code might query it. + * So if we get such query, we also change it to lookup of + * CairoRectangleInt. + * https://bugzilla.gnome.org/show_bug.cgi?id=655423 + */ + if (G_UNLIKELY (!strcmp (data.gtype_name, "GdkRectangle"))) + data.gtype_name = "CairoRectangleInt"; + + /* Inside each typelib, we include the "C prefix" which acts as + * a namespace mechanism. For GtkTreeView, the C prefix is Gtk. + * Given the assumption that GTypes for a library also use the + * C prefix, we know we can skip examining a typelib if our + * target type does not have this typelib's C prefix. Use this + * assumption as our first attempt at locating the DirEntry. + */ + entry = find_by_gtype (repository->priv->typelibs, &data, TRUE); + if (entry == NULL) + entry = find_by_gtype (repository->priv->lazy_typelibs, &data, TRUE); - g_hash_table_foreach (repository->priv->typelibs, find_by_gtype_foreach, &data); - if (data.result == NULL) - g_hash_table_foreach (repository->priv->lazy_typelibs, find_by_gtype_foreach, &data); + /* If we have no result, but we did find a typelib claiming to + * offer bindings for such a prefix, bail out now on the assumption + * that a more exhaustive search would not produce any results. + */ + if (entry == NULL && data.found_prefix) + return NULL; - /* We do two passes; see comment in find_interface */ - if (data.result == NULL) - { - data.fastpass = FALSE; - g_hash_table_foreach (repository->priv->typelibs, find_by_gtype_foreach, &data); - } - if (data.result == NULL) - g_hash_table_foreach (repository->priv->lazy_typelibs, find_by_gtype_foreach, &data); + /* Not ever class library necessarily specifies a correct c_prefix, + * so take a second pass. This time we will try a global lookup, + * ignoring prefixes. + * See http://bugzilla.gnome.org/show_bug.cgi?id=564016 + */ + if (entry == NULL) + entry = find_by_gtype (repository->priv->typelibs, &data, FALSE); + if (entry == NULL) + entry = find_by_gtype (repository->priv->lazy_typelibs, &data, FALSE); - if (data.result != NULL) + if (entry != NULL) { - cached = _g_info_new_full (data.result->blob_type, + cached = _g_info_new_full (entry->blob_type, repository, - NULL, data.result_typelib, data.result->offset); + NULL, data.result_typelib, entry->offset); g_hash_table_insert (repository->priv->info_by_gtype, (gpointer) gtype, diff --git a/girepository/girepository.h b/girepository/girepository.h index eb990a27..2b2b1713 100644 --- a/girepository/girepository.h +++ b/girepository/girepository.h @@ -90,6 +90,7 @@ typedef enum GType g_irepository_get_type (void) G_GNUC_CONST; GIRepository *g_irepository_get_default (void); void g_irepository_prepend_search_path (const char *directory); +void g_irepository_prepend_library_path (const char *directory); GSList * g_irepository_get_search_path (void); const char * g_irepository_load_typelib (GIRepository *repository, GITypelib *typelib, diff --git a/girepository/girepository.symbols b/girepository/girepository.symbols new file mode 100644 index 00000000..5f01adff --- /dev/null +++ b/girepository/girepository.symbols @@ -0,0 +1,196 @@ +g_arg_info_get_closure +g_arg_info_get_destroy +g_arg_info_get_direction +g_arg_info_get_ownership_transfer +g_arg_info_get_scope +g_arg_info_get_type +g_arg_info_is_caller_allocates +g_arg_info_is_optional +g_arg_info_is_return_value +g_arg_info_is_skip +g_arg_info_load_type +g_arg_info_may_be_null +g_base_info_equal +g_base_info_get_attribute +g_base_info_get_container +g_base_info_get_name +g_base_info_get_namespace +g_base_info_get_type +g_base_info_get_typelib +g_base_info_gtype_get_type +g_base_info_is_deprecated +g_base_info_iterate_attributes +g_base_info_ref +g_base_info_unref +g_info_new +g_callable_info_can_throw_gerror +g_callable_info_get_arg +g_callable_info_get_caller_owns +g_callable_info_get_n_args +g_callable_info_get_return_attribute +g_callable_info_get_return_type +g_callable_info_invoke +g_callable_info_iterate_return_attributes +g_callable_info_is_method +g_callable_info_load_arg +g_callable_info_load_return_type +g_callable_info_may_return_null +g_callable_info_skip_return +g_constant_info_free_value +g_constant_info_get_type +g_constant_info_get_value +g_enum_info_get_error_domain +g_enum_info_get_method +g_enum_info_get_n_methods +g_enum_info_get_n_values +g_enum_info_get_storage_type +g_enum_info_get_value +g_value_info_get_value +g_field_info_get_field +g_field_info_get_flags +g_field_info_get_offset +g_field_info_get_size +g_field_info_get_type +g_field_info_set_field +g_function_info_get_flags +g_function_info_get_property +g_function_info_get_symbol +g_function_info_get_vfunc +g_function_info_invoke +g_invoke_error_quark +g_interface_info_find_method +g_interface_info_find_signal +g_interface_info_find_vfunc +g_interface_info_get_constant +g_interface_info_get_iface_struct +g_interface_info_get_method +g_interface_info_get_n_constants +g_interface_info_get_n_methods +g_interface_info_get_n_prerequisites +g_interface_info_get_n_properties +g_interface_info_get_prerequisite +g_interface_info_get_n_signals +g_interface_info_get_n_vfuncs +g_interface_info_get_property +g_interface_info_get_signal +g_interface_info_get_vfunc +g_object_info_find_method +g_object_info_find_method_using_interfaces +g_object_info_find_signal +g_object_info_find_vfunc +g_object_info_find_vfunc_using_interfaces +g_object_info_get_abstract +g_object_info_get_class_struct +g_object_info_get_constant +g_object_info_get_field +g_object_info_get_fundamental +g_object_info_get_get_value_function +g_object_info_get_get_value_function_pointer +g_object_info_get_interface +g_object_info_get_method +g_object_info_get_n_constants +g_object_info_get_n_fields +g_object_info_get_n_interfaces +g_object_info_get_n_methods +g_object_info_get_n_properties +g_object_info_get_n_signals +g_object_info_get_n_vfuncs +g_object_info_get_parent +g_object_info_get_property +g_object_info_get_ref_function +g_object_info_get_ref_function_pointer +g_object_info_get_set_value_function +g_object_info_get_set_value_function_pointer +g_object_info_get_signal +g_object_info_get_type_init +g_object_info_get_type_name +g_object_info_get_unref_function +g_object_info_get_unref_function_pointer +g_object_info_get_vfunc +g_property_info_get_flags +g_property_info_get_ownership_transfer +g_property_info_get_type +g_registered_type_info_get_g_type +g_registered_type_info_get_type_init +g_registered_type_info_get_type_name +gi_cclosure_marshal_generic +g_irepository_dump +g_irepository_enumerate_versions +g_irepository_error_quark +g_irepository_find_by_error_domain +g_irepository_find_by_gtype +g_irepository_find_by_name +g_irepository_get_c_prefix +g_irepository_get_default +g_irepository_get_dependencies +g_irepository_get_info +g_irepository_get_loaded_namespaces +g_irepository_get_n_infos +g_irepository_get_option_group +g_irepository_get_search_path +g_irepository_get_shared_library +g_irepository_get_type +g_irepository_get_typelib_path +g_irepository_get_version +g_irepository_is_registered +g_irepository_load_typelib +g_irepository_prepend_library_path +g_irepository_prepend_search_path +g_irepository_require +g_irepository_require_private +gi_type_info_extract_ffi_return_value +gi_type_tag_get_ffi_type +g_callable_info_free_closure +g_callable_info_prepare_closure +g_function_info_prep_invoker +g_function_invoker_destroy +g_function_invoker_new_for_address +g_type_info_get_ffi_type +g_signal_info_get_class_closure +g_signal_info_get_flags +g_signal_info_true_stops_emit +g_struct_info_find_method +g_struct_info_get_alignment +g_struct_info_get_field +g_struct_info_get_method +g_struct_info_get_n_fields +g_struct_info_get_n_methods +g_struct_info_get_size +g_struct_info_is_foreign +g_struct_info_is_gtype_struct +g_type_info_is_pointer +g_type_info_is_zero_terminated +g_type_info_get_array_fixed_size +g_type_info_get_array_length +g_type_info_get_array_type +g_type_info_get_interface +g_type_info_get_param_type +g_type_info_get_tag +g_type_tag_to_string +g_info_type_to_string +g_typelib_check_sanity +g_typelib_error_quark +g_typelib_free +g_typelib_get_namespace +g_typelib_new_from_const_memory +g_typelib_new_from_mapped_file +g_typelib_new_from_memory +g_typelib_symbol +g_typelib_validate +g_union_info_find_method +g_union_info_get_alignment +g_union_info_get_discriminator +g_union_info_get_discriminator_offset +g_union_info_get_discriminator_type +g_union_info_get_field +g_union_info_get_method +g_union_info_get_n_fields +g_union_info_get_n_methods +g_union_info_get_size +g_union_info_is_discriminated +g_vfunc_info_get_address +g_vfunc_info_get_invoker +g_vfunc_info_get_flags +g_vfunc_info_get_offset +g_vfunc_info_get_signal +g_vfunc_info_invoke diff --git a/girepository/girffi.c b/girepository/girffi.c index ec710c37..f4c80eaa 100644 --- a/girepository/girffi.c +++ b/girepository/girffi.c @@ -26,7 +26,9 @@ #include <errno.h> #include <string.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif #include "girffi.h" #include "girepository.h" #include "girepository-private.h" diff --git a/girepository/girmodule.c b/girepository/girmodule.c index af71f369..05c8987f 100644 --- a/girepository/girmodule.c +++ b/girepository/girmodule.c @@ -261,8 +261,9 @@ add_directory_index_section (guint8 *data, GIrModule *module, guint32 *offset2) for (i = 0; i < n_interfaces; i++) { + const char *str; entry = (DirEntry *)&data[header->directory + (i * header->entry_blob_size)]; - const char *str = (const char *) (&data[entry->name]); + str = (const char *) (&data[entry->name]); _gi_typelib_hash_builder_add_string (dirindex_builder, str, i); } diff --git a/girepository/girnode.c b/girepository/girnode.c index 881aa9be..afb71e57 100644 --- a/girepository/girnode.c +++ b/girepository/girnode.c @@ -28,6 +28,11 @@ #include "girnode.h" #include "gitypelib-internal.h" +#ifdef _MSC_VER +#define strtoll _strtoi64 +#define strtoull _strtoui64 +#endif + static gulong string_count = 0; static gulong unique_string_count = 0; static gulong string_size = 0; @@ -228,7 +233,7 @@ _g_ir_node_free (GIrNode *node) _g_ir_node_free ((GIrNode *)type->parameter_type1); _g_ir_node_free ((GIrNode *)type->parameter_type2); - g_free (type->interface); + g_free (type->giinterface); g_strfreev (type->errors); } @@ -1244,7 +1249,7 @@ serialize_type (GIrTypelibBuild *build, GIrNode *iface; gchar *name; - iface = find_entry_node (build, node->interface, NULL); + iface = find_entry_node (build, node->giinterface, NULL); if (iface) { if (iface->type == G_IR_NODE_XREF) @@ -1253,8 +1258,8 @@ serialize_type (GIrTypelibBuild *build, } else { - g_warning ("Interface for type reference %s not found", node->interface); - name = node->interface; + g_warning ("Interface for type reference %s not found", node->giinterface); + name = node->giinterface; } g_string_append_printf (str, "%s%s", name, @@ -1483,7 +1488,7 @@ _g_ir_node_build_typelib (GIrNode *node, iface->reserved = 0; iface->tag = type->tag; iface->reserved2 = 0; - iface->interface = find_entry (build, type->interface); + iface->interface = find_entry (build, type->giinterface); } break; diff --git a/girepository/girnode.h b/girepository/girnode.h index d89847ac..07b084c4 100644 --- a/girepository/girnode.h +++ b/girepository/girnode.h @@ -133,7 +133,7 @@ struct _GIrNodeType GIrNodeType *parameter_type1; GIrNodeType *parameter_type2; - gchar *interface; + gchar *giinterface; gchar **errors; }; diff --git a/girepository/giroffsets.c b/girepository/giroffsets.c index e3c9d7f5..368332ea 100644 --- a/girepository/giroffsets.c +++ b/girepository/giroffsets.c @@ -190,10 +190,10 @@ get_interface_size_alignment (GIrTypelibBuild *build, { GIrNode *iface; - iface = _g_ir_find_node (build, ((GIrNode*)type)->module, type->interface); + iface = _g_ir_find_node (build, ((GIrNode*)type)->module, type->giinterface); if (!iface) { - _g_ir_module_fatal (build, 0, "Can't resolve type '%s' for %s", type->interface, who); + _g_ir_module_fatal (build, 0, "Can't resolve type '%s' for %s", type->giinterface, who); *size = -1; *alignment = -1; return FALSE; diff --git a/girepository/girparser.c b/girepository/girparser.c index fa0de1f8..f96cfb1e 100644 --- a/girepository/girparser.c +++ b/girepository/girparser.c @@ -36,6 +36,24 @@ */ #define SUPPORTED_GIR_VERSION "1.2" +#ifdef G_OS_WIN32 + +#include <windows.h> + +#ifdef GIR_DIR +#undef GIR_DIR +#endif + +/* GIR_DIR is used only in code called just once, + * so no problem leaking this + */ +#define GIR_DIR \ + g_build_filename (g_win32_get_package_installation_directory_of_module(NULL), \ + "share", \ + GIR_SUFFIX, \ + NULL) +#endif + struct _GIrParser { gchar **includes; @@ -77,7 +95,6 @@ typedef enum STATE_ALIAS, /* 30 */ STATE_TYPE, STATE_ATTRIBUTE, - STATE_DOC, STATE_PASSTHROUGH } ParseState; @@ -324,15 +341,20 @@ state_switch (ParseContext *ctx, ParseState newstate) g_assert (ctx->state != newstate); ctx->prev_state = ctx->state; ctx->state = newstate; + + if (ctx->state == STATE_PASSTHROUGH) + ctx->unknown_depth = 1; } static GIrNode * pop_node (ParseContext *ctx) { + GSList *top; + GIrNode *node; g_assert (ctx->node_stack != 0); - GSList *top = ctx->node_stack; - GIrNode *node = top->data; + top = ctx->node_stack; + node = top->data; g_debug ("popping node %d %s", node->type, node->name); ctx->node_stack = top->next; @@ -359,7 +381,8 @@ typedef struct { } IntegerAliasInfo; static IntegerAliasInfo integer_aliases[] = { - { "gchar", SIZEOF_CHAR, 0 }, + { "gchar", SIZEOF_CHAR, 1 }, + { "guchar", SIZEOF_CHAR, 0 }, { "gshort", SIZEOF_SHORT, 1 }, { "gushort", SIZEOF_SHORT, 0 }, { "gint", SIZEOF_INT, 1 }, @@ -552,8 +575,8 @@ parse_type_internal (GIrModule *module, if (*str == '<') { - (str)++; char *tmp, *end; + (str)++; end = strchr (str, '>'); tmp = g_strndup (str, end - str); @@ -565,9 +588,10 @@ parse_type_internal (GIrModule *module, } else { + const char *start; type->tag = GI_TYPE_TAG_INTERFACE; type->is_interface = TRUE; - const char *start = str; + start = str; /* must be an interface type */ while (g_ascii_isalnum (*str) || @@ -577,7 +601,7 @@ parse_type_internal (GIrModule *module, *str == ':') (str)++; - type->interface = g_strndup (start, str - start); + type->giinterface = g_strndup (start, str - start); } if (next) @@ -703,10 +727,7 @@ introspectable_prelude (GMarkupParseContext *context, if (introspectable) state_switch (ctx, new_state); else - { - state_switch (ctx, STATE_PASSTHROUGH); - ctx->unknown_depth = 1; - } + state_switch (ctx, STATE_PASSTHROUGH); return introspectable; } @@ -1965,7 +1986,7 @@ start_type (GMarkupParseContext *context, * doesn't look like a pointer, but is internally. */ if (typenode->tag == GI_TYPE_TAG_INTERFACE && - is_disguised_structure (ctx, typenode->interface)) + is_disguised_structure (ctx, typenode->giinterface)) pointer_depth++; if (pointer_depth > 0) @@ -2095,22 +2116,6 @@ end_type (ParseContext *ctx) } static gboolean -start_doc (GMarkupParseContext *context, - const gchar *element_name, - const gchar **attribute_names, - const gchar **attribute_values, - ParseContext *ctx, - GError **error) -{ - if (strcmp (element_name, "doc") != 0) - return FALSE; - - state_switch (ctx, STATE_DOC); - - return TRUE; -} - -static gboolean start_attribute (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, @@ -2743,9 +2748,11 @@ start_element_handler (GMarkupParseContext *context, attribute_names, attribute_values, ctx, error)) goto out; - else if (start_doc (context, element_name, attribute_names, - attribute_values, ctx, error)) - goto out; + if (strcmp (element_name, "doc") == 0) + { + state_switch (ctx, STATE_PASSTHROUGH); + goto out; + } break; case 'e': @@ -2824,6 +2831,11 @@ start_element_handler (GMarkupParseContext *context, attribute_names, attribute_values, ctx, error)) goto out; + else if (strcmp (element_name, "instance-parameter") == 0) + { + state_switch (ctx, STATE_PASSTHROUGH); + goto out; + } else if (strcmp (element_name, "c:include") == 0) { state_switch (ctx, STATE_C_INCLUDE); @@ -2860,6 +2872,9 @@ start_element_handler (GMarkupParseContext *context, version = find_attribute ("version", attribute_names, attribute_values); shared_library = find_attribute ("shared-library", attribute_names, attribute_values); cprefix = find_attribute ("c:identifier-prefixes", attribute_names, attribute_values); + /* Backwards compatibility; vala currently still generates this */ + if (cprefix == NULL) + cprefix = find_attribute ("c:prefix", attribute_names, attribute_values); if (name == NULL) MISSING_ATTRIBUTE (context, error, element_name, "name"); @@ -3006,7 +3021,6 @@ start_element_handler (GMarkupParseContext *context, ctx->file_path, line_number, char_number, element_name, ctx->state); state_switch (ctx, STATE_PASSTHROUGH); - ctx->unknown_depth = 1; } out: @@ -3391,13 +3405,6 @@ end_element_handler (GMarkupParseContext *context, } break; - case STATE_DOC: - if (strcmp ("doc", element_name) == 0) - { - state_switch (ctx, ctx->prev_state); - } - break; - case STATE_PASSTHROUGH: ctx->unknown_depth -= 1; g_assert (ctx->unknown_depth >= 0); diff --git a/girepository/gitypelib-internal.h b/girepository/gitypelib-internal.h index 04662b4a..ac71008d 100644 --- a/girepository/gitypelib-internal.h +++ b/girepository/gitypelib-internal.h @@ -1126,13 +1126,15 @@ DirEntry *g_typelib_get_dir_entry (GITypelib *typelib, DirEntry *g_typelib_get_dir_entry_by_name (GITypelib *typelib, const char *name); -DirEntry *g_typelib_get_dir_entry_by_gtype (GITypelib *typelib, - gboolean fastpass, - GType gtype); +DirEntry *g_typelib_get_dir_entry_by_gtype_name (GITypelib *typelib, + const gchar *gtype_name); DirEntry *g_typelib_get_dir_entry_by_error_domain (GITypelib *typelib, GQuark error_domain); +gboolean g_typelib_matches_gtype_name_prefix (GITypelib *typelib, + const gchar *gtype_name); + void g_typelib_check_sanity (void); #define g_typelib_get_string(typelib,offset) ((const gchar*)&(typelib->data)[(offset)]) diff --git a/girepository/gitypelib.c b/girepository/gitypelib.c index 2af17e96..d88924a6 100644 --- a/girepository/gitypelib.c +++ b/girepository/gitypelib.c @@ -198,55 +198,17 @@ g_typelib_get_dir_entry_by_name (GITypelib *typelib, } DirEntry * -g_typelib_get_dir_entry_by_gtype (GITypelib *typelib, - gboolean fastpass, - GType gtype) +g_typelib_get_dir_entry_by_gtype_name (GITypelib *typelib, + const gchar *gtype_name) { Header *header = (Header *)typelib->data; - guint n_entries = header->n_local_entries; - const char *gtype_name = g_type_name (gtype); - DirEntry *entry; guint i; - const char *c_prefix; - - /* There is a corner case regarding GdkRectangle. GdkRectangle is a - boxed type, but it is just an alias to boxed struct - CairoRectangleInt. Scanner automatically converts all references - to GdkRectangle to CairoRectangleInt, so GdkRectangle does not - appear in the typelibs at all, although user code might query it. - So if we get such query, we also change it to lookup of - CairoRectangleInt. - https://bugzilla.gnome.org/show_bug.cgi?id=655423 */ - if (!fastpass && !strcmp (gtype_name, "GdkRectangle")) - gtype_name = "CairoRectangleInt"; - - /* Inside each typelib, we include the "C prefix" which acts as - * a namespace mechanism. For GtkTreeView, the C prefix is Gtk. - * Given the assumption that GTypes for a library also use the - * C prefix, we know we can skip examining a typelib if our - * target type does not have this typelib's C prefix. - * - * However, not every class library necessarily conforms to this, - * e.g. Clutter has Cogl inside it. So, we split this into two - * passes. First we try a lookup, skipping things which don't - * have the prefix. If that fails then we try a global lookup, - * ignoring the prefix. - * - * See http://bugzilla.gnome.org/show_bug.cgi?id=564016 - */ - c_prefix = g_typelib_get_string (typelib, header->c_prefix); - if (fastpass && c_prefix != NULL) - { - if (g_ascii_strncasecmp (c_prefix, gtype_name, strlen (c_prefix)) != 0) - return NULL; - } - for (i = 1; i <= n_entries; i++) + for (i = 1; i <= header->n_local_entries; i++) { RegisteredTypeBlob *blob; const char *type; - - entry = g_typelib_get_dir_entry (typelib, i); + DirEntry *entry = g_typelib_get_dir_entry (typelib, i); if (!BLOB_IS_REGISTERED_TYPE (entry)) continue; @@ -261,6 +223,110 @@ g_typelib_get_dir_entry_by_gtype (GITypelib *typelib, return NULL; } +typedef struct { + const char *s; + const char *separator; + gsize sep_len; + GString buf; +} StrSplitIter; + +static void +strsplit_iter_init (StrSplitIter *iter, + const char *s, + const char *separator) +{ + iter->s = s; + iter->separator = separator; + iter->sep_len = strlen (separator); + iter->buf.str = NULL; + iter->buf.len = 0; + iter->buf.allocated_len = 0; +} + +static gboolean +strsplit_iter_next (StrSplitIter *iter, + char **out_val) +{ + const char *s = iter->s; + const char *next; + gsize len; + + if (!s) + return FALSE; + next = strstr (s, iter->separator); + if (next) + { + iter->s = next + iter->sep_len; + len = next - s; + } + else + { + iter->s = NULL; + len = strlen (s); + } + if (len == 0) + { + *out_val = ""; + } + else + { + g_string_overwrite_len (&iter->buf, 0, s, (gssize)len); + *out_val = iter->buf.str; + } + return TRUE; +} + +static void +strsplit_iter_clear (StrSplitIter *iter) +{ + g_free (iter->buf.str); +} + +gboolean +g_typelib_matches_gtype_name_prefix (GITypelib *typelib, + const gchar *gtype_name) +{ + Header *header = (Header *)typelib->data; + const char *c_prefix; + gchar *prefix; + gboolean ret = FALSE; + StrSplitIter split_iter; + gsize gtype_name_len; + + c_prefix = g_typelib_get_string (typelib, header->c_prefix); + if (c_prefix == NULL || strlen (c_prefix) == 0) + return FALSE; + + gtype_name_len = strlen (gtype_name); + + /* c_prefix is a comma separated string of supported prefixes + * in the typelib. + * We match the specified gtype_name if the gtype_name starts + * with the prefix, and is followed by a capital letter. + * For example, a typelib offering the 'Gdk' prefix does match + * GdkX11Cursor, however a typelib offering the 'G' prefix does not. + */ + strsplit_iter_init (&split_iter, c_prefix, ","); + while (strsplit_iter_next (&split_iter, &prefix)) + { + size_t len = strlen (prefix); + + if (gtype_name_len < len) + continue; + + if (strncmp (prefix, gtype_name, len) != 0) + continue; + + if (g_ascii_isupper (gtype_name[len])) + { + ret = TRUE; + break; + } + } + strsplit_iter_clear (&split_iter); + return ret; +} + DirEntry * g_typelib_get_dir_entry_by_error_domain (GITypelib *typelib, GQuark error_domain) @@ -2062,6 +2128,72 @@ g_typelib_error_quark (void) return quark; } +static GSList *library_paths; + +/** + * g_irepository_prepend_library_path: + * @directory: (type filename): a single directory to scan for shared libraries + * + * Prepends @directory to the search path that is used to + * search shared libraries referenced by imported namespaces. + * Multiple calls to this function all contribute to the final + * list of paths. + * The list of paths is unique and shared for all #GIRepository + * instances across the process, but it doesn't affect namespaces + * imported before the call. + * + * If the library is not found in the directories configured + * in this way, loading will fall back to the system library + * path (ie. LD_LIBRARY_PATH and DT_RPATH in ELF systems). + * See the documentation of your dynamic linker for full details. + * + * Since: 1.35.8 + */ +void +g_irepository_prepend_library_path (const char *directory) +{ + library_paths = g_slist_prepend (library_paths, + g_strdup (directory)); +} + +/* Note on the GModule flags used by this function: + + * Glade's autoconnect feature and OpenGL's extension mechanism + * as used by Clutter rely on g_module_open(NULL) to work as a means of + * accessing the app's symbols. This keeps us from using + * G_MODULE_BIND_LOCAL. BIND_LOCAL may have other issues as well; + * in general libraries are not expecting multiple copies of + * themselves and are not expecting to be unloaded. So we just + * load modules globally for now. + */ +static GModule * +load_one_shared_library (const char *shlib) +{ + GSList *p; + GModule *m; + + if (!g_path_is_absolute (shlib)) + { + /* First try in configured library paths */ + for (p = library_paths; p; p = p->next) + { + char *path = g_build_filename (p->data, shlib, NULL); + + m = g_module_open (path, G_MODULE_BIND_LAZY); + + g_free (path); + if (m != NULL) + return m; + } + } + + /* Then try loading from standard paths */ + /* Do not attempt to fix up shlib to replace .la with .so: + it's done by GModule anyway. + */ + return g_module_open (shlib, G_MODULE_BIND_LAZY); +} + static void _g_typelib_do_dlopen (GITypelib *typelib) { @@ -2091,30 +2223,7 @@ _g_typelib_do_dlopen (GITypelib *typelib) { GModule *module; - /* Glade's autoconnect feature and OpenGL's extension mechanism - * as used by Clutter rely on g_module_open(NULL) to work as a means of - * accessing the app's symbols. This keeps us from using - * G_MODULE_BIND_LOCAL. BIND_LOCAL may have other issues as well; - * in general libraries are not expecting multiple copies of - * themselves and are not expecting to be unloaded. So we just - * load modules globally for now. - */ - - module = g_module_open (shlibs[i], G_MODULE_BIND_LAZY); - - if (module == NULL) - { - GString *shlib_full = g_string_new (shlibs[i]); - - module = g_module_open (shlib_full->str, G_MODULE_BIND_LAZY); - if (module == NULL) - { - g_string_overwrite (shlib_full, strlen (shlib_full->str)-2, SHLIB_SUFFIX); - module = g_module_open (shlib_full->str, G_MODULE_BIND_LAZY); - } - - g_string_free (shlib_full, TRUE); - } + module = load_one_shared_library (shlibs[i]); if (module == NULL) { diff --git a/girepository/gthash-test.c b/girepository/gthash-test.c index ea811e35..faeb2dc5 100644 --- a/girepository/gthash-test.c +++ b/girepository/gthash-test.c @@ -56,7 +56,6 @@ test_build_retrieve (void) int main(int argc, char **argv) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add_func ("/gthash/build-retrieve", test_build_retrieve); diff --git a/girepository/gthash.c b/girepository/gthash.c index b50ea6f0..ecc3b104 100644 --- a/girepository/gthash.c +++ b/girepository/gthash.c @@ -29,7 +29,7 @@ #define ALIGN_VALUE(this, boundary) \ (( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1))) -/** +/* * String hashing in the typelib. We have a set of static (fixed) strings, * and given one, we need to find its index number. This problem is perfect * hashing: http://en.wikipedia.org/wiki/Perfect_hashing |