Browse Source

small fixes and preparations for further additions. valgrind shows no leaks now

master
Georg Hopp 14 years ago
parent
commit
ac539ffa2a
  1. 6
      bigpoint_dyntype.c
  2. 7
      bigpoint_dyntype.h
  3. 7
      tests/hash_test.c

6
bigpoint_dyntype.c

@ -4,6 +4,7 @@
#include <json/json.h>
#include "bigpoint_dyntype.h"
#include "bigpoint_hash.h"
static
@ -24,10 +25,11 @@ __construct(struct BIGPOINT_DYNTYPE * _this, va_list * params)
break;
case BIGPOINT_DYNTYPE_HASH:
(_this->data)._hash = new(BIGPOINT_HASH);
break;
default:
(_this->data)._object = NULL;
(_this->data)._hash = NULL;
}
}
@ -57,7 +59,7 @@ __jsonConst(struct BIGPOINT_DYNTYPE * _this, struct json_object * json)
default:
_this->type = BIGPOINT_DYNTYPE_NULL;
_this->size = 0;
(_this->data)._object = NULL;
(_this->data)._hash = NULL;
}
}

7
bigpoint_dyntype.h

@ -5,6 +5,10 @@
#include "bigpoint_cclass.h"
struct BIGPOINT_DYNTYPE;
#include "bigpoint_hash.h"
enum BIGPOINT_DYNTYPE_TYPES {
BIGPOINT_DYNTYPE_NULL = 0,
@ -26,7 +30,8 @@ struct BIGPOINT_DYNTYPE {
int _int;
double _float;
char * _string;
void * _object;
struct BIGPOINT_DYNTYPE ** _array;
struct BIGPOINT_HASH * _hash;
} data;
};

7
tests/hash_test.c

@ -16,6 +16,7 @@ main(int argc, char * argv[])
{
struct BIGPOINT_DYNTYPE * dyn;
struct BIGPOINT_HASH * hash = new(BIGPOINT_HASH);
struct json_object * json;
dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), 123);
bigpoint_hash_set(hash, TEST_KEY1, dyn);
@ -33,9 +34,9 @@ main(int argc, char * argv[])
delete(hash);
hash = newFromJson(
BIGPOINT_HASH,
json_tokener_parse("{\"key1\":123,\"key2\":321}"));
json = json_tokener_parse("{\"key1\":123,\"key2\":321}");
hash = newFromJson(BIGPOINT_HASH, json);
json_object_put(json);
dyn = bigpoint_hash_get(hash, TEST_KEY1);
printf("%d\n", (dyn->data)._int);

Loading…
Cancel
Save