FAQ

svn commit: r883210 - in /lucene/lucy/trunk/charmonizer/src/Charmonizer: Core/Compiler.c Core/Compiler.h Core/HeadCheck.c Core/ModHandler.c Core/OperSys.c Core/Util.c Core/Util.h Probe/Headers.c Probe/Integers.c Probe/LargeFiles.c

Marvin
Nov 23, 2009 at 2:07 am
Author: marvin
Date: Mon Nov 23 02:06:41 2009
New Revision: 883210

URL: http://svn.apache.org/viewvc?rev=883210&view=rev
Log:
Commit part of LUCY-68. Remove several string handling functions from Util.h
and replace their functionality with local use of malloc(), free() and
sprintf().

Modified:
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/HeadCheck.c
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.c
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperSys.c
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h
lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Headers.c
lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Integers.c
lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/LargeFiles.c

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c Mon Nov 23 02:06:41 2009
@@ -13,11 +13,11 @@
S_destroy(Compiler *self);

static chaz_bool_t
-S_compile_exe(Compiler *self, const char *source_path, const char *exe_path,
+S_compile_exe(Compiler *self, const char *source_path, const char *exe_name,
const char *code, size_t code_len);

static chaz_bool_t
-S_compile_obj(Compiler *self, const char *source_path, const char *obj_path,
+S_compile_obj(Compiler *self, const char *source_path, const char *obj_name,
const char *code, size_t code_len);

static void
@@ -41,8 +41,6 @@
self->cc_flags = strdup(cc_flags);

/* init */
- self->buf = NULL;
- self->buf_len = 0;
self->compile_exe = S_compile_exe;
self->compile_obj = S_compile_obj;
self->add_inc_dir = S_add_inc_dir;
@@ -73,7 +71,6 @@
}
free(self->inc_dirs);

- free(self->buf);
free(self->cc_command);
free(self->cc_flags);
free(self->include_flag);
@@ -82,81 +79,124 @@
free(self);
}

