1
0
Fork 0

more memory zones

This commit is contained in:
Frank Celler 2012-04-25 23:35:30 +02:00
parent 85db82258b
commit ac74aa7ec9
11 changed files with 333 additions and 209 deletions

View File

@ -299,7 +299,7 @@ ProgramOptions::~ProgramOptions () {
} }
for (map<string, TRI_vector_string_t*>::iterator i = _valuesVector.begin(); i != _valuesVector.end(); ++i) { for (map<string, TRI_vector_string_t*>::iterator i = _valuesVector.begin(); i != _valuesVector.end(); ++i) {
TRI_FreeVectorString(i->second); TRI_FreeVectorString(TRI_CORE_MEM_ZONE, i->second);
} }
for (map<string, bool*>::iterator i = _valuesBool.begin(); i != _valuesBool.end(); ++i) { for (map<string, bool*>::iterator i = _valuesBool.begin(); i != _valuesBool.end(); ++i) {
@ -538,7 +538,7 @@ void ProgramOptions::setupSubDescription (ProgramOptionsDescription const& descr
if (wtr == 0) { if (wtr == 0) {
wtr = _valuesVector[option] = (TRI_vector_string_t*) TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_vector_string_t)); wtr = _valuesVector[option] = (TRI_vector_string_t*) TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_vector_string_t));
TRI_InitVectorString(TRI_CORE_MEM_ZONE, wtr); TRI_InitVectorString(wtr, TRI_CORE_MEM_ZONE);
} }
TRI_AddVectorStringPODescription(desc, option.c_str(), shortOption, help.c_str(), wtr); TRI_AddVectorStringPODescription(desc, option.c_str(), shortOption, help.c_str(), wtr);

View File

@ -280,19 +280,19 @@ TRI_json_t* TRI_CopyJson (TRI_memory_zone_t*, TRI_json_t*);
/// @brief parses a json string /// @brief parses a json string
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_JsonString (char const* text); TRI_json_t* TRI_JsonString (TRI_memory_zone_t*, char const* text);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief parses a json string and returns error message /// @brief parses a json string and returns error message
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_Json2String (char const* text, char** error); TRI_json_t* TRI_Json2String (TRI_memory_zone_t*, char const* text, char** error);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief parses a json file and returns error message /// @brief parses a json file and returns error message
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_JsonFile (char const* path, char** error); TRI_json_t* TRI_JsonFile (TRI_memory_zone_t*, char const* path, char** error);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @} /// @}

View File

