Skip to content

Commit

Permalink
Better lto and bytestring builder
Browse files Browse the repository at this point in the history
  • Loading branch information
PJK committed Apr 30, 2015
1 parent 098340b commit 8e75783
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
include(CPack)

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -pedantic -g -ggdb -DDEBUG=true")
set(CMAKE_C_FLAGS_RELEASE "-O3 -Wall -pedantic -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O3 -flto -Wall -pedantic -DNDEBUG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")

set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto")

enable_testing()

Expand Down
2 changes: 1 addition & 1 deletion examples/streaming_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main(int argc, char * argv[])
size_t bytes_read = 0;
callbacks.string = find_string;
while (bytes_read < info.st_size) {
cbor_stream_decode(buffer, info.st_size - bytes_read, &callbacks, NULL);
decode_result = cbor_stream_decode(buffer, info.st_size - bytes_read, &callbacks, NULL);
bytes_read += decode_result.read;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/cbor/bytestrings.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* it under the terms of the MIT license. See LICENSE for details.
*/

#include <string.h>
#include "bytestrings.h"

size_t cbor_bytestring_length(const cbor_item_t *item)
Expand Down Expand Up @@ -58,6 +59,15 @@ cbor_item_t *cbor_new_indefinite_bytestring()
return item;
}

cbor_item_t *cbor_build_bytestringstring(cbor_data handle, size_t length)
{
cbor_item_t *res = cbor_new_definite_bytestring();
void * content = _CBOR_MALLOC(length);
memcpy(content, handle, length);
cbor_bytestring_set_handle(res, content, length);
return res;
}

void cbor_bytestring_set_handle(cbor_item_t *item, unsigned char *data, size_t length)
{
assert(cbor_isa_bytestring(item));
Expand Down
30 changes: 19 additions & 11 deletions src/cbor/bytestrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,31 @@
* ============================================================================
*/

size_t cbor_bytestring_length(const cbor_item_t * item);
bool cbor_bytestring_is_definite(const cbor_item_t * item);
bool cbor_bytestring_is_indefinite(const cbor_item_t * item);
unsigned char * cbor_bytestring_handle(const cbor_item_t * item);
size_t cbor_bytestring_length(const cbor_item_t *item);

void cbor_bytestring_set_handle(cbor_item_t * item, unsigned char * data, size_t length);
bool cbor_bytestring_is_definite(const cbor_item_t *item);

bool cbor_bytestring_is_indefinite(const cbor_item_t *item);

unsigned char *cbor_bytestring_handle(const cbor_item_t *item);

void cbor_bytestring_set_handle(cbor_item_t *item, unsigned char *data, size_t length);

/* Indefinite bytestrings only */
cbor_item_t * * cbor_bytestring_chunks_handle(const cbor_item_t * item);
size_t cbor_bytestring_chunk_count(const cbor_item_t * item);
cbor_item_t **cbor_bytestring_chunks_handle(const cbor_item_t *item);

size_t cbor_bytestring_chunk_count(const cbor_item_t *item);

/* Returns NULL on realloc failure */
cbor_item_t * cbor_bytestring_add_chunk(cbor_item_t * item, cbor_item_t * chunk);
cbor_item_t * cbor_bytestring_concatenate(cbor_item_t * item);
cbor_item_t *cbor_bytestring_add_chunk(cbor_item_t *item, cbor_item_t *chunk);

cbor_item_t *cbor_bytestring_concatenate(cbor_item_t *item);

cbor_item_t *cbor_new_definite_bytestring();

cbor_item_t *cbor_new_indefinite_bytestring();

cbor_item_t * cbor_new_definite_bytestring();
cbor_item_t * cbor_new_indefinite_bytestring();
cbor_item_t *cbor_build_bytestringstring(cbor_data handle, size_t length);


#endif //LIBCBOR_BYTESTRINGS_H

0 comments on commit 8e75783

Please sign in to comment.