-static chaz_bool_t
-S_compile_exe(Compiler *self, const char *source_path, const char *exe_path,
- const char *code, size_t code_len)
+static char*
+S_inc_dir_string(Compiler *self)
{
- chaz_bool_t successful;
- OperSys *os = self->os;
- char *exe_full_filepath = NULL;
+ size_t needed = 0;
+ char *inc_dir_string;
char **inc_dirs;
-
- /* tack the exe_ext onto the path */
- join_strings(&exe_full_filepath, 0, exe_path, os->exe_ext, NULL);
-
- /* write the source file */
- write_file(source_path, code, code_len);
-
- /* prepare the compiler command */
- if (verbosity < 2 && chaz_ModHand_charm_run_available) {
- self->buf_len = join_strings(&(self->buf), self->buf_len,
- os->local_command_start, "_charm_run ", self->cc_command, " ",
- source_path, " ", self->exe_flag, exe_full_filepath, " ", NULL);
- }
- else {
- self->buf_len = join_strings(&(self->buf), self->buf_len,
- self->cc_command, " ", source_path, " ", self->exe_flag,
- exe_full_filepath, " ", NULL);
+ for (inc_dirs = self->inc_dirs; *inc_dirs != NULL; inc_dirs++) {
+ needed += strlen(self->include_flag) + 2;
+ needed += strlen(*inc_dirs);
}
+ inc_dir_string = malloc(needed + 1);
+ inc_dir_string[0] = '\0';
for (inc_dirs = self->inc_dirs; *inc_dirs != NULL; inc_dirs++) {
- self->buf_len = append_strings(&(self->buf), self->buf_len,
- self->include_flag, *inc_dirs, " ", NULL);
+ strcat(inc_dir_string, self->include_flag);
+ strcat(inc_dir_string, *inc_dirs);
+ strcat(inc_dir_string, " ");
}
- self->buf_len = append_strings(&(self->buf), self->buf_len,
- self->cc_flags, " ", NULL);
+ return inc_dir_string;
+}

- /* execute the compiler command and detect success/failure */
- system(self->buf);
- successful = can_open_file(exe_full_filepath);
- free(exe_full_filepath);
+static chaz_bool_t
+S_compile_exe(Compiler *self, const char *source_path, const char *exe_name,
+ const char *code, size_t code_len)
+{
+ OperSys *os = self->os;
+ size_t exe_file_buf_size = strlen(exe_name) + strlen(os->exe_ext) + 1;
+ char *exe_file = malloc(exe_file_buf_size);
+ size_t exe_file_buf_len = sprintf(exe_file, "%s%s", exe_name, os->exe_ext);
+ char *inc_dir_string = S_inc_dir_string(self);
+ size_t command_max_size = strlen(os->local_command_start)
+ + strlen(self->cc_command)
+ + strlen(source_path)
+ + strlen(self->exe_flag)
+ + exe_file_buf_len
+ + strlen(inc_dir_string)
+ + strlen(self->cc_flags)
+ + 200;
+ char *command = malloc(command_max_size);
+ chaz_bool_t result;

- return successful;
+ /* Prepare the compiler command. */
+ if (verbosity < 2 && chaz_ModHand_charm_run_available) {
+ sprintf(command, "%s%s %s %s %s%s %s %s",
+ os->local_command_start, "_charm_run ",
+ self->cc_command, source_path,
+ self->exe_flag, exe_file,
+ inc_dir_string,
+ self->cc_flags);
+ }
+ else {
+ sprintf(command, "%s %s %s%s %s %s",
+ self->cc_command, source_path,
+ self->exe_flag, exe_file,
+ inc_dir_string,
+ self->cc_flags);
+ }
+
+ /* Write the source file. */
+ write_file(source_path, code);
+
+ /* Run the compiler command. See if compilation was successful. */
+ system(command);
+ result = can_open_file(exe_file);
+
+ free(command);
+ free(inc_dir_string);
+ free(exe_file);
+ return result;
}

static chaz_bool_t
-S_compile_obj(Compiler *self, const char *source_path, const char *obj_path,
+S_compile_obj(Compiler *self, const char *source_path, const char *obj_name,
const char *code, size_t code_len)
{
- chaz_bool_t successful;
- OperSys *os = self->os;
- char *obj_full_filepath = NULL;
-
- /* tack the obj_ext onto the path */
- join_strings(&obj_full_filepath, 0, obj_path, os->obj_ext, NULL);
+ OperSys *os = self->os;
+ size_t obj_file_buf_size = strlen(obj_name) + strlen(os->obj_ext) + 1;
+ char *obj_file = malloc(obj_file_buf_size);
+ size_t obj_file_buf_len = sprintf(obj_file, "%s%s", obj_name, os->obj_ext);
+ char *inc_dir_string = S_inc_dir_string(self);
+ size_t command_max_size = strlen(os->local_command_start)
+ + strlen(self->cc_command)
+ + strlen(source_path)
+ + strlen(self->object_flag)
+ + obj_file_buf_len
+ + strlen(inc_dir_string)
+ + strlen(self->cc_flags)
+ + 200;
+ char *command = malloc(command_max_size);
+ chaz_bool_t result;

- /* write the source file */
- write_file(source_path, code, code_len);
-
- /* compile the source */
+ /* Prepare the compiler command. */
if (verbosity < 2 && chaz_ModHand_charm_run_available) {
- join_strings(&(self->buf), self->buf_len,
- os->local_command_start, "_charm_run ", self->cc_command, " ",
- source_path, " ", self->object_flag, obj_full_filepath, " ",
- self->include_flag, ". ", self->cc_flags, NULL);
+ sprintf(command, "%s%s %s %s %s%s %s %s",
+ os->local_command_start, "_charm_run ",
+ self->cc_command, source_path,
+ self->object_flag, obj_file,
+ inc_dir_string,
+ self->cc_flags);
}
else {
- join_strings(&(self->buf), self->buf_len,
- self->cc_command, " ", source_path, " ", self->object_flag,
- obj_full_filepath, " ", self->include_flag, ". ", self->cc_flags,
- NULL);
- }
- system(self->buf);
-
- /* see if compilation was successful */
- successful = can_open_file(obj_full_filepath);
- free(obj_full_filepath);
-
- return successful;
+ sprintf(command, "%s %s %s%s %s %s",
+ self->cc_command, source_path,
+ self->object_flag, obj_file,
+ inc_dir_string,
+ self->cc_flags);
+ }
+
+ /* Write the source file. */
+ write_file(source_path, code);
+
+ /* Run the compiler command. See if compilation was successful. */
+ system(command);
+ result = can_open_file(obj_file);
+
+ free(command);
+ free(inc_dir_string);
+ free(obj_file);
+ return result;
}

static void

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h Mon Nov 23 02:06:41 2009
@@ -45,8 +45,6 @@
char *object_flag;
char *exe_flag;
char **inc_dirs;
- char *buf;
- size_t buf_len;
chaz_CC_compile_exe_t compile_exe;
chaz_CC_compile_obj_t compile_obj;
chaz_CC_add_inc_dir_t add_inc_dir;

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/HeadCheck.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/HeadCheck.c?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/HeadCheck.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/HeadCheck.c Mon Nov 23 02:06:41 2009
@@ -11,9 +11,6 @@
chaz_bool_t exists;
} Header;

