hashtable...squid

Discussion in 'C Programming' started by s88, May 31, 2005.

  1. s88

    s88 Guest

    I work with the bit-vector(http://search.cpan.org/dist/Bit-Vector/)
    and squid lib as well. But I meet a weird situation now...Let's see my
    code.
    I wanna creat a hashtable in a function, and then return the address of
    the hashtable.
    But my hashtable looks empty outside the fake_table().
    The hashtable just manage the pointer I insert. Don't really "copy"
    anything into the table.


    hashtable *fake_table(){

    BitVector_Boot();
    N_char x1[] = "101000";
    N_char x2[] = "101010";

    wordptr X1 = BitVector_Create(6, 1);
    wordptr X2 = BitVector_Create(6, 1);

    BitVector_from_Bin(X1, x1);
    BitVector_from_Bin(X2, x2);

    hash_table *inst_table =
    hash_create(inst_tb_compare,7951,hash_string);
    hash_table *ht2 =
    hash_create(inst_tb_compare,7951,hash_string);

    inst_tb_atom *_atom1 = (inst_tb_atom
    *)malloc(sizeof(inst_tb_atom));
    inst_tb_atom *_atom2 = (inst_tb_atom
    *)malloc(sizeof(inst_tb_atom));

    _atom1->_type = 1;
    _atom1->point_to.ht = ht2;
    _atom1->X = X1;

    _atom2->_type = 1;
    _atom2->point_to.ht = ht3;
    _atom2->X = X2;

    hash_insert(ht2,x2,_atom2);
    hash_insert(inst_table,x1,_atom1);

    return inst_table;
    }

    Thanx!!!
     
    s88, May 31, 2005
    #1
    1. Advertising

  2. s88

    Jack Klein Guest

    On 30 May 2005 17:45:29 -0700, "s88" <> wrote in
    comp.lang.c:

    > I work with the bit-vector(http://search.cpan.org/dist/Bit-Vector/)
    > and squid lib as well. But I meet a weird situation now...Let's see my
    > code.
    > I wanna creat a hashtable in a function, and then return the address of
    > the hashtable.
    > But my hashtable looks empty outside the fake_table().
    > The hashtable just manage the pointer I insert. Don't really "copy"
    > anything into the table.


    The problem here is that your code is littered with non-standard types
    that are apparently defined (with typedef or macros) in the header
    files for the third party libraries that you are trying to use.

    > hashtable *fake_table(){
    >
    > BitVector_Boot();


    The C language does not define what this function call does, so there
    is no reason at all to assume that anyone here knows either.

    > N_char x1[] = "101000";
    > N_char x2[] = "101010";


    Here you appear to be defining two arrays of type 'N_char', which must
    be an alias for one of the character types, after calling a function.
    Does your compiler conform to the 1999 or later version of the C
    standard? This is illegal code in earlier versions of C.


    > wordptr X1 = BitVector_Create(6, 1);
    > wordptr X2 = BitVector_Create(6, 1);
    >
    > BitVector_from_Bin(X1, x1);
    > BitVector_from_Bin(X2, x2);
    >
    > hash_table *inst_table =
    > hash_create(inst_tb_compare,7951,hash_string);
    > hash_table *ht2 =
    > hash_create(inst_tb_compare,7951,hash_string);
    >
    > inst_tb_atom *_atom1 = (inst_tb_atom
    > *)malloc(sizeof(inst_tb_atom));


    Casting the pointer returned by malloc() in C is unnecessary and can
    hide a serious error causing undefined behavior if <stdlib.h> is not
    included or there is otherwise not a proper prototype for malloc() in
    scope.

    Also you are committing the serious error of not checking the return
    value of malloc() for NULL, which it will return if the allocation
    fails.


    > inst_tb_atom *_atom2 = (inst_tb_atom
    > *)malloc(sizeof(inst_tb_atom));
    >
    > _atom1->_type = 1;
    > _atom1->point_to.ht = ht2;
    > _atom1->X = X1;
    >
    > _atom2->_type = 1;
    > _atom2->point_to.ht = ht3;
    > _atom2->X = X2;
    >
    > hash_insert(ht2,x2,_atom2);
    > hash_insert(inst_table,x1,_atom1);
    >
    > return inst_table;
    > }
    >
    > Thanx!!!


    We haven't got the faintest idea of how these functions get the memory
    they use. You'll have to talk to whoever made the library.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, May 31, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    554
  2. Zlatko Hristov

    Python script to grep squid logs

    Zlatko Hristov, Apr 14, 2004, in forum: Python
    Replies:
    1
    Views:
    890
    Lee Harr
    Apr 15, 2004
  3. Eddie Butcher

    Zope, Squid and manage_workspace

    Eddie Butcher, Jun 11, 2004, in forum: Python
    Replies:
    0
    Views:
    325
    Eddie Butcher
    Jun 11, 2004
  4. CptDondo

    OT: squid-type cache for XML?

    CptDondo, Nov 14, 2006, in forum: HTML
    Replies:
    4
    Views:
    641
    Toby Inkster
    Nov 14, 2006
  5. pantagruel
    Replies:
    1
    Views:
    698
    pantagruel
    Mar 10, 2008
Loading...

Share This Page