aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjthorn <jthorn@df1f8a13-aa1d-4dd4-9681-27ded5b42416>2002-06-03 19:15:47 +0000
committerjthorn <jthorn@df1f8a13-aa1d-4dd4-9681-27ded5b42416>2002-06-03 19:15:47 +0000
commitc40a1a5fd3ab71629fa649b9581afac2859f150f (patch)
treebc0026cd8288032c69f669d52936466703db041b
parent73e130376b2ed1e2d7ffd23afaf3c6e2c8d7fa6c (diff)
template.c
* change comments to note that we never return UTIL_ERROR_NO_MEMORY InterpLocalUniform.c * add this kludge to handle malloc(0): > /* > * Implementation Note: > * > * We malloc() several scratch arrays, some with sizes determined by > * N_{input,output}_arrays. Thus if N_{input,output}_arrays == 0, with > * the obvious code we would malloc(0). Alas, the C standard permits > * malloc(0) to return a NULL pointer, which the usual malloc() idiom > * CCTK_INT *const p = malloc(N * sizeof(CCTK_INT)); > * if (p == NULL) > * then return UTIL_ERROR_NO_MEMORY > * would falsely detect as an out-of-memory condition. > * > * As a workaround, we pad all our malloc request sizes, i.e. > * CCTK_INT *const p = malloc((N+1) * sizeof(CCTK_INT)); > * if (p == NULL) > * then return UTIL_ERROR_NO_MEMORY > * This is a kludge, but so are the other plausible solutions. :( :( > */ git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/LocalInterp/trunk@64 df1f8a13-aa1d-4dd4-9681-27ded5b42416
-rw-r--r--src/GeneralizedPolynomial-Uniform/InterpLocalUniform.c33
-rw-r--r--src/GeneralizedPolynomial-Uniform/template.c3
2 files changed, 28 insertions, 8 deletions
diff --git a/src/GeneralizedPolynomial-Uniform/InterpLocalUniform.c b/src/GeneralizedPolynomial-Uniform/InterpLocalUniform.c
index 0d18e17..f4f2631 100644
--- a/src/GeneralizedPolynomial-Uniform/InterpLocalUniform.c
+++ b/src/GeneralizedPolynomial-Uniform/InterpLocalUniform.c
@@ -431,6 +431,27 @@ int LocalInterp_InterpLocalUniform(int N_dims,
const CCTK_INT output_array_type_codes[],
void *const output_arrays[])
{
+/*
+ * Implementation Note:
+ *
+ * We malloc() several scratch arrays, some with sizes determined by
+ * N_{input,output}_arrays. Thus if N_{input,output}_arrays == 0, with
+ * the obvious code we would malloc(0). Alas, the C standard permits
+ * malloc(0) to return a NULL pointer, which the usual malloc() idiom
+ * CCTK_INT *const p = malloc(N * sizeof(CCTK_INT));
+ * if (p == NULL)
+ * then return UTIL_ERROR_NO_MEMORY
+ * would falsely detect as an out-of-memory condition.
+ *
+ * As a workaround, we pad all our malloc request sizes, i.e.
+ * CCTK_INT *const p = malloc((N+1) * sizeof(CCTK_INT));
+ * if (p == NULL)
+ * then return UTIL_ERROR_NO_MEMORY
+ * This is a kludge, but so are the other plausible solutions. :( :(
+ */
+int N_input_arrays1 = N_input_arrays + 1;
+int N_output_arrays1 = N_output_arrays + 1;
+
int status, status1, status2, status3, status4;
/******************************************************************************/
@@ -645,7 +666,7 @@ if ((smoothing < 0) || (smoothing > MAX_SMOOTHING))
*/
{
CCTK_INT *const input_array_offsets
- = malloc(N_input_arrays * sizeof(CCTK_INT));
+ = malloc(N_input_arrays1 * sizeof(CCTK_INT));
if (input_array_offsets == NULL)
then return UTIL_ERROR_NO_MEMORY; /*** ERROR RETURN ***/
status = Util_TableGetIntArray(param_table_handle,
@@ -789,7 +810,7 @@ else {
*/
{
CCTK_INT *const operand_indices
- = malloc(N_output_arrays * sizeof(CCTK_INT));
+ = malloc(N_output_arrays1 * sizeof(CCTK_INT));
if (operand_indices == NULL)
then {
free(input_array_offsets);
@@ -865,7 +886,7 @@ else {
*/
{
CCTK_INT *const operation_codes
- = malloc(N_output_arrays * sizeof(CCTK_INT));
+ = malloc(N_output_arrays1 * sizeof(CCTK_INT));
if (operation_codes == NULL)
then {
free(operand_indices);
@@ -1017,7 +1038,7 @@ if (status)
then {
/* yes, we're doing Jacobian queries */
Jacobian_info.Jacobian_pointer
- = (CCTK_REAL **) malloc(N_output_arrays * sizeof(CCTK_REAL *));
+ = (CCTK_REAL **) malloc(N_output_arrays1 * sizeof(CCTK_REAL *));
if (Jacobian_info.Jacobian_pointer == NULL)
then {
free(operation_codes);
@@ -1027,7 +1048,7 @@ if (status)
}
{
CCTK_POINTER *Jacobian_pointer_temp
- = (CCTK_POINTER *) malloc(N_output_arrays * sizeof(CCTK_POINTER));
+ = (CCTK_POINTER *) malloc(N_output_arrays1 * sizeof(CCTK_POINTER));
if (Jacobian_pointer_temp == NULL)
then {
free(operation_codes);
@@ -1070,7 +1091,7 @@ if (status)
}
Jacobian_info.Jacobian_offset
- = (CCTK_INT *) malloc(N_output_arrays * sizeof(CCTK_INT));
+ = (CCTK_INT *) malloc(N_output_arrays1 * sizeof(CCTK_INT));
if (Jacobian_info.Jacobian_offset == NULL)
then {
free(operation_codes);
diff --git a/src/GeneralizedPolynomial-Uniform/template.c b/src/GeneralizedPolynomial-Uniform/template.c
index c95f117..6d6c080 100644
--- a/src/GeneralizedPolynomial-Uniform/template.c
+++ b/src/GeneralizedPolynomial-Uniform/template.c
@@ -265,11 +265,10 @@
@vio out
@returntype int
- @returndesc This function's return result is the same as that of
+ @returndesc This function's return results are a subset of those of
InterpLocalUniform():
0 success
UTIL_ERROR_BAD_INPUT one of the input arguments is invalid
- UTIL_ERROR_NO_MEMORY unable to malloc() temporary memory
CCTK_ERROR_INTERP_POINT_X_RANGE
interpolation point is out of range
@endreturndesc