-static char *code_buf = NULL;
-static int code_buf_len = 0;
-
/* hello_world.c without the hello or the world */
static char test_code[] = "int main() { return 0; }\n";

@@ -89,14 +86,22 @@
{
chaz_bool_t success;
int i;
+ char *code_buf = strdup("");
+ size_t needed = sizeof(test_code) + 20;

/* build the source code string */
- code_buf_len = join_strings(&code_buf, code_buf_len, " ", NULL);
for (i = 0; header_names[i] != NULL; i++) {
- code_buf_len = append_strings(&code_buf, code_buf_len, "#include <",
- header_names[i], ">\n", NULL);
+ needed += strlen(header_names[i]);
+ needed += sizeof("#include <>\n");
+ }
+ code_buf = malloc(needed);
+ code_buf[0] = '\0';
+ for (i = 0; header_names[i] != NULL; i++) {
+ strcat(code_buf, "#include <");
+ strcat(code_buf, header_names[i]);
+ strcat(code_buf, ">\n");
}
- code_buf_len = append_strings(&code_buf, code_buf_len, test_code, NULL);
+ strcat(code_buf, test_code);

/* if the code compiles, bulk add all header names to the cache */
success = test_compile(code_buf, strlen(code_buf));
@@ -106,6 +111,7 @@
}
}

+ free(code_buf);
return success;
}

@@ -121,13 +127,12 @@
{
long needed = sizeof(contains_code) + strlen(struct_name)
+ strlen(member) + strlen(includes) + 10;
- if (code_buf_len < needed) {
- code_buf_len = needed;
- free(code_buf);
- code_buf = malloc(code_buf_len);
- }
- sprintf(code_buf, contains_code, includes, struct_name, member);
- return test_compile(code_buf, strlen(code_buf));
+ char *buf = malloc(needed);
+ chaz_bool_t retval;
+ sprintf(buf, contains_code, includes, struct_name, member);
+ retval = test_compile(buf, strlen(buf));
+ free(buf);
+ return retval;
}

static int
@@ -144,18 +149,19 @@
}

