Skip to content

Commit

Permalink
note taking
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperthunk committed Apr 14, 2012
1 parent 23499df commit 56679c8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 28 deletions.
33 changes: 9 additions & 24 deletions c_src/erlxsl.h
Expand Up @@ -123,33 +123,12 @@ extern "C" {
memcpy((((item_T*)cmd->command_data.iov->payload.data) + (cmd->command_data.iov->size - 1)), item, sizeof(item_T))) \
: (cmd->command_data.iov->size += 1, cmd->command_data.iov->payload.data = item))

#define write_cmd_data2(item_T, item, cmd) \
do { \
if (cmd != NULL && item != NULL) { \
Int32 size = cmd->command_data.iov->size; \
if (size > 0) { \
Int32 idx = size -1; \
item_T *p = (item_T*)cmd->command_data.iov->payload.data; \
item_T *chunk = (item_T*)cmd->resize(cmd->command_data.iov->payload.data, \
(sizeof(item_T) * cmd->command_data.iov->size)); \
cmd->command_data.iov->payload.data = chunk; \
for (Int32 i = 0; i < idx; i++) { \
chunk[i] = p[i]; \
} \
chunk[idx] = item; \
} else { \
cmd->command_data.iov->size += 1; \
cmd->command_data.iov->payload.data = item; \
} \
} \
} while (false)

/* Resizes the result buffer of 'cmd' using its 'resize' function
* pointer to the 'newsize'. The DriverIOVec size is updated and
* the expression evaluates to the (potentially re-positioned) reassigned buffer.
*/
#define resize_result_buffer(newsize, cmd) \
(cmd->result->payload.buffer = \
(cmd->result->payload.buffer = /* UNSAFE: shouldn't this be an unsigned 32bit int!? */ \
cmd->resize(cmd->result->payload.buffer, cmd->result->size = (Int32)newsize))

#define cmd_buff(cmd) cmd->result->payload.buffer
Expand All @@ -162,6 +141,7 @@ extern "C" {
? NULL /* we cannot proceed */ \
: (cmd->result->dirty == 0) \
? (cmd->result->size < strlen(buff)) \
/* NB: resize_result_buffer expands to an assignment, so no dangling pointers are left behind */
? resize_result_buffer(strlen(buff), cmd) \
/* we've enough room to work here */ \
: (cmd->result->payload.buffer == NULL) \
Expand All @@ -177,6 +157,7 @@ extern "C" {
do { \
if (cmd != NULL && cmd->result != NULL) { \
cmd->result->dirty = 0; \
/* FIXME: shouldn't this be cmd->release(.....) instead? */ \
DRV_FREE(cmd->result->payload.buffer); \
cmd->result->payload.buffer = NULL; \
} \
Expand Down Expand Up @@ -298,7 +279,8 @@ typedef struct {
/* Indicates the type of data in the 'payload' field. */
DataFormat type;
/* Indicates the size of the buffer (or data) where this is necessary. */
Int32 size; // FIXME: this is a big assumption about the MAX response size!
Int32 size; // FIXME: should be 64bits not 32 (or switch on build settings)
// UNSAFE: size should be unsigned!!!
union {
/* Maintaining our response data in a buffer. */
char* buffer;
Expand All @@ -307,7 +289,7 @@ typedef struct {
} payload;
} DriverIOVec;

/* Stores the data an input type specifier for an input document. */
/* Stores an input type specifier for an input document. */
typedef struct {
/*
* Indicates whether the buffer contains the document
Expand All @@ -324,6 +306,9 @@ typedef struct {
typedef struct {
/* Stores the port associated with the current driver instance. */
void* port;
// FIXME: this type probably changes between different compiled beam installs
// therefore we should either reference the right header (erl_driver?)
// or use a void pointer and cast it back to ErlDrvPort in the driver code.
/* Stores the calling process' Pid. */
unsigned long caller_pid;
} DriverContext;
Expand Down
2 changes: 1 addition & 1 deletion ebin/erlxsl.app
Expand Up @@ -16,4 +16,4 @@ erlxsl,
[{driver_options,
[{engine,"default_provider"},
{driver,"erlxsl"},
{load_path,"priv/bin"}]}]}]}.
{load_path,"priv/bin"}]}]}]}.
3 changes: 2 additions & 1 deletion inttest/rebar.config
@@ -1 +1,2 @@
{deps, [{cspec, "*", {git, "https://github.com/visionmedia/cspec.git", "master"}}]}.
{deps, [{cspec, "*",
{git, "https://github.com/visionmedia/cspec.git", "master"}}]}.
2 changes: 1 addition & 1 deletion inttest/spec/ei.spec
Expand Up @@ -68,7 +68,7 @@ describe "Decoding Buffers using EI"
);
state should be OutOfMemory;
free_command(cmd);
end
end

end

2 changes: 1 addition & 1 deletion inttest/spec/init_types.spec
Expand Up @@ -282,7 +282,7 @@ describe "Initializing XslTask Structures"
state should be Success;
char *s = assert_failed;

s should have_failed_due_to "hsize->input_size == strlen(xml)";
s should have_failed_due_to "hsize->input_size == strlen(xml)";

free_task(task);
end
Expand Down

0 comments on commit 56679c8

Please sign in to comment.