@ -70,6 +70,12 @@ typedef void TRI_memory_zone_t;
TRI_memory_zone_t* TRI_CORE_MEM_ZONE; TRI_memory_zone_t* TRI_CORE_MEM_ZONE;
////////////////////////////////////////////////////////////////////////////////
/// @brief unknown memory zone
////////////////////////////////////////////////////////////////////////////////
TRI_memory_zone_t* TRI_UNKNOWN_MEM_ZONE;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @} /// @}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -93,6 +93,12 @@ bool TRI_IsPrefixString (char const* full, char const* prefix);
char* TRI_DuplicateString (char const*); char* TRI_DuplicateString (char const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief duplicates a string
////////////////////////////////////////////////////////////////////////////////
char* TRI_DuplicateStringZ (TRI_memory_zone_t*, char const*);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief duplicates a string of given length /// @brief duplicates a string of given length
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -224,6 +230,12 @@ char* TRI_EscapeUtf8String (char const* in, size_t inLength, bool escapeSlash, s
char* TRI_UnescapeUtf8String (char const* in, size_t inLength, size_t* outLength); char* TRI_UnescapeUtf8String (char const* in, size_t inLength, size_t* outLength);
////////////////////////////////////////////////////////////////////////////////
/// @brief unescapes unicode escape sequences
////////////////////////////////////////////////////////////////////////////////
char* TRI_UnescapeUtf8StringZ (TRI_memory_zone_t*, char const* in, size_t inLength, size_t* outLength);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @} /// @}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -435,7 +435,7 @@ int TRI_ResizeVectorPointer (TRI_vector_pointer_t* vector, size_t n) {
if (vector->_buffer != NULL) { if (vector->_buffer != NULL) {
memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(void*)); memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(void*));
TRI_Free(vector->_buffer); TRI_Free(vector->_memoryZone, vector->_buffer);
} }
vector->_buffer = newBuffer; vector->_buffer = newBuffer;
@ -450,34 +450,36 @@ int TRI_ResizeVectorPointer (TRI_vector_pointer_t* vector, size_t n) {
/// @brief adds an element at the end /// @brief adds an element at the end
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_PushBackVectorPointer (TRI_vector_pointer_t* vector, void* element) { int TRI_PushBackVectorPointer (TRI_vector_pointer_t* vector, void* element) {
if (vector->_length == vector->_capacity) { if (vector->_length == vector->_capacity) {
void* newBuffer; void* newBuffer;
size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity); size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity);
newBuffer = TRI_Allocate(newSize * sizeof(void*)); newBuffer = TRI_Allocate(vector->_memoryZone, newSize * sizeof(void*));
if (!newBuffer) {
// TODO FIXME: handle memory allocation failure */ if (newBuffer == NULL) {
return TRI_ERROR_OUT_OF_MEMORY;
} }
vector->_capacity = newSize; vector->_capacity = newSize;
if (vector->_buffer != NULL) { if (vector->_buffer != NULL) {
memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(void*)); memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(void*));
TRI_Free(vector->_buffer); TRI_Free(vector->_memoryZone, vector->_buffer);
} }
vector->_buffer = newBuffer; vector->_buffer = newBuffer;
} }
vector->_buffer[vector->_length++] = element; vector->_buffer[vector->_length++] = element;
return TRI_ERROR_NO_ERROR;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief inserts an element at position n, shifting the following elements /// @brief inserts an element at position n, shifting the following elements
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_InsertVectorPointer (TRI_vector_pointer_t* vector, void* element, size_t n) { int TRI_InsertVectorPointer (TRI_vector_pointer_t* vector, void* element, size_t n) {
if (vector->_length >= vector->_capacity) { if (vector->_length >= vector->_capacity) {
void* newBuffer; void* newBuffer;
size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity); size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity);
@ -486,16 +488,17 @@ void TRI_InsertVectorPointer (TRI_vector_pointer_t* vector, void* element, size_
newSize = n + 1; newSize = n + 1;
} }
newBuffer = TRI_Allocate(newSize * sizeof(void*)); newBuffer = TRI_Allocate(vector->_memoryZone, newSize * sizeof(void*));
if (!newBuffer) {
// TODO FIXME: handle memory allocation failure */ if (newBuffer == NULL) {
return TRI_ERROR_OUT_OF_MEMORY;
} }
vector->_capacity = newSize; vector->_capacity = newSize;
if (vector->_buffer != NULL) { if (vector->_buffer != NULL) {
memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(void*)); memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(void*));
TRI_Free(vector->_buffer); TRI_Free(vector->_memoryZone, vector->_buffer);
} }
vector->_buffer = newBuffer; vector->_buffer = newBuffer;
@ -515,6 +518,8 @@ void TRI_InsertVectorPointer (TRI_vector_pointer_t* vector, void* element, size_
else { else {
++vector->_length; ++vector->_length;
} }
return TRI_ERROR_NO_ERROR;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -574,7 +579,8 @@ void* TRI_AtVectorPointer (TRI_vector_pointer_t const* vector, size_t pos) {
/// @brief initialises a vector /// @brief initialises a vector
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_InitVectorString (TRI_vector_string_t* vector) { void TRI_InitVectorString (TRI_vector_string_t* vector, TRI_memory_zone_t* zone) {
vector->_memoryZone = zone;
vector->_buffer = NULL; vector->_buffer = NULL;
vector->_length = 0; vector->_length = 0;
vector->_capacity = 0; vector->_capacity = 0;
@ -590,11 +596,11 @@ void TRI_DestroyVectorString (TRI_vector_string_t* vector) {
if (vector->_buffer != NULL) { if (vector->_buffer != NULL) {
for (i = 0; i < vector->_capacity; ++i) { for (i = 0; i < vector->_capacity; ++i) {
if (vector->_buffer[i] != 0) { if (vector->_buffer[i] != 0) {
TRI_Free(vector->_buffer[i]); TRI_Free(vector->_memoryZone, vector->_buffer[i]);
} }
} }
TRI_Free(vector->_buffer); TRI_Free(vector->_memoryZone, vector->_buffer);
} }
} }
@ -602,9 +608,9 @@ void TRI_DestroyVectorString (TRI_vector_string_t* vector) {
/// @brief destroys a vector and frees the string /// @brief destroys a vector and frees the string
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_FreeVectorString (TRI_vector_string_t* vector) { void TRI_FreeVectorString (TRI_memory_zone_t* zone, TRI_vector_string_t* vector) {
TRI_DestroyVectorString(vector); TRI_DestroyVectorString(vector);
TRI_Free(vector); TRI_Free(zone, vector);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -624,14 +630,16 @@ void TRI_FreeVectorString (TRI_vector_string_t* vector) {
/// @brief copies a vector and all its strings /// @brief copies a vector and all its strings
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_vector_string_t* TRI_CopyVectorString (TRI_vector_string_t* vector) { TRI_vector_string_t* TRI_CopyVectorString (TRI_memory_zone_t* zone,
TRI_vector_string_t* vector) {
TRI_vector_string_t* copy; TRI_vector_string_t* copy;
char** ptr; char** ptr;
char** end; char** end;
char** qtr; char** qtr;
copy = TRI_Allocate(sizeof(TRI_vector_t)); copy = TRI_Allocate(zone, sizeof(TRI_vector_t));
if (!copy) {
if (copy == NULL) {
return NULL; return NULL;
} }
@ -641,9 +649,10 @@ TRI_vector_string_t* TRI_CopyVectorString (TRI_vector_string_t* vector) {
copy->_capacity = 0; copy->_capacity = 0;
} }
else { else {
copy->_buffer = TRI_Allocate(vector->_length * sizeof(char*)); copy->_buffer = TRI_Allocate(zone, vector->_length * sizeof(char*));
if (!copy->_buffer) {
TRI_Free(copy); if (copy->_buffer == NULL) {
TRI_Free(zone, copy);
return NULL; return NULL;
} }
@ -655,8 +664,19 @@ TRI_vector_string_t* TRI_CopyVectorString (TRI_vector_string_t* vector) {
qtr = copy->_buffer; qtr = copy->_buffer;
for (; ptr < end; ++ptr, ++qtr) { for (; ptr < end; ++ptr, ++qtr) {
*qtr = TRI_DuplicateString(*ptr); *qtr = TRI_DuplicateStringZ(zone, *ptr);
// TODO FIXME: handle memory allocation failure
if (*qtr == NULL) {
char** xtr = copy->_buffer;
for (; xtr < qtr; ++xtr) {
TRI_Free(zone, *xtr);
}
TRI_Free(zone, copy->_buffer);
TRI_Free(zone, copy);
return NULL;
}
} }
} }
@ -683,64 +703,69 @@ void TRI_ClearVectorString (TRI_vector_string_t* vector) {
/// @brief resizes the vector /// @brief resizes the vector
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_ResizeVectorString (TRI_vector_string_t* vector, size_t n) { int TRI_ResizeVectorString (TRI_vector_string_t* vector, size_t n) {
if (vector->_length == n) { if (vector->_length == n) {
return; return TRI_ERROR_NO_ERROR;
} }
if (vector->_capacity < n) { if (vector->_capacity < n) {
void* newBuffer; void* newBuffer;
size_t newSize = n; size_t newSize = n;
newBuffer = TRI_Allocate(newSize * sizeof(char*)); newBuffer = TRI_Allocate(vector->_memoryZone, newSize * sizeof(char*));
if (!newBuffer) {
// TODO FIXME: handle memory allocation failure if (newBuffer == NULL) {
return TRI_ERROR_OUT_OF_MEMORY;
} }
vector->_capacity = n; vector->_capacity = n;
if (vector->_buffer != NULL) { if (vector->_buffer != NULL) {
memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(char*)); memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(char*));
TRI_Free(vector->_buffer); TRI_Free(vector->_memoryZone, vector->_buffer);
} }
vector->_buffer = newBuffer; vector->_buffer = newBuffer;
} }
vector->_length = n; vector->_length = n;
return TRI_ERROR_NO_ERROR;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief adds an element at the end /// @brief adds an element at the end
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_PushBackVectorString (TRI_vector_string_t* vector, char* element) { int TRI_PushBackVectorString (TRI_vector_string_t* vector, char* element) {
if (vector->_length == vector->_capacity) { if (vector->_length == vector->_capacity) {
char** newBuffer; char** newBuffer;
size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity); size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity);
newBuffer = (char**) TRI_Allocate(newSize * sizeof(char*)); newBuffer = (char**) TRI_Allocate(vector->_memoryZone, newSize * sizeof(char*));
if (!newBuffer) {
// TODO FIXME: handle memory allocation failure if (newBuffer == NULL) {
return TRI_ERROR_OUT_OF_MEMORY;
} }
vector->_capacity = newSize; vector->_capacity = newSize;
if (vector->_buffer != NULL) { if (vector->_buffer != NULL) {
memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(char*)); memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(char*));
TRI_Free(vector->_buffer); TRI_Free(vector->_memoryZone, vector->_buffer);
} }
vector->_buffer = newBuffer; vector->_buffer = newBuffer;
} }
vector->_buffer[vector->_length++] = element; vector->_buffer[vector->_length++] = element;
return TRI_ERROR_NO_ERROR;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief inserts an element at position n /// @brief inserts an element at position n
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_InsertVectorString (TRI_vector_string_t* vector, char* element, size_t n) { int TRI_InsertVectorString (TRI_vector_string_t* vector, char* element, size_t n) {
if (n >= vector->_capacity) { if (n >= vector->_capacity) {
char** newBuffer; char** newBuffer;
size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity); size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity);
@ -749,16 +774,17 @@ void TRI_InsertVectorString (TRI_vector_string_t* vector, char* element, size_t
newSize = n + 1; newSize = n + 1;
} }
newBuffer = (char**) TRI_Allocate(newSize * sizeof(char*)); newBuffer = (char**) TRI_Allocate(vector->_memoryZone, newSize * sizeof(char*));
if (!newBuffer) {
// TODO FIXME: handle memory allocation failure if (newBuffer == NULL) {
return TRI_ERROR_OUT_OF_MEMORY;
} }
vector->_capacity = newSize; vector->_capacity = newSize;
if (vector->_buffer != NULL) { if (vector->_buffer != NULL) {
memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(char*)); memcpy(newBuffer, vector->_buffer, vector->_length * sizeof(char*));
TRI_Free(vector->_buffer); TRI_Free(vector->_memoryZone, vector->_buffer);
} }
vector->_buffer = newBuffer; vector->_buffer = newBuffer;
@ -769,8 +795,10 @@ void TRI_InsertVectorString (TRI_vector_string_t* vector, char* element, size_t
vector->_buffer + n, vector->_buffer + n,
sizeof(char**) * (vector->_length - n)); sizeof(char**) * (vector->_length - n));
} }
vector->_length++; vector->_length++;
vector->_buffer[n] = element; vector->_buffer[n] = element;
return TRI_ERROR_NO_ERROR;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -780,7 +808,7 @@ void TRI_InsertVectorString (TRI_vector_string_t* vector, char* element, size_t
void TRI_RemoveVectorString (TRI_vector_string_t* vector, size_t n) { void TRI_RemoveVectorString (TRI_vector_string_t* vector, size_t n) {
if (n < vector->_length) { if (n < vector->_length) {
if (vector->_buffer[n] != NULL) { if (vector->_buffer[n] != NULL) {
TRI_Free(vector->_buffer[n]); TRI_Free(vector->_memoryZone, vector->_buffer[n]);
} }
if (n + 1 < vector->_length) { if (n + 1 < vector->_length) {

View File

@ -271,13 +271,13 @@ int TRI_ResizeVectorPointer (TRI_vector_pointer_t*, size_t);
/// @brief adds an element at the end /// @brief adds an element at the end
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_PushBackVectorPointer (TRI_vector_pointer_t*, void*); int TRI_PushBackVectorPointer (TRI_vector_pointer_t*, void*);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief adds an element at position n /// @brief adds an element at position n
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_InsertVectorPointer (TRI_vector_pointer_t*, void*, size_t); int TRI_InsertVectorPointer (TRI_vector_pointer_t*, void*, size_t);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief removes an element, returns this element /// @brief removes an element, returns this element
@ -340,7 +340,7 @@ TRI_vector_string_t;
/// @brief initialises a vector /// @brief initialises a vector
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_InitVectorString (TRI_memory_zone_t*, TRI_vector_string_t*); void TRI_InitVectorString (TRI_vector_string_t*, TRI_memory_zone_t*);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a vector and all strings, but does not free the pointer /// @brief destroys a vector and all strings, but does not free the pointer
@ -352,7 +352,7 @@ void TRI_DestroyVectorString (TRI_vector_string_t*);
/// @brief destroys a vector and frees the string /// @brief destroys a vector and frees the string
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_FreeVectorString (TRI_vector_string_t*); void TRI_FreeVectorString (TRI_memory_zone_t*, TRI_vector_string_t*);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @} /// @}
@ -371,7 +371,7 @@ void TRI_FreeVectorString (TRI_vector_string_t*);
/// @brief copies a vector and all its strings /// @brief copies a vector and all its strings
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_vector_string_t* TRI_CopyVectorString (TRI_vector_string_t*); TRI_vector_string_t* TRI_CopyVectorString (TRI_memory_zone_t*, TRI_vector_string_t*);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief returns true if the vector is empty /// @brief returns true if the vector is empty
@ -389,7 +389,7 @@ void TRI_ClearVectorString (TRI_vector_string_t*);
/// @brief resizes the vector /// @brief resizes the vector
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_ResizeVectorString (TRI_vector_string_t*, size_t n); int TRI_ResizeVectorString (TRI_vector_string_t*, size_t n);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief adds an element at the end /// @brief adds an element at the end
@ -397,7 +397,7 @@ void TRI_ResizeVectorString (TRI_vector_string_t*, size_t n);
/// Note that the vector claims owenship of element. /// Note that the vector claims owenship of element.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_PushBackVectorString (TRI_vector_string_t*, char* element); int TRI_PushBackVectorString (TRI_vector_string_t*, char* element);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief adds an element at position n /// @brief adds an element at position n
@ -405,7 +405,7 @@ void TRI_PushBackVectorString (TRI_vector_string_t*, char* element);
/// Note that the vector claims owenship of element. /// Note that the vector claims owenship of element.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_InsertVectorString (TRI_vector_string_t*, char* element, size_t n); int TRI_InsertVectorString (TRI_vector_string_t*, char* element, size_t n);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief removes an element, frees this element /// @brief removes an element, frees this element

View File

@ -590,8 +590,8 @@ static yyconst flex_int16_t yy_chk[130] =
static yyconst flex_int16_t yy_rule_linenum[14] = static yyconst flex_int16_t yy_rule_linenum[14] =
{ 0, { 0,
85, 89, 93, 101, 109, 117, 121, 125, 129, 133, 86, 90, 94, 102, 110, 118, 122, 126, 130, 134,
137, 146, 149 138, 147, 150
} ; } ;
/* The intent behind this definition is that it'll catch /* The intent behind this definition is that it'll catch
@ -617,7 +617,8 @@ static yyconst flex_int16_t yy_rule_linenum[14] =
#define UNQUOTED_STRING 12 #define UNQUOTED_STRING 12
struct jsonData { struct jsonData {
char const* message; char const* _message;
TRI_memory_zone_t* _memoryZone;
}; };
#define YY_FATAL_ERROR(a) \ #define YY_FATAL_ERROR(a) \
@ -2391,9 +2392,10 @@ static TRI_json_t* ParseList (yyscan_t scanner) {
bool comma; bool comma;
int c; int c;
list = TRI_CreateListJson(); list = TRI_CreateListJson(yyextra._memoryZone);
if (list == NULL) { if (list == NULL) {
yyextra._message = "out-of-memory";
return NULL; return NULL;
} }
@ -2409,8 +2411,8 @@ static TRI_json_t* ParseList (yyscan_t scanner) {
if (comma) { if (comma) {
if (c != COMMA) { if (c != COMMA) {
TRI_FreeJson(list); TRI_FreeJson(yyextra._memoryZone, list);
yyextra.message = "expecting comma"; yyextra._message = "expecting comma";
return NULL; return NULL;
} }
@ -2423,17 +2425,17 @@ static TRI_json_t* ParseList (yyscan_t scanner) {
sub = ParseObject(scanner, c); sub = ParseObject(scanner, c);
if (sub == NULL) { if (sub == NULL) {
TRI_FreeJson(list); TRI_FreeJson(yyextra._memoryZone, list);
return NULL; return NULL;
} }
TRI_PushBack3ListJson(list, sub); TRI_PushBack3ListJson(yyextra._memoryZone, list, sub);
c = tri_jsp_lex(scanner); c = tri_jsp_lex(scanner);
} }
TRI_FreeJson(list); TRI_FreeJson(yyextra._memoryZone, list);
yyextra.message = "expecting a list element, got end-of-file"; yyextra._message = "expecting a list element, got end-of-file";
return NULL; return NULL;
} }
@ -2455,7 +2457,11 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
size_t outLength; size_t outLength;
comma = false; comma = false;
array = TRI_CreateArrayJson(); array = TRI_CreateArrayJson(yyextra._memoryZone);
if (array == NULL) {
yyextra._message = "out-of-memory";
}
c = tri_jsp_lex(scanner); c = tri_jsp_lex(scanner);
@ -2466,8 +2472,8 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
if (comma) { if (comma) {
if (c != COMMA) { if (c != COMMA) {
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
yyextra.message = "expecting comma"; yyextra._message = "expecting comma";
return NULL; return NULL;
} }
@ -2479,22 +2485,22 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
// attribute name // attribute name
if (c != STRING_CONSTANT) { if (c != STRING_CONSTANT) {
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
yyextra.message = "expecting attribute name"; yyextra._message = "expecting attribute name";
return NULL; return NULL;
} }
ptr = yytext; ptr = yytext;
len = yyleng; len = yyleng;
name = TRI_UnescapeUtf8String(ptr + 1, len - 2, &outLength); name = TRI_UnescapeUtf8StringZ(yyextra._memoryZone, ptr + 1, len - 2, &outLength);
// followed by a colon // followed by a colon
c = tri_jsp_lex(scanner); c = tri_jsp_lex(scanner);
if (c != COLON) { if (c != COLON) {
TRI_FreeString(name); TRI_FreeString(yyextra._memoryZone, name);
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
yyextra.message = "expecting colon"; yyextra._message = "expecting colon";
return NULL; return NULL;
} }
@ -2503,19 +2509,19 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
sub = ParseObject(scanner, c); sub = ParseObject(scanner, c);
if (sub == NULL) { if (sub == NULL) {
TRI_FreeString(name); TRI_FreeString(yyextra._memoryZone, name);
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
return NULL; return NULL;
} }
TRI_Insert3ArrayJson(array, name, sub); TRI_Insert3ArrayJson(yyextra._memoryZone, array, name, sub);
TRI_FreeString(name); TRI_FreeString(yyextra._memoryZone, name);
c = tri_jsp_lex(scanner); c = tri_jsp_lex(scanner);
} }
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
yyextra.message = "expecting a object attribute name or element, got end-of-file"; yyextra._message = "expecting a object attribute name or element, got end-of-file";
return NULL; return NULL;
} }
@ -2526,20 +2532,39 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
static TRI_json_t* ParseObject (yyscan_t scanner, int c) { static TRI_json_t* ParseObject (yyscan_t scanner, int c) {
struct yyguts_t * yyg = (struct yyguts_t*) scanner; struct yyguts_t * yyg = (struct yyguts_t*) scanner;
TRI_json_t* result;
switch (c) { switch (c) {
case END_OF_FILE: case END_OF_FILE:
yyextra.message = "expecting atom, got end-of-file"; yyextra._message = "expecting atom, got end-of-file";
return NULL; return NULL;
case FALSE_CONSTANT: case FALSE_CONSTANT:
return TRI_CreateBooleanJson(false); result = TRI_CreateBooleanJson(yyextra._memoryZone, false);
if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
case TRUE_CONSTANT: case TRUE_CONSTANT:
return TRI_CreateBooleanJson(true); result = TRI_CreateBooleanJson(yyextra._memoryZone, true);
if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
case NULL_CONSTANT: case NULL_CONSTANT:
return TRI_CreateNullJson(); result = TRI_CreateNullJson(yyextra._memoryZone);
if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
case NUMBER_CONSTANT: { case NUMBER_CONSTANT: {
char buffer[512]; char buffer[512];
@ -2547,7 +2572,7 @@ static TRI_json_t* ParseObject (yyscan_t scanner, int c) {
double d; double d;
if ((size_t) yyleng >= sizeof(buffer)) { if ((size_t) yyleng >= sizeof(buffer)) {
yyextra.message = "number too big"; yyextra._message = "number too big";
return NULL; return NULL;
} }
@ -2557,60 +2582,71 @@ static TRI_json_t* ParseObject (yyscan_t scanner, int c) {
d = strtod(buffer, &ep); d = strtod(buffer, &ep);
if (d == HUGE_VAL && errno == ERANGE) { if (d == HUGE_VAL && errno == ERANGE) {
yyextra.message = "number too big"; yyextra._message = "number too big";
return NULL; return NULL;
} }
if (d == 0 && errno == ERANGE) { if (d == 0 && errno == ERANGE) {
yyextra.message = "number too small"; yyextra._message = "number too small";
return NULL; return NULL;
} }
if (ep != buffer + yyleng) { if (ep != buffer + yyleng) {
yyextra.message = "cannot parse number"; yyextra._message = "cannot parse number";
return NULL; return NULL;
} }
return TRI_CreateNumberJson(d); result = TRI_CreateNumberJson(yyextra._memoryZone, d);
if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
} }
case STRING_CONSTANT: { case STRING_CONSTANT: {
char* ptr; char* ptr;
size_t outLength; size_t outLength;
ptr = TRI_UnescapeUtf8String(yytext + 1, yyleng - 2, &outLength); ptr = TRI_UnescapeUtf8StringZ(yyextra._memoryZone, yytext + 1, yyleng - 2, &outLength);
result = TRI_CreateString2Json(yyextra._memoryZone, ptr, outLength);
return TRI_CreateString2Json(ptr, outLength); if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
} }
case OPEN_BRACE: case OPEN_BRACE:
return ParseArray(scanner); return ParseArray(scanner);
case CLOSE_BRACE: case CLOSE_BRACE:
yyextra.message = "expected object, got '}'"; yyextra._message = "expected object, got '}'";
return NULL; return NULL;
case OPEN_BRACKET: case OPEN_BRACKET:
return ParseList(scanner); return ParseList(scanner);
case CLOSE_BRACKET: case CLOSE_BRACKET:
yyextra.message = "expected object, got ']'"; yyextra._message = "expected object, got ']'";
return NULL; return NULL;
case COMMA: case COMMA:
yyextra.message = "expected object, got ','"; yyextra._message = "expected object, got ','";
return NULL; return NULL;
case COLON: case COLON:
yyextra.message = "expected object, got ':'"; yyextra._message = "expected object, got ':'";
return NULL; return NULL;
case UNQUOTED_STRING: case UNQUOTED_STRING:
yyextra.message = "expected object, got unquoted string"; yyextra._message = "expected object, got unquoted string";
return NULL; return NULL;
} }
yyextra.message = "unknown atom"; yyextra._message = "unknown atom";
return NULL; return NULL;
} }
@ -2631,7 +2667,7 @@ static TRI_json_t* ParseObject (yyscan_t scanner, int c) {
/// @brief parses a json string /// @brief parses a json string
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_Json2String (char const* text, char** error) { TRI_json_t* TRI_Json2String (TRI_memory_zone_t* zone, char const* text, char** error) {
TRI_json_t* object; TRI_json_t* object;
YY_BUFFER_STATE buf; YY_BUFFER_STATE buf;
int c; int c;
@ -2643,13 +2679,15 @@ TRI_json_t* TRI_Json2String (char const* text, char** error) {
tri_jsp_lex_init(&scanner); tri_jsp_lex_init(&scanner);
yyg = (struct yyguts_t*) scanner; yyg = (struct yyguts_t*) scanner;
yyextra._memoryZone = zone;
buf = tri_jsp__scan_string((char yyconst*) text,scanner); buf = tri_jsp__scan_string((char yyconst*) text,scanner);
c = tri_jsp_lex(scanner); c = tri_jsp_lex(scanner);
object = ParseObject(scanner, c); object = ParseObject(scanner, c);
if (object == NULL) { if (object == NULL) {
LOG_DEBUG("failed to parse json object: '%s'", yyextra.message); LOG_DEBUG("failed to parse json object: '%s'", yyextra._message);
} }
else { else {
c = tri_jsp_lex(scanner); c = tri_jsp_lex(scanner);
@ -2661,8 +2699,8 @@ TRI_json_t* TRI_Json2String (char const* text, char** error) {
} }
if (error != NULL) { if (error != NULL) {
if (yyextra.message != 0) { if (yyextra._message != 0) {
*error = TRI_DuplicateString(yyextra.message); *error = TRI_DuplicateString(yyextra._message);
} }
else { else {
*error = NULL; *error = NULL;
@ -2679,15 +2717,15 @@ TRI_json_t* TRI_Json2String (char const* text, char** error) {
/// @brief parses a json string /// @brief parses a json string
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_JsonString (char const* text) { TRI_json_t* TRI_JsonString (TRI_memory_zone_t* zone, char const* text) {
return TRI_Json2String(text, 0); return TRI_Json2String(zone, text, 0);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief parses a json file /// @brief parses a json file
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_JsonFile (char const* path, char** error) { TRI_json_t* TRI_JsonFile (TRI_memory_zone_t* zone, char const* path, char** error) {
FILE* in; FILE* in;
TRI_json_t* object; TRI_json_t* object;
int c; int c;
@ -2705,13 +2743,14 @@ TRI_json_t* TRI_JsonFile (char const* path, char** error) {
tri_jsp_lex_init(&scanner); tri_jsp_lex_init(&scanner);
yyg = (struct yyguts_t*) scanner; yyg = (struct yyguts_t*) scanner;
yyextra._memoryZone = zone;
yyin = in; yyin = in;
c = tri_jsp_lex(scanner); c = tri_jsp_lex(scanner);
object = ParseObject(scanner, c); object = ParseObject(scanner, c);
if (object == NULL) { if (object == NULL) {
LOG_DEBUG("failed to parse json object: '%s'", yyextra.message); LOG_DEBUG("failed to parse json object: '%s'", yyextra._message);
} }
else { else {
c = tri_jsp_lex(scanner); c = tri_jsp_lex(scanner);
@ -2723,8 +2762,8 @@ TRI_json_t* TRI_JsonFile (char const* path, char** error) {
} }
if (error != NULL) { if (error != NULL) {
if (yyextra.message != NULL) { if (yyextra._message != NULL) {
*error = TRI_DuplicateString(yyextra.message); *error = TRI_DuplicateString(yyextra._message);
} }
else { else {
*error = NULL; *error = NULL;

View File

@ -69,7 +69,8 @@ PLUS [+]
#define UNQUOTED_STRING 12 #define UNQUOTED_STRING 12
struct jsonData { struct jsonData {
char const* message; char const* _message;
TRI_memory_zone_t* _memoryZone;
}; };
#define YY_FATAL_ERROR(a) \ #define YY_FATAL_ERROR(a) \
@ -179,9 +180,10 @@ static TRI_json_t* ParseList (yyscan_t scanner) {
bool comma; bool comma;
int c; int c;
list = TRI_CreateListJson(); list = TRI_CreateListJson(yyextra._memoryZone);
if (list == NULL) { if (list == NULL) {
yyextra._message = "out-of-memory";
return NULL; return NULL;
} }
@ -197,8 +199,8 @@ static TRI_json_t* ParseList (yyscan_t scanner) {
if (comma) { if (comma) {
if (c != COMMA) { if (c != COMMA) {
TRI_FreeJson(list); TRI_FreeJson(yyextra._memoryZone, list);
yyextra.message = "expecting comma"; yyextra._message = "expecting comma";
return NULL; return NULL;
} }
@ -211,17 +213,17 @@ static TRI_json_t* ParseList (yyscan_t scanner) {
sub = ParseObject(scanner, c); sub = ParseObject(scanner, c);
if (sub == NULL) { if (sub == NULL) {
TRI_FreeJson(list); TRI_FreeJson(yyextra._memoryZone, list);
return NULL; return NULL;
} }
TRI_PushBack3ListJson(list, sub); TRI_PushBack3ListJson(yyextra._memoryZone, list, sub);
c = yylex(scanner); c = yylex(scanner);
} }
TRI_FreeJson(list); TRI_FreeJson(yyextra._memoryZone, list);
yyextra.message = "expecting a list element, got end-of-file"; yyextra._message = "expecting a list element, got end-of-file";
return NULL; return NULL;
} }
@ -243,7 +245,11 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
size_t outLength; size_t outLength;
comma = false; comma = false;
array = TRI_CreateArrayJson(); array = TRI_CreateArrayJson(yyextra._memoryZone);
if (array == NULL) {
yyextra._message = "out-of-memory";
}
c = yylex(scanner); c = yylex(scanner);
@ -254,8 +260,8 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
if (comma) { if (comma) {
if (c != COMMA) { if (c != COMMA) {
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
yyextra.message = "expecting comma"; yyextra._message = "expecting comma";
return NULL; return NULL;
} }
@ -267,22 +273,22 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
// attribute name // attribute name
if (c != STRING_CONSTANT) { if (c != STRING_CONSTANT) {
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
yyextra.message = "expecting attribute name"; yyextra._message = "expecting attribute name";
return NULL; return NULL;
} }
ptr = yytext; ptr = yytext;
len = yyleng; len = yyleng;
name = TRI_UnescapeUtf8String(ptr + 1, len - 2, &outLength); name = TRI_UnescapeUtf8StringZ(yyextra._memoryZone, ptr + 1, len - 2, &outLength);
// followed by a colon // followed by a colon
c = yylex(scanner); c = yylex(scanner);
if (c != COLON) { if (c != COLON) {
TRI_FreeString(name); TRI_FreeString(yyextra._memoryZone, name);
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
yyextra.message = "expecting colon"; yyextra._message = "expecting colon";
return NULL; return NULL;
} }
@ -291,19 +297,19 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
sub = ParseObject(scanner, c); sub = ParseObject(scanner, c);
if (sub == NULL) { if (sub == NULL) {
TRI_FreeString(name); TRI_FreeString(yyextra._memoryZone, name);
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
return NULL; return NULL;
} }
TRI_Insert3ArrayJson(array, name, sub); TRI_Insert3ArrayJson(yyextra._memoryZone, array, name, sub);
TRI_FreeString(name); TRI_FreeString(yyextra._memoryZone, name);
c = yylex(scanner); c = yylex(scanner);
} }
TRI_FreeJson(array); TRI_FreeJson(yyextra._memoryZone, array);
yyextra.message = "expecting a object attribute name or element, got end-of-file"; yyextra._message = "expecting a object attribute name or element, got end-of-file";
return NULL; return NULL;
} }
@ -314,20 +320,39 @@ static TRI_json_t* ParseArray (yyscan_t scanner) {
static TRI_json_t* ParseObject (yyscan_t scanner, int c) { static TRI_json_t* ParseObject (yyscan_t scanner, int c) {
struct yyguts_t * yyg = (struct yyguts_t*) scanner; struct yyguts_t * yyg = (struct yyguts_t*) scanner;
TRI_json_t* result;
switch (c) { switch (c) {
case END_OF_FILE: case END_OF_FILE:
yyextra.message = "expecting atom, got end-of-file"; yyextra._message = "expecting atom, got end-of-file";
return NULL; return NULL;
case FALSE_CONSTANT: case FALSE_CONSTANT:
return TRI_CreateBooleanJson(false); result = TRI_CreateBooleanJson(yyextra._memoryZone, false);
if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
case TRUE_CONSTANT: case TRUE_CONSTANT:
return TRI_CreateBooleanJson(true); result = TRI_CreateBooleanJson(yyextra._memoryZone, true);
if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
case NULL_CONSTANT: case NULL_CONSTANT:
return TRI_CreateNullJson(); result = TRI_CreateNullJson(yyextra._memoryZone);
if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
case NUMBER_CONSTANT: { case NUMBER_CONSTANT: {
char buffer[512]; char buffer[512];
@ -335,7 +360,7 @@ static TRI_json_t* ParseObject (yyscan_t scanner, int c) {
double d; double d;
if ((size_t) yyleng >= sizeof(buffer)) { if ((size_t) yyleng >= sizeof(buffer)) {
yyextra.message = "number too big"; yyextra._message = "number too big";
return NULL; return NULL;
} }
@ -345,60 +370,71 @@ static TRI_json_t* ParseObject (yyscan_t scanner, int c) {
d = strtod(buffer, &ep); d = strtod(buffer, &ep);
if (d == HUGE_VAL && errno == ERANGE) { if (d == HUGE_VAL && errno == ERANGE) {
yyextra.message = "number too big"; yyextra._message = "number too big";
return NULL; return NULL;
} }
if (d == 0 && errno == ERANGE) { if (d == 0 && errno == ERANGE) {
yyextra.message = "number too small"; yyextra._message = "number too small";
return NULL; return NULL;
} }
if (ep != buffer + yyleng) { if (ep != buffer + yyleng) {
yyextra.message = "cannot parse number"; yyextra._message = "cannot parse number";
return NULL; return NULL;
} }
return TRI_CreateNumberJson(d); result = TRI_CreateNumberJson(yyextra._memoryZone, d);
if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
} }
case STRING_CONSTANT: { case STRING_CONSTANT: {
char* ptr; char* ptr;
size_t outLength; size_t outLength;
ptr = TRI_UnescapeUtf8String(yytext + 1, yyleng - 2, &outLength); ptr = TRI_UnescapeUtf8StringZ(yyextra._memoryZone, yytext + 1, yyleng - 2, &outLength);
result = TRI_CreateString2Json(yyextra._memoryZone, ptr, outLength);
return TRI_CreateString2Json(ptr, outLength); if (result == NULL) {
yyextra._message = "out-of-memory";
}
return result;
} }
case OPEN_BRACE: case OPEN_BRACE:
return ParseArray(scanner); return ParseArray(scanner);
case CLOSE_BRACE: case CLOSE_BRACE:
yyextra.message = "expected object, got '}'"; yyextra._message = "expected object, got '}'";
return NULL; return NULL;
case OPEN_BRACKET: case OPEN_BRACKET:
return ParseList(scanner); return ParseList(scanner);
case CLOSE_BRACKET: case CLOSE_BRACKET:
yyextra.message = "expected object, got ']'"; yyextra._message = "expected object, got ']'";
return NULL; return NULL;
case COMMA: case COMMA:
yyextra.message = "expected object, got ','"; yyextra._message = "expected object, got ','";
return NULL; return NULL;
case COLON: case COLON:
yyextra.message = "expected object, got ':'"; yyextra._message = "expected object, got ':'";
return NULL; return NULL;
case UNQUOTED_STRING: case UNQUOTED_STRING:
yyextra.message = "expected object, got unquoted string"; yyextra._message = "expected object, got unquoted string";
return NULL; return NULL;
} }
yyextra.message = "unknown atom"; yyextra._message = "unknown atom";
return NULL; return NULL;
} }
@ -419,7 +455,7 @@ static TRI_json_t* ParseObject (yyscan_t scanner, int c) {
/// @brief parses a json string /// @brief parses a json string
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_Json2String (char const* text, char** error) { TRI_json_t* TRI_Json2String (TRI_memory_zone_t* zone, char const* text, char** error) {
TRI_json_t* object; TRI_json_t* object;
YY_BUFFER_STATE buf; YY_BUFFER_STATE buf;
int c; int c;
@ -431,13 +467,15 @@ TRI_json_t* TRI_Json2String (char const* text, char** error) {
yylex_init(&scanner); yylex_init(&scanner);
yyg = (struct yyguts_t*) scanner; yyg = (struct yyguts_t*) scanner;
yyextra._memoryZone = zone;
buf = yy_scan_string((char yyconst*) text, scanner); buf = yy_scan_string((char yyconst*) text, scanner);
c = yylex(scanner); c = yylex(scanner);
object = ParseObject(scanner, c); object = ParseObject(scanner, c);
if (object == NULL) { if (object == NULL) {
LOG_DEBUG("failed to parse json object: '%s'", yyextra.message); LOG_DEBUG("failed to parse json object: '%s'", yyextra._message);
} }
else { else {
c = yylex(scanner); c = yylex(scanner);
@ -449,8 +487,8 @@ TRI_json_t* TRI_Json2String (char const* text, char** error) {
} }
if (error != NULL) { if (error != NULL) {
if (yyextra.message != 0) { if (yyextra._message != 0) {
*error = TRI_DuplicateString(yyextra.message); *error = TRI_DuplicateString(yyextra._message);
} }
else { else {
*error = NULL; *error = NULL;
@ -467,15 +505,15 @@ TRI_json_t* TRI_Json2String (char const* text, char** error) {
/// @brief parses a json string /// @brief parses a json string
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_JsonString (char const* text) { TRI_json_t* TRI_JsonString (TRI_memory_zone_t* zone, char const* text) {
return TRI_Json2String(text, 0); return TRI_Json2String(zone, text, 0);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief parses a json file /// @brief parses a json file
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_JsonFile (char const* path, char** error) { TRI_json_t* TRI_JsonFile (TRI_memory_zone_t* zone, char const* path, char** error) {
FILE* in; FILE* in;
TRI_json_t* object; TRI_json_t* object;
int c; int c;
@ -493,13 +531,14 @@ TRI_json_t* TRI_JsonFile (char const* path, char** error) {
yylex_init(&scanner); yylex_init(&scanner);
yyg = (struct yyguts_t*) scanner; yyg = (struct yyguts_t*) scanner;
yyextra._memoryZone = zone;
yyin = in; yyin = in;
c = yylex(scanner); c = yylex(scanner);
object = ParseObject(scanner, c); object = ParseObject(scanner, c);
if (object == NULL) { if (object == NULL) {
LOG_DEBUG("failed to parse json object: '%s'", yyextra.message); LOG_DEBUG("failed to parse json object: '%s'", yyextra._message);
} }
else { else {
c = yylex(scanner); c = yylex(scanner);
@ -511,8 +550,8 @@ TRI_json_t* TRI_JsonFile (char const* path, char** error) {
} }
if (error != NULL) { if (error != NULL) {
if (yyextra.message != NULL) { if (yyextra._message != NULL) {
*error = TRI_DuplicateString(yyextra.message); *error = TRI_DuplicateString(yyextra._message);
} }
else { else {
*error = NULL; *error = NULL;

View File

@ -152,7 +152,7 @@ static void OutputMachine (string const& text, LoggerData::Info const& info) {
char const* end = format + LoggerFormat.size(); char const* end = format + LoggerFormat.size();
time_t tt = time(0); time_t tt = time(0);
StringBuffer line; StringBuffer line(TRI_CORE_MEM_ZONE);
for (; format < end; ++format) { for (; format < end; ++format) {
if (*format == '%') { if (*format == '%') {

View File

@ -174,13 +174,13 @@ struct option * InitOptionStructure (struct option * option,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void FreeOption (TRI_PO_desc_t* desc, void const * input, void * output) { static void FreeOption (TRI_PO_desc_t* desc, void const * input, void * output) {
TRI_FreeString(desc->_name); TRI_FreeString(TRI_CORE_MEM_ZONE, desc->_name);
if (desc->_desc != NULL) { if (desc->_desc != NULL) {
TRI_FreeString(desc->_desc); TRI_FreeString(TRI_CORE_MEM_ZONE, desc->_desc);
} }
TRI_Free(desc); TRI_Free(TRI_CORE_MEM_ZONE, desc);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -440,7 +440,7 @@ static void ParseStringArg (char const * userarg, void * value) {
desc = (TRI_PO_string_t*) value; desc = (TRI_PO_string_t*) value;
if (*desc->_value != NULL) { if (*desc->_value != NULL) {
TRI_Free(*desc->_value); TRI_Free(TRI_CORE_MEM_ZONE, *desc->_value);
} }
*desc->_value = TRI_DuplicateString(userarg); *desc->_value = TRI_DuplicateString(userarg);
@ -736,7 +736,7 @@ static bool HandleOption (TRI_program_options_t * options,
item = TRI_AtVector(&options->_items, i); item = TRI_AtVector(&options->_items, i);
if (TRI_EqualString(full, item->_desc->_name)) { if (TRI_EqualString(full, item->_desc->_name)) {
TRI_FreeString(full); TRI_FreeString(TRI_CORE_MEM_ZONE, full);
item->parse(value, item->_desc); item->parse(value, item->_desc);
item->_used = true; item->_used = true;
@ -745,7 +745,7 @@ static bool HandleOption (TRI_program_options_t * options,
} }
} }
TRI_FreeString(full); TRI_FreeString(TRI_CORE_MEM_ZONE, full);
return false; return false;
} }
@ -930,13 +930,13 @@ static void UsageVectorStringNode (TRI_PO_vector_string_t * desc, void const * i
TRI_PO_section_t* TRI_CreatePODescription (char const *description) { TRI_PO_section_t* TRI_CreatePODescription (char const *description) {
TRI_PO_section_t * desc; TRI_PO_section_t * desc;
desc = TRI_Allocate(sizeof(TRI_PO_section_t)); desc = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_PO_section_t));
desc->base._type = TRI_PO_SECTION; desc->base._type = TRI_PO_SECTION;
desc->base._name = TRI_DuplicateString("Program Options"); desc->base._name = TRI_DuplicateString("Program Options");
desc->base._desc = (description != NULL) ? TRI_DuplicateString(description) : NULL; desc->base._desc = (description != NULL) ? TRI_DuplicateString(description) : NULL;
TRI_InitVectorPointer(&desc->_children); TRI_InitVectorPointer(&desc->_children, TRI_CORE_MEM_ZONE);
return desc; return desc;
} }
@ -973,10 +973,10 @@ TRI_program_options_t * TRI_CreateProgramOptions (TRI_PO_section_t * desc) {
po_visit_functions_t optionBuilders; po_visit_functions_t optionBuilders;
struct option nullOpt; struct option nullOpt;
po = TRI_Allocate(sizeof(TRI_program_options_t)); po = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_program_options_t));
TRI_InitVector(&po->_longopts, sizeof(struct option)); TRI_InitVector(&po->_longopts, TRI_CORE_MEM_ZONE, sizeof(struct option));
TRI_InitVector(&po->_items, sizeof(TRI_PO_item_t)); TRI_InitVector(&po->_items, TRI_CORE_MEM_ZONE, sizeof(TRI_PO_item_t));
optionBuilders.visitDoubleNode = CreateDoubleOption; optionBuilders.visitDoubleNode = CreateDoubleOption;
optionBuilders.visitFlagNode = CreateFlagOption; optionBuilders.visitFlagNode = CreateFlagOption;
@ -998,7 +998,7 @@ TRI_program_options_t * TRI_CreateProgramOptions (TRI_PO_section_t * desc) {
TRI_PushBackVector(&po->_longopts, &nullOpt); TRI_PushBackVector(&po->_longopts, &nullOpt);
// setup argument vector // setup argument vector
TRI_InitVectorString(&po->_arguments); TRI_InitVectorString(&po->_arguments, TRI_CORE_MEM_ZONE);
return po; return po;
} }
@ -1019,7 +1019,7 @@ void TRI_DestroyProgramOptions (TRI_program_options_t * options) {
void TRI_FreeProgramOptions (TRI_program_options_t * options) { void TRI_FreeProgramOptions (TRI_program_options_t * options) {
TRI_DestroyProgramOptions(options); TRI_DestroyProgramOptions(options);
TRI_Free(options); TRI_Free(TRI_CORE_MEM_ZONE, options);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1049,7 +1049,7 @@ void TRI_AddDoublePODescription (TRI_PO_section_t * desc,
assert(name != NULL); assert(name != NULL);
assert(variable != NULL); assert(variable != NULL);
res = TRI_Allocate(sizeof(po_double_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(po_double_t));
res->base._type = TRI_PO_DOUBLE; res->base._type = TRI_PO_DOUBLE;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1074,7 +1074,7 @@ void TRI_AddFlagPODescription (TRI_PO_section_t * desc,
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(po_flag_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(po_flag_t));
res->base._type = TRI_PO_FLAG; res->base._type = TRI_PO_FLAG;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1101,7 +1101,7 @@ void TRI_AddInt16PODescription (TRI_PO_section_t * desc,
assert(variable != NULL); assert(variable != NULL);
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(po_int16_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(po_int16_t));
res->base._type = TRI_PO_INT16; res->base._type = TRI_PO_INT16;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1128,7 +1128,7 @@ void TRI_AddInt32PODescription (TRI_PO_section_t * desc,
assert(variable != NULL); assert(variable != NULL);
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(po_int32_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(po_int32_t));
res->base._type = TRI_PO_INT32; res->base._type = TRI_PO_INT32;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1155,7 +1155,7 @@ void TRI_AddInt64PODescription (TRI_PO_section_t * desc,
assert(variable != NULL); assert(variable != NULL);
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(po_int64_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(po_int64_t));
res->base._type = TRI_PO_INT64; res->base._type = TRI_PO_INT64;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1181,7 +1181,7 @@ void TRI_AddStringPODescription (TRI_PO_section_t * desc,
assert(variable != NULL); assert(variable != NULL);
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(TRI_PO_string_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_PO_string_t));
res->base._type = TRI_PO_STRING; res->base._type = TRI_PO_STRING;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1208,7 +1208,7 @@ void TRI_AddUInt16PODescription (TRI_PO_section_t * desc,
assert(variable != NULL); assert(variable != NULL);
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(po_uint16_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(po_uint16_t));
res->base._type = TRI_PO_UINT16; res->base._type = TRI_PO_UINT16;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1235,7 +1235,7 @@ void TRI_AddUInt32PODescription (TRI_PO_section_t * desc,
assert(variable != NULL); assert(variable != NULL);
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(po_uint32_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(po_uint32_t));
res->base._type = TRI_PO_UINT32; res->base._type = TRI_PO_UINT32;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1262,7 +1262,7 @@ void TRI_AddUInt64PODescription (TRI_PO_section_t * desc,
assert(variable != NULL); assert(variable != NULL);
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(po_uint64_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(po_uint64_t));
res->base._type = TRI_PO_UINT64; res->base._type = TRI_PO_UINT64;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1289,7 +1289,7 @@ void TRI_AddVectorStringPODescription (TRI_PO_section_t * desc,
assert(variable != NULL); assert(variable != NULL);
assert(name != NULL); assert(name != NULL);
res = TRI_Allocate(sizeof(TRI_PO_vector_string_t)); res = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_PO_vector_string_t));
res->base._type = TRI_PO_VECTOR_STRING; res->base._type = TRI_PO_VECTOR_STRING;
res->base._name = TRI_DuplicateString(name); res->base._name = TRI_DuplicateString(name);
@ -1333,7 +1333,7 @@ char * TRI_UsagePODescription (TRI_PO_section_t * desc) {
visitors.visitUInt64Node = UsageUInt64Node; visitors.visitUInt64Node = UsageUInt64Node;
visitors.visitVectorStringNode = UsageVectorStringNode; visitors.visitVectorStringNode = UsageVectorStringNode;
TRI_InitStringBuffer(&buffer); TRI_InitStringBuffer(&buffer, TRI_CORE_MEM_ZONE);
VisitProgramOptions(&desc->base, &visitors, NULL, &buffer); VisitProgramOptions(&desc->base, &visitors, NULL, &buffer);
// the caller has to free this buffer // the caller has to free this buffer
@ -1360,7 +1360,7 @@ bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t * options,
TRI_set_errno(TRI_ERROR_NO_ERROR); TRI_set_errno(TRI_ERROR_NO_ERROR);
TRI_InitStringBuffer(&buffer); TRI_InitStringBuffer(&buffer, TRI_CORE_MEM_ZONE);
for (i = 0; i < options->_items._length; ++i) { for (i = 0; i < options->_items._length; ++i) {
item = TRI_AtVector(&options->_items, i); item = TRI_AtVector(&options->_items, i);
@ -1511,7 +1511,7 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
res = regexec(&re1, buffer, 0, 0, 0); res = regexec(&re1, buffer, 0, 0, 0);
if (res == 0) { if (res == 0) {
TRI_FreeString(buffer); TRI_FreeString(TRI_CORE_MEM_ZONE, buffer);
buffer = NULL; buffer = NULL;
continue; continue;
} }
@ -1520,10 +1520,10 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
res = regexec(&re2, buffer, sizeof(matches) / sizeof(matches[0]), matches, 0); res = regexec(&re2, buffer, sizeof(matches) / sizeof(matches[0]), matches, 0);
if (res == 0) { if (res == 0) {
TRI_FreeString(section); TRI_FreeString(TRI_CORE_MEM_ZONE, section);
section = TRI_DuplicateString2(buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so); section = TRI_DuplicateString2(buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
TRI_FreeString(buffer); TRI_FreeString(TRI_CORE_MEM_ZONE, buffer);
buffer = NULL; buffer = NULL;
continue; continue;
@ -1536,12 +1536,12 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
option = TRI_DuplicateString2(buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so); option = TRI_DuplicateString2(buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
value = TRI_DuplicateString2(buffer + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so); value = TRI_DuplicateString2(buffer + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
TRI_FreeString(buffer); TRI_FreeString(TRI_CORE_MEM_ZONE, buffer);
buffer = NULL; buffer = NULL;
ok = HandleOption(options, section, option, value); ok = HandleOption(options, section, option, value);
TRI_FreeString(value); TRI_FreeString(TRI_CORE_MEM_ZONE, value);
if (! ok) { if (! ok) {
TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION); TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION);
@ -1553,11 +1553,11 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
fprintf(stderr, "%s: unrecognized option '%s'\n", programName, option); fprintf(stderr, "%s: unrecognized option '%s'\n", programName, option);
} }
TRI_FreeString(option); TRI_FreeString(TRI_CORE_MEM_ZONE, option);
break; break;
} }
TRI_FreeString(option); TRI_FreeString(TRI_CORE_MEM_ZONE, option);
continue; continue;
} }
@ -1567,7 +1567,7 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
if (res == 0) { if (res == 0) {
option = TRI_DuplicateString2(buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so); option = TRI_DuplicateString2(buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
TRI_FreeString(buffer); TRI_FreeString(TRI_CORE_MEM_ZONE, buffer);
buffer = NULL; buffer = NULL;
ok = HandleOption(options, section, option, ""); ok = HandleOption(options, section, option, "");
@ -1582,11 +1582,11 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
fprintf(stderr, "%s: unrecognized option '%s'\n", programName, option); fprintf(stderr, "%s: unrecognized option '%s'\n", programName, option);
} }
TRI_FreeString(option); TRI_FreeString(TRI_CORE_MEM_ZONE, option);
break; break;
} }
TRI_FreeString(option); TRI_FreeString(TRI_CORE_MEM_ZONE, option);
continue; continue;
} }
@ -1598,24 +1598,24 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
option = TRI_DuplicateString2(buffer + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so); option = TRI_DuplicateString2(buffer + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
value = TRI_DuplicateString2(buffer + matches[3].rm_so, matches[3].rm_eo - matches[3].rm_so); value = TRI_DuplicateString2(buffer + matches[3].rm_so, matches[3].rm_eo - matches[3].rm_so);
TRI_FreeString(buffer); TRI_FreeString(TRI_CORE_MEM_ZONE, buffer);
buffer = NULL; buffer = NULL;
ok = HandleOption(options, tmpSection, option, value); ok = HandleOption(options, tmpSection, option, value);
TRI_FreeString(value); TRI_FreeString(TRI_CORE_MEM_ZONE, value);
if (! ok) { if (! ok) {
TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION); TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION);
fprintf(stderr, "%s: unrecognized option '%s.%s'\n", programName, tmpSection, option); fprintf(stderr, "%s: unrecognized option '%s.%s'\n", programName, tmpSection, option);
TRI_FreeString(tmpSection); TRI_FreeString(TRI_CORE_MEM_ZONE, tmpSection);
TRI_FreeString(option); TRI_FreeString(TRI_CORE_MEM_ZONE, option);
break; break;
} }
TRI_FreeString(tmpSection); TRI_FreeString(TRI_CORE_MEM_ZONE, tmpSection);
TRI_FreeString(option); TRI_FreeString(TRI_CORE_MEM_ZONE, option);
continue; continue;
} }
@ -1626,7 +1626,7 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
tmpSection = TRI_DuplicateString2(buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so); tmpSection = TRI_DuplicateString2(buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
option = TRI_DuplicateString2(buffer + matches[2].rm_so, matches[2].rm_eo - matches[1].rm_so); option = TRI_DuplicateString2(buffer + matches[2].rm_so, matches[2].rm_eo - matches[1].rm_so);
TRI_FreeString(buffer); TRI_FreeString(TRI_CORE_MEM_ZONE, buffer);
buffer = NULL; buffer = NULL;
ok = HandleOption(options, tmpSection, option, ""); ok = HandleOption(options, tmpSection, option, "");
@ -1635,29 +1635,29 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t * options,
TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION); TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION);
fprintf(stderr, "%s: unrecognized option '%s.%s'\n", programName, tmpSection, option); fprintf(stderr, "%s: unrecognized option '%s.%s'\n", programName, tmpSection, option);
TRI_FreeString(tmpSection); TRI_FreeString(TRI_CORE_MEM_ZONE, tmpSection);
TRI_FreeString(option); TRI_FreeString(TRI_CORE_MEM_ZONE, option);
break; break;
} }
TRI_FreeString(tmpSection); TRI_FreeString(TRI_CORE_MEM_ZONE, tmpSection);
TRI_FreeString(option); TRI_FreeString(TRI_CORE_MEM_ZONE, option);
continue; continue;
} }
TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION); TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION);
fprintf(stderr, "%s: unrecognized entry '%s'\n", programName, buffer); fprintf(stderr, "%s: unrecognized entry '%s'\n", programName, buffer);
TRI_FreeString(buffer); TRI_FreeString(TRI_CORE_MEM_ZONE, buffer);
buffer = NULL; buffer = NULL;
break; break;
} }
if (buffer != NULL) { if (buffer != NULL) {
TRI_FreeString(buffer); TRI_FreeString(TRI_CORE_MEM_ZONE, buffer);
} }
TRI_FreeString(section); TRI_FreeString(TRI_CORE_MEM_ZONE, section);
regfree(&re1); regfree(&re1);
regfree(&re2); regfree(&re2);

View File

@ -121,7 +121,7 @@ namespace triagens {
HttpResponse::HttpResponse () HttpResponse::HttpResponse ()
: _code(NOT_IMPLEMENTED), : _code(NOT_IMPLEMENTED),
_headers(5), _headers(5),
_body(), _body(TRI_UNKNOWN_MEM_ZONE),
_isHeadResponse(false), _isHeadResponse(false),
_bodySize(0), _bodySize(0),
_freeables() { _freeables() {
@ -132,7 +132,7 @@ namespace triagens {
HttpResponse::HttpResponse (string const& header) HttpResponse::HttpResponse (string const& header)
: _code(NOT_IMPLEMENTED), : _code(NOT_IMPLEMENTED),
_headers(5), _headers(5),
_body(), _body(TRI_UNKNOWN_MEM_ZONE),
_isHeadResponse(false), _isHeadResponse(false),
_bodySize(0), _bodySize(0),
_freeables() { _freeables() {
@ -144,7 +144,7 @@ namespace triagens {
HttpResponse::HttpResponse (HttpResponseCode code) HttpResponse::HttpResponse (HttpResponseCode code)
: _code(code), : _code(code),
_headers(5), _headers(5),
_body(), _body(TRI_UNKNOWN_MEM_ZONE),
_isHeadResponse(false), _isHeadResponse(false),
_bodySize(0), _bodySize(0),
_freeables() { _freeables() {