static Header*
-S_discover_header(const char *header_name) {
+S_discover_header(const char *header_name)
+{
Header* header = (Header*)malloc(sizeof(Header));
+ char *include_test = malloc(strlen(header_name) + 30);

/* assign */
header->name = strdup(header_name);

/* see whether code that tries to pull in this header compiles */
- code_buf_len = join_strings(&code_buf, code_buf_len, "#include <",
- header_name, ">\n", test_code, NULL);
- header->exists = test_compile(code_buf, strlen(code_buf))
- ? true : false;
+ sprintf(include_test, "#include <%s>\n%s", header_name, test_code);
+ header->exists = test_compile(include_test, strlen(include_test));

+ free(include_test);
return header;
}


Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.c?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.c Mon Nov 23 02:06:41 2009
@@ -40,11 +40,13 @@
chaz_ModHand_init()
{
/* set the name of the application which we "try" to execute */
- (void)join_strings(&try_app_path, 0, TRY_APP_BASENAME, os->exe_ext, NULL);
+ try_app_path = malloc(strlen(TRY_APP_BASENAME) + strlen(os->exe_ext) + 1);
+ sprintf(try_app_path, "%s%s", TRY_APP_BASENAME, os->exe_ext);

/* set the invocation string for the "try" application */
- (void)join_strings(&try_app_command, 0, os->local_command_start,
- try_app_path, NULL);
+ try_app_command = malloc(strlen(os->local_command_start) +
+ strlen(try_app_path) + 1);
+ sprintf(try_app_command, "%s%s", os->local_command_start, try_app_path);

/* write files needed by this module and others */
S_build_charm_run();
@@ -100,7 +102,7 @@
static void
S_write_charm_h()
{
- write_file("_charm.h", charm_h_code, strlen(charm_h_code));
+ write_file("_charm.h", charm_h_code);
}

static char charm_run_code_a[] = METAQUOTE
@@ -153,13 +155,23 @@
static void
S_build_charm_run()
{
- char *code = NULL;
chaz_bool_t compile_succeeded = false;
-
- (void)join_strings(&code, 0, charm_run_code_a, charm_run_code_b, " \"",
- os->devnull, "\" ", charm_run_code_c, " \"", os->devnull, "\" ",
- charm_run_code_d, NULL);
-
+ size_t needed = sizeof(charm_run_code_a)
+ + sizeof(charm_run_code_b)
+ + strlen(os->devnull)
+ + sizeof(charm_run_code_c)
+ + strlen(os->devnull)
+ + sizeof(charm_run_code_d)
+ + 20;
+ char *code = malloc(needed);
+
+ sprintf(code, "%s%s \"%s\" %s \"%s\" %s",
+ charm_run_code_a,
+ charm_run_code_b,
+ os->devnull,
+ charm_run_code_c,
+ os->devnull,
+ charm_run_code_d);
compile_succeeded = compiler->compile_exe(compiler, "_charm_run.c",
"_charm_run", code, strlen(code));
if (!compile_succeeded)

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperSys.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperSys.c?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperSys.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperSys.c Mon Nov 23 02:06:41 2009
@@ -98,38 +98,45 @@
static void
S_remove_exe(OperSys *self, char *name)
{
- self->buf_len = join_strings(&(self->buf), self->buf_len, name,
- self->exe_ext, NULL);
- remove(self->buf);
+ char *exe_name = malloc(strlen(name) + strlen(self->exe_ext) + 1);
+ sprintf(exe_name, "%s%s", name, self->exe_ext);
+ remove(exe_name);
+ free(exe_name);
}

static void
S_remove_obj(OperSys *self, char *name)
{
- self->buf_len = join_strings(&(self->buf), self->buf_len, name,
- self->obj_ext, NULL);
- remove(self->buf);
+ char *obj_name = malloc(strlen(name) + strlen(self->obj_ext) + 1);
+ sprintf(obj_name, "%s%s", name, self->obj_ext);
+ remove(obj_name);
+ free(obj_name);
}

static int
S_run_local(OperSys *self, ...)
{
- va_list args;
-
- /* start with "./", ".\", or whatever */
- self->buf_len = join_strings(&(self->buf), self->buf_len,
- self->local_command_start, NULL);
+ va_list args;
+ char *command = strdup(self->local_command_start);
+ size_t len = strlen(command);
+ int retval;
+ char *arg;

/* append all supplied texts */
va_start(args, self);
- self->buf_len = vappend_strings(&(self->buf), self->buf_len, args);
+ while (NULL != (arg = va_arg(args, char*))) {
+ len += strlen(arg);
+ command = realloc(command, len + 1);
+ strcat(command, arg);
+ }
va_end(args);

/* run the command */
- return system(self->buf);
+ retval = system(command);
+ free(command);
+ return retval;
}

-
/**
* Copyright 2006 The Apache Software Foundation
*

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c Mon Nov 23 02:06:41 2009
@@ -10,10 +10,10 @@
int chaz_Util_verbosity = 1;

void
-chaz_Util_write_file(const char *filename, const char *content,
- size_t content_len)
+chaz_Util_write_file(const char *filename, const char *content)
{
FILE *fh = fopen(filename, "w+");
+ size_t content_len = strlen(content);
if (fh == NULL)
die("Couldn't open '%s': %s", filename, strerror(errno));
fwrite(content, sizeof(char), content_len, fh);
@@ -132,88 +132,8 @@
}
}

-size_t
-chaz_Util_grow_buf(char **buf, size_t old_len, size_t new_len)
-{
- /* grow buffer only if necessary */
- if (new_len > 0 && new_len >= old_len) {
- *buf = realloc(*buf, new_len + 1);
- if (*buf == NULL)
- die("buffer allocation failed");
- *((*buf) + new_len) = '\0';
- }
-
- /* return whatever the buffer size is now */
- return new_len > old_len ? new_len : old_len;
-}
-
-size_t
-chaz_Util_append_strings(char **buf, size_t buf_len, ...)
-{
- va_list args;
- size_t retval;
-
- /* delegate to vappend_strings */
- va_start(args, buf_len);
- retval = vappend_strings(buf, buf_len, args);
- va_end(args);
-
- return retval;
-}
-
-size_t
-chaz_Util_vappend_strings(char **buf, size_t buf_len, va_list args)
-{
- char *str;
- size_t new_len = buf_len == 0 ? 0 : strlen(*buf);
-
- /* start with a null-terminated empty string if necessary */
- if (buf_len == 0) {
- buf_len = grow_buf(buf, buf_len, 1);
- (*buf)[0] = '\0';
- }
-
- /* concat, reallocating along the way as needed */
- while ( (str = va_arg(args, char*)) != NULL ) {
- new_len += strlen(str);
- if (new_len >= buf_len) {
- /* inefficient, but portable */
- *buf = realloc(*buf, new_len + 1);
- buf_len = new_len + 1;
- }
- strcat(*buf, str);
- }
-
-
- return new_len;
-}
-
-size_t
-chaz_Util_join_strings(char **buf, size_t buf_len, ...)
-{
- va_list args;
- size_t retval;
-
- /* delegate to vjoin_strings */
- va_start(args, buf_len);
- retval = vjoin_strings(buf, buf_len, args);
- va_end(args);
-
- return retval;
-}
-
-size_t
-chaz_Util_vjoin_strings(char **buf, size_t buf_len, va_list args)
-{
- /* start with en empty string for vappend to append to */
- if (*buf != NULL)
- (*buf)[0] = '\0';
-
- return vappend_strings(buf, buf_len, args);
-}
-
/**
- * Copyright 2006 The Apache Software Foundation
+ * Copyright 2006-2009 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h Mon Nov 23 02:06:41 2009
@@ -14,8 +14,7 @@
* an error occurs.
*/
void
-chaz_Util_write_file(const char *filename, const char *content,
- size_t content_len);
+chaz_Util_write_file(const char *filename, const char *content);

/* Read an entire file into memory.
*/
@@ -51,35 +50,6 @@
int
chaz_Util_can_open_file(char *file_path);

-/* Make sure that the buffer pointed to by [buf_ptr] can hold least as many
- * bytes as [new_len] + 1.
- */
-size_t
-chaz_Util_grow_buf(char **buf_ptr, size_t old_len, size_t new_len);
-
-/* Concatenate each string in a null-terminated list onto the end of [buf].
- * Grow [buf] if necessary and return its size.
- */
-size_t
-chaz_Util_append_strings(char **buf, size_t buf_len, ...);
-
-/* Varargs version of append_str.
- */
-size_t
-chaz_Util_vappend_strings(char **buf, size_t buf_len, va_list args);
-
-/* Replace the contents of [buf] (if any) with a string formed by
- * concatenating all the char* arguments in a null-terminated list.
- * Grow [buf] if necessary and return its size.
- */
-size_t
-chaz_Util_join_strings(char **buf, size_t buf_len, ...);
-
-/* Varargs version of join_strings.
- */
-size_t
-chaz_Util_vjoin_strings(char **buf, size_t buf_len, va_list args);
-
#ifdef CHAZ_USE_SHORT_NAMES
#define verbosity chaz_Util_verbosity
#define write_file chaz_Util_write_file
@@ -89,11 +59,6 @@
#define warn chaz_Util_warn
#define remove_and_verify chaz_Util_remove_and_verify
#define can_open_file chaz_Util_can_open_file
- #define grow_buf chaz_Util_grow_buf
- #define append_strings chaz_Util_append_strings
- #define vappend_strings chaz_Util_vappend_strings
- #define join_strings chaz_Util_join_strings
- #define vjoin_strings chaz_Util_vjoin_strings
#endif

#endif /* H_CHAZ_UTIL */

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Headers.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Headers.c?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Headers.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Headers.c Mon Nov 23 02:06:41 2009
@@ -181,7 +181,11 @@
size_t len = strlen(header_name) + sizeof("HAS_");

/* grow buffer and start off with "HAS_" */
- aff_buf_size = grow_buf(&aff_buf, aff_buf_size, len);
+ if (aff_buf_size < len + 1) {
+ free(aff_buf);
+ aff_buf_size = len + 1;
+ aff_buf = malloc(aff_buf_size);
+ }
strcpy(aff_buf, "HAS_");

/* transform one char at a time */

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Integers.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Integers.c?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Integers.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Integers.c Mon Nov 23 02:06:41 2009
@@ -8,9 +8,6 @@
#include <stdio.h>
#include <stdlib.h>

-static char *code_buf = NULL;
-static size_t code_buf_len = 0;
-
/* Determine endian-ness of this machine.
*/
static chaz_bool_t
@@ -77,6 +74,7 @@
char i64_t_type[10];
char i64_t_postfix[10];
char u64_t_postfix[10];
+ char code_buf[sizeof(type64_code) + 200];

START_RUN("Integers");

@@ -103,8 +101,6 @@
}

/* determine whether long longs are available */
- code_buf_len = grow_buf(&code_buf, code_buf_len,
- sizeof(type64_code) + 200);
sprintf(code_buf, type64_code, "long long");
output = capture_output(code_buf, strlen(code_buf), &output_len);
if (output != NULL) {

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/LargeFiles.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/LargeFiles.c?rev=883210&r1=883209&r2=883210&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/LargeFiles.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/LargeFiles.c Mon Nov 23 02:06:41 2009
@@ -54,9 +54,6 @@
static chaz_bool_t
S_can_create_big_files();

-static char* code_buf = NULL;
-static size_t code_buf_len = 0;
-
/* vars for holding lfs commands, once they're discovered */
static char fopen_command[10];
static char fseek_command[10];
@@ -127,7 +124,6 @@
END_SHORT_NAMES;
}

- free(code_buf);
END_RUN;
}

