Changeset 24031


Ignore:
Timestamp:
05/19/11 09:26:07 (10 years ago)
Author:
jmt12
Message:

Found mg indexing randomly broke on 64bit machines. Tracked it down to random.c and perf_hash.c. Replaced all occurances of 'long' (which is not well defined on 64 bit machines) with the more stable mg_s_long (mglong.h) to fix this issue.

Location:
main/branches/64_bit_Greenstone/greenstone2/common-src/indexers/mg/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/branches/64_bit_Greenstone/greenstone2/common-src/indexers/mg/lib/perf_hash.c

    r16583 r24031  
    4242
    4343/* Random Number stuff */
    44 static long seed[] = {0, 0};
     44static mg_s_long seed[] = {0, 0};
    4545#define RANDOM() irandm(seed)
    4646#define SEED_RANDOM(the_seed) do{ seed[0] = the_seed; }while(0)
     
    105105
    106106#ifndef STRUCT
    107 static long **tb0, **tb1, **tb2;
     107static mg_s_long **tb0, **tb1, **tb2;
    108108#else
    109109struct tb_entry **tb;
     
    128128{               /* deletes edge e from list of v */
    129129
    130   int b;
    131 
     130  int b, norm_b;
    132131  b = FIRST[v];
    133132  assert (norm (b) != 0);
     
    700699    {
    701700      if (tb0)
    702     if (!(tb0[i] = Xmalloc (sizeof (long) * MAX_L)))
     701    if (!(tb0[i] = Xmalloc (sizeof (mg_s_long) * MAX_L)))
    703702        ok = 0;
    704703      if (tb1)
    705     if (!(tb1[i] = Xmalloc (sizeof (long) * MAX_L)))
     704    if (!(tb1[i] = Xmalloc (sizeof (mg_s_long) * MAX_L)))
    706705        ok = 0;
    707706      if (tb2)
    708     if (!(tb2[i] = Xmalloc (sizeof (long) * MAX_L)))
     707    if (!(tb2[i] = Xmalloc (sizeof (mg_s_long) * MAX_L)))
    709708        ok = 0;
    710709    }
     
    744743
    745744  if (r <= 0)
    746     SEED_RANDOM ((long) time ((time_t *) NULL));
     745    SEED_RANDOM ((mg_s_long) time ((time_t *) NULL));
    747746  else
    748747    SEED_RANDOM (r);
     
    907906    {
    908907      if (phd->tb0)
    909     if (!(phd->tb0[i] = Xmalloc (sizeof (long) * phd->MAX_L)))
     908    if (!(phd->tb0[i] = Xmalloc (sizeof (mg_s_long) * phd->MAX_L)))
    910909        ok = 0;
    911910      if (phd->tb1)
    912     if (!(phd->tb1[i] = Xmalloc (sizeof (long) * phd->MAX_L)))
     911    if (!(phd->tb1[i] = Xmalloc (sizeof (mg_s_long) * phd->MAX_L)))
    913912        ok = 0;
    914913      if (phd->tb2)
    915     if (!(phd->tb2[i] = Xmalloc (sizeof (long) * phd->MAX_L)))
     914    if (!(phd->tb2[i] = Xmalloc (sizeof (mg_s_long) * phd->MAX_L)))
    916915        ok = 0;
    917916    }
     
    951950      int j;
    952951
    953       tot += fread ((char *) phd->tb0[i], sizeof (long), phd->MAX_L, f) *
     952      tot += fread ((char *) phd->tb0[i], sizeof (mg_s_long), phd->MAX_L, f) *
    954953        sizeof (int);
    955       tot += fread ((char *) phd->tb1[i], sizeof (long), phd->MAX_L, f) *
     954      tot += fread ((char *) phd->tb1[i], sizeof (mg_s_long), phd->MAX_L, f) *
    956955        sizeof (int);
    957       tot += fread ((char *) phd->tb2[i], sizeof (long), phd->MAX_L, f) *
     956      tot += fread ((char *) phd->tb2[i], sizeof (mg_s_long), phd->MAX_L, f) *
    958957        sizeof (int);
    959958
  • main/branches/64_bit_Greenstone/greenstone2/common-src/indexers/mg/lib/perf_hash.h

    r16583 r24031  
    2323#define H_PERF_HASH
    2424
    25 
    26 
     25#include "mglong.h"
    2726
    2827struct tb_entry
    2928  {
    30     long tb0, tb1, tb2;
     29    mg_s_long tb0, tb1, tb2;
    3130  };
    3231
  • main/branches/64_bit_Greenstone/greenstone2/common-src/indexers/mg/lib/random.c

    r16583 r24031  
    3333 *  The table mt[0:127] is defined by mt[i] = 69069 ** (128-i)
    3434 */
    35 
    36 #define MASK ((long) 593970775)
     35#include "random.h"
     36
     37#define MASK ((mg_s_long) 593970775)
    3738/*  or in hex, 23674657 */
    3839
     
    4041/*  i.e. 2 to power -31 */
    4142
    42 static long mt [128] =   {
     43static mg_s_long mt [128] =   {
    4344      902906369,
    4445     2030498053,
     
    172173
    173174double
    174 random (long is [2])
     175random (mg_s_long is [2])
    175176{
    176     long it, leh, nit;
     177    mg_s_long it, leh, nit;
    177178
    178179    it = is [0];
     
    187188    is [0] = it;    is [1] = leh;
    188189    if (leh < 0) leh = ~leh;
    189     return (SCALE * ((long) (leh | 1)));
     190    return (SCALE * ((mg_s_long) (leh | 1)));
    190191}
    191192
    192193
    193194
    194 long
    195 irandm (long is [2])
     195mg_s_long
     196irandm (mg_s_long is [2])
    196197{
    197     long it, leh, nit;
     198    mg_s_long it, leh, nit;
    198199
    199200    it = is [0];
  • main/branches/64_bit_Greenstone/greenstone2/common-src/indexers/mg/lib/random.h

    r16583 r24031  
    3636 *  The table mt[0:127] is defined by mt[i] = 69069 ** (128-i)
    3737 */
     38#include "mglong.h"
    3839
    39 double random (long is [2]);
    40 long irandm (long is [2]);
     40double random (mg_s_long is [2]);
     41mg_s_long irandm (mg_s_long is [2]);
    4142
    4243#endif
Note: See TracChangeset for help on using the changeset viewer.