@@ -154,16 +150,16 @@
{
char *output = NULL;
size_t output_len;
- size_t needed = sizeof(off64_code) + (2 * strlen(combo->offset64_type))
- +strlen(combo->fopen_command) + strlen(combo->ftell_command)
- + strlen(combo->fseek_command) + 20;
+ size_t needed = sizeof(off64_code)
+ + (2 * strlen(combo->offset64_type))
+ + strlen(combo->fopen_command)
+ + strlen(combo->ftell_command)
+ + strlen(combo->fseek_command)
+ + 20;
+ char *code_buf = malloc(needed);
chaz_bool_t success = false;

- /* allocate buffer as necessary and prepare the source code */
- if (code_buf_len < needed) {
- code_buf = (char*)realloc(code_buf, needed);
- code_buf_len = needed;
- }
+ /* Prepare the source code. */
sprintf(code_buf, off64_code, combo->includes, combo->offset64_type,
combo->fopen_command, combo->offset64_type, combo->ftell_command,
combo->fseek_command);
@@ -263,12 +259,16 @@
char *output;
size_t output_len;
FILE *truncating_fh;
+ size_t needed = strlen(create_bigfile_code_a)
+ + strlen(fseek_command)
+ + strlen(create_bigfile_code_a)
+ + 10;
+ char *code_buf = malloc(needed);

/* concat the source strings, compile the file, capture output */
- code_buf_len = join_strings(&code_buf, code_buf_len,
- create_bigfile_code_a, fseek_command, create_bigfile_code_b, NULL);
-
- output = capture_output(code_buf, code_buf_len, &output_len);
+ sprintf(code_buf, "%s%s%s", create_bigfile_code_a, fseek_command,
+ create_bigfile_code_b);
+ output = capture_output(code_buf, strlen(code_buf), &output_len);

/* truncate, just in case the call to remove fails */
truncating_fh = fopen("_charm_large_file_test", "w");
@@ -277,6 +277,7 @@
remove_and_verify("_charm_large_file_test");

/* return true if the test app made it to the finish line */
+ free(code_buf);
return output == NULL ? false : true;
}
reply

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post

1 user in discussion

Marvin: 1 post