move variables to local scopes, fix some whitespace and indentation, some

2008-09-19  Michael Natterer  <mitch@gimp.org>

	* plug-ins/script-fu/scheme-wrapper.c: move variables to local
	scopes, fix some whitespace and indentation, some misc. cleanup,
	remove comments about array calling conventions that had lots of
	copy and paste errors.


svn path=/trunk/; revision=27014
This commit is contained in:
Michael Natterer
2008-09-19 12:15:26 +00:00
committed by Michael Natterer
parent c7af52b846
commit d80d1fabe9
2 changed files with 127 additions and 124 deletions

View File

@ -1,3 +1,10 @@
2008-09-19 Michael Natterer <mitch@gimp.org>
* plug-ins/script-fu/scheme-wrapper.c: move variables to local
scopes, fix some whitespace and indentation, some misc. cleanup,
remove comments about array calling conventions that had lots of
copy and paste errors.
2008-09-19 Sven Neumann <sven@gimp.org> 2008-09-19 Sven Neumann <sven@gimp.org>
* app/actions/file-actions.c: renamed "file-new-menu" to * app/actions/file-actions.c: renamed "file-new-menu" to

View File

@ -443,17 +443,17 @@ ts_init_constants (scheme *sc)
/* These constants are deprecated and will be removed at a later date. */ /* These constants are deprecated and will be removed at a later date. */
symbol = sc->vptr->mk_symbol (sc, "gimp-dir"); symbol = sc->vptr->mk_symbol (sc, "gimp-dir");
sc->vptr->scheme_define (sc, sc->global_env, symbol, sc->vptr->scheme_define (sc, sc->global_env, symbol,
sc->vptr->mk_string (sc, gimp_directory () )); sc->vptr->mk_string (sc, gimp_directory ()));
sc->vptr->setimmutable (symbol); sc->vptr->setimmutable (symbol);
symbol = sc->vptr->mk_symbol (sc, "gimp-data-dir"); symbol = sc->vptr->mk_symbol (sc, "gimp-data-dir");
sc->vptr->scheme_define (sc, sc->global_env, symbol, sc->vptr->scheme_define (sc, sc->global_env, symbol,
sc->vptr->mk_string (sc, gimp_data_directory () )); sc->vptr->mk_string (sc, gimp_data_directory ()));
sc->vptr->setimmutable (symbol); sc->vptr->setimmutable (symbol);
symbol = sc->vptr->mk_symbol (sc, "gimp-plugin-dir"); symbol = sc->vptr->mk_symbol (sc, "gimp-plugin-dir");
sc->vptr->scheme_define (sc, sc->global_env, symbol, sc->vptr->scheme_define (sc, sc->global_env, symbol,
sc->vptr->mk_string (sc, gimp_plug_in_directory () )); sc->vptr->mk_string (sc, gimp_plug_in_directory ()));
sc->vptr->setimmutable (symbol); sc->vptr->setimmutable (symbol);
for (i = 0; old_constants[i].name != NULL; ++i) for (i = 0; old_constants[i].name != NULL; ++i)
@ -471,19 +471,8 @@ ts_init_procedures (scheme *sc,
gboolean register_scripts) gboolean register_scripts)
{ {
gchar **proc_list; gchar **proc_list;
gchar *proc_blurb;
gchar *proc_help;
gchar *proc_author;
gchar *proc_copyright;
gchar *proc_date;
GimpPDBProcType proc_type;
gint nparams;
gint nreturn_vals;
GimpParamDef *params;
GimpParamDef *return_vals;
gint num_procs; gint num_procs;
gint i; gint i;
gchar *buff;
pointer symbol; pointer symbol;
#if USE_DL #if USE_DL
@ -527,6 +516,17 @@ ts_init_procedures (scheme *sc,
/* Register each procedure as a scheme func */ /* Register each procedure as a scheme func */
for (i = 0; i < num_procs; i++) for (i = 0; i < num_procs; i++)
{ {
gchar *proc_blurb;
gchar *proc_help;
gchar *proc_author;
gchar *proc_copyright;
gchar *proc_date;
GimpPDBProcType proc_type;
gint n_params;
gint n_return_vals;
GimpParamDef *params;
GimpParamDef *return_vals;
/* lookup the procedure */ /* lookup the procedure */
if (gimp_procedural_db_proc_info (proc_list[i], if (gimp_procedural_db_proc_info (proc_list[i],
&proc_blurb, &proc_blurb,
@ -535,13 +535,15 @@ ts_init_procedures (scheme *sc,
&proc_copyright, &proc_copyright,
&proc_date, &proc_date,
&proc_type, &proc_type,
&nparams, &nreturn_vals, &n_params, &n_return_vals,
&params, &return_vals)) &params, &return_vals))
{ {
gchar *buff;
/* Build a define that will call the foreign function. /* Build a define that will call the foreign function.
* The Scheme statement was suggested by Simon Budig. * The Scheme statement was suggested by Simon Budig.
*/ */
if (nparams == 0) if (n_params == 0)
{ {
buff = g_strdup_printf (" (define (%s)" buff = g_strdup_printf (" (define (%s)"
" (gimp-proc-db-call \"%s\"))", " (gimp-proc-db-call \"%s\"))",
@ -566,8 +568,8 @@ ts_init_procedures (scheme *sc,
g_free (proc_copyright); g_free (proc_copyright);
g_free (proc_date); g_free (proc_date);
gimp_destroy_paramdefs (params, nparams); gimp_destroy_paramdefs (params, n_params);
gimp_destroy_paramdefs (return_vals, nreturn_vals); gimp_destroy_paramdefs (return_vals, n_return_vals);
} }
g_free (proc_list[i]); g_free (proc_list[i]);
@ -608,7 +610,6 @@ script_fu_marshal_procedure_call (scheme *sc,
gchar error_str[1024]; gchar error_str[1024];
gint i; gint i;
gint success = TRUE; gint success = TRUE;
pointer intermediate_val;
pointer return_val = sc->NIL; pointer return_val = sc->NIL;
#if DEBUG_MARSHALL #if DEBUG_MARSHALL
@ -617,7 +618,8 @@ script_fu_marshal_procedure_call (scheme *sc,
#define typeflag(p) ((p)->_flag) #define typeflag(p) ((p)->_flag)
#define type(p) (typeflag(p)&T_MASKTYPE) #define type(p) (typeflag(p)&T_MASKTYPE)
static const char *ts_types[] = { static const char *ts_types[] =
{
"T_NONE", "T_NONE",
"T_STRING", "T_NUMBER", "T_SYMBOL", "T_PROC", "T_STRING", "T_NUMBER", "T_SYMBOL", "T_PROC",
"T_PAIR", "T_CLOSURE", "T_CONTINUATION", "T_FOREIGN", "T_PAIR", "T_CLOSURE", "T_CONTINUATION", "T_FOREIGN",
@ -681,7 +683,7 @@ script_fu_marshal_procedure_call (scheme *sc,
} }
/* Check the supplied number of arguments */ /* Check the supplied number of arguments */
if ( (sc->vptr->list_length (sc, a) - 1) != nparams) if ((sc->vptr->list_length (sc, a) - 1) != nparams)
{ {
#if DEBUG_MARSHALL #if DEBUG_MARSHALL
g_printerr (" Invalid number of arguments (expected %d but received %d)", g_printerr (" Invalid number of arguments (expected %d but received %d)",
@ -1194,49 +1196,52 @@ script_fu_marshal_procedure_call (scheme *sc,
success = FALSE; success = FALSE;
if (success) if (success)
{ {
/* parasite->name */ pointer temp_val;
intermediate_val = sc->vptr->pair_car (a);
if (!sc->vptr->is_string (sc->vptr->pair_car (intermediate_val))) /* parasite->name */
temp_val = sc->vptr->pair_car (a);
if (!sc->vptr->is_string (sc->vptr->pair_car (temp_val)))
{ {
success = FALSE; success = FALSE;
break; break;
} }
args[i].data.d_parasite.name = args[i].data.d_parasite.name =
sc->vptr->string_value (sc->vptr->pair_car (intermediate_val)); sc->vptr->string_value (sc->vptr->pair_car (temp_val));
#if DEBUG_MARSHALL #if DEBUG_MARSHALL
g_printerr (" name '%s'\n", args[i].data.d_parasite.name); g_printerr (" name '%s'\n", args[i].data.d_parasite.name);
#endif #endif
/* parasite->flags */ /* parasite->flags */
intermediate_val = sc->vptr->pair_cdr (intermediate_val); temp_val = sc->vptr->pair_cdr (temp_val);
if (!sc->vptr->is_number (sc->vptr->pair_car (intermediate_val))) if (!sc->vptr->is_number (sc->vptr->pair_car (temp_val)))
{ {
success = FALSE; success = FALSE;
break; break;
} }
args[i].data.d_parasite.flags = args[i].data.d_parasite.flags =
sc->vptr->ivalue (sc->vptr->pair_car (intermediate_val)); sc->vptr->ivalue (sc->vptr->pair_car (temp_val));
#if DEBUG_MARSHALL #if DEBUG_MARSHALL
g_printerr (" flags %d", args[i].data.d_parasite.flags); g_printerr (" flags %d", args[i].data.d_parasite.flags);
#endif #endif
/* parasite->data */ /* parasite->data */
intermediate_val = sc->vptr->pair_cdr (intermediate_val); temp_val = sc->vptr->pair_cdr (temp_val);
if (!sc->vptr->is_string (sc->vptr->pair_car (intermediate_val))) if (!sc->vptr->is_string (sc->vptr->pair_car (temp_val)))
{ {
success = FALSE; success = FALSE;
break; break;
} }
args[i].data.d_parasite.size = args[i].data.d_parasite.size =
sc->vptr->ivalue (sc->vptr->pair_car (intermediate_val)); sc->vptr->ivalue (sc->vptr->pair_car (temp_val));
args[i].data.d_parasite.data = args[i].data.d_parasite.data =
sc->vptr->string_value (sc->vptr->pair_car (intermediate_val)); sc->vptr->string_value (sc->vptr->pair_car (temp_val));
#if DEBUG_MARSHALL #if DEBUG_MARSHALL
g_printerr (", size %d\n", args[i].data.d_parasite.size); g_printerr (", size %d\n", args[i].data.d_parasite.size);
g_printerr (" data '%s'\n", (char *)args[i].data.d_parasite.data); g_printerr (" data '%s'\n", (char *)args[i].data.d_parasite.data);
@ -1414,9 +1419,6 @@ script_fu_marshal_procedure_call (scheme *sc,
break; break;
case GIMP_PDB_INT32ARRAY: case GIMP_PDB_INT32ARRAY:
/* integer arrays are always implemented such that the previous
* return value contains the number of strings in the array
*/
{ {
gint32 num_int32s = values[i].data.d_int32; gint32 num_int32s = values[i].data.d_int32;
gint32 *array = (gint32 *) values[i + 1].data.d_int32array; gint32 *array = (gint32 *) values[i + 1].data.d_int32array;
@ -1435,9 +1437,6 @@ script_fu_marshal_procedure_call (scheme *sc,
break; break;
case GIMP_PDB_INT16ARRAY: case GIMP_PDB_INT16ARRAY:
/* integer arrays are always implemented such that the previous
* return value contains the number of strings in the array
*/
{ {
gint32 num_int16s = values[i].data.d_int32; gint32 num_int16s = values[i].data.d_int32;
gint16 *array = (gint16 *) values[i + 1].data.d_int16array; gint16 *array = (gint16 *) values[i + 1].data.d_int16array;
@ -1456,9 +1455,6 @@ script_fu_marshal_procedure_call (scheme *sc,
break; break;
case GIMP_PDB_INT8ARRAY: case GIMP_PDB_INT8ARRAY:
/* integer arrays are always implemented such that the previous
* return value contains the number of strings in the array
*/
{ {
gint32 num_int8s = values[i].data.d_int32; gint32 num_int8s = values[i].data.d_int32;
guint8 *array = (guint8 *) values[i + 1].data.d_int8array; guint8 *array = (guint8 *) values[i + 1].data.d_int8array;
@ -1477,9 +1473,6 @@ script_fu_marshal_procedure_call (scheme *sc,
break; break;
case GIMP_PDB_FLOATARRAY: case GIMP_PDB_FLOATARRAY:
/* float arrays are always implemented such that the previous
* return value contains the number of strings in the array
*/
{ {
gint32 num_floats = values[i].data.d_int32; gint32 num_floats = values[i].data.d_int32;
gdouble *array = (gdouble *) values[i + 1].data.d_floatarray; gdouble *array = (gdouble *) values[i + 1].data.d_floatarray;
@ -1498,9 +1491,6 @@ script_fu_marshal_procedure_call (scheme *sc,
break; break;
case GIMP_PDB_STRINGARRAY: case GIMP_PDB_STRINGARRAY:
/* string arrays are always implemented such that the previous
* return value contains the number of strings in the array
*/
{ {
gint num_strings = values[i].data.d_int32; gint num_strings = values[i].data.d_int32;
gchar **array = (gchar **) values[i + 1].data.d_stringarray; gchar **array = (gchar **) values[i + 1].data.d_stringarray;
@ -1512,14 +1502,16 @@ script_fu_marshal_procedure_call (scheme *sc,
for (j = num_strings - 1; j >= 0; j--) for (j = num_strings - 1; j >= 0; j--)
{ {
list = sc->vptr->cons (sc, list = sc->vptr->cons (sc,
sc->vptr->mk_string sc->vptr->mk_string (sc,
(sc, array[j] ? array[j] : ""), array[j] ?
array[j] : ""),
list); list);
/* hook the current list into return_val, so that it /* hook the current list into return_val, so that it
* inherits the set_safe_foreign()-protection. * inherits the set_safe_foreign()-protection.
* May be removed when tinyscheme fixes the GC issue * May be removed when tinyscheme fixes the GC issue
* with foreign functions */ * with foreign functions
*/
sc->vptr->set_car (return_val, list); sc->vptr->set_car (return_val, list);
} }
} }
@ -1528,10 +1520,11 @@ script_fu_marshal_procedure_call (scheme *sc,
case GIMP_PDB_COLOR: case GIMP_PDB_COLOR:
{ {
guchar r, g, b; guchar r, g, b;
gpointer temp_val;
gimp_rgb_get_uchar (&values[i + 1].data.d_color, &r, &g, &b); gimp_rgb_get_uchar (&values[i + 1].data.d_color, &r, &g, &b);
intermediate_val = sc->vptr->cons (sc, temp_val = sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, r), sc->vptr->mk_integer (sc, r),
sc->vptr->cons (sc, sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, g), sc->vptr->mk_integer (sc, g),
@ -1539,16 +1532,13 @@ script_fu_marshal_procedure_call (scheme *sc,
sc->vptr->mk_integer (sc, b), sc->vptr->mk_integer (sc, b),
sc->NIL))); sc->NIL)));
return_val = sc->vptr->cons (sc, return_val = sc->vptr->cons (sc,
intermediate_val, temp_val,
return_val); return_val);
set_safe_foreign (sc, return_val); set_safe_foreign (sc, return_val);
break; break;
} }
case GIMP_PDB_COLORARRAY: case GIMP_PDB_COLORARRAY:
/* color arrays are always implemented such that the previous
* return value contains the number of strings in the array
*/
{ {
gint32 num_colors = values[i].data.d_int32; gint32 num_colors = values[i].data.d_int32;
GimpRGB *array = (GimpRGB *) values[i + 1].data.d_colorarray; GimpRGB *array = (GimpRGB *) values[i + 1].data.d_colorarray;
@ -1560,10 +1550,11 @@ script_fu_marshal_procedure_call (scheme *sc,
for (j = 0; j < num_colors; j++) for (j = 0; j < num_colors; j++)
{ {
guchar r, g, b; guchar r, g, b;
pointer temp_val;
gimp_rgb_get_uchar (&array[j], &r, &g, &b); gimp_rgb_get_uchar (&array[j], &r, &g, &b);
intermediate_val = sc->vptr->cons (sc, temp_val = sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, r), sc->vptr->mk_integer (sc, r),
sc->vptr->cons (sc, sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, g), sc->vptr->mk_integer (sc, g),
@ -1571,22 +1562,24 @@ script_fu_marshal_procedure_call (scheme *sc,
sc->vptr->mk_integer (sc, b), sc->vptr->mk_integer (sc, b),
sc->NIL))); sc->NIL)));
return_val = sc->vptr->cons (sc, return_val = sc->vptr->cons (sc,
intermediate_val, temp_val,
return_val); return_val);
set_safe_foreign (sc, return_val); set_safe_foreign (sc, return_val);
} }
} }
break; break;
case GIMP_PDB_REGION: case GIMP_PDB_REGION:
{ {
gint32 x, y, w, h; gint32 x, y, w, h;
pointer temp_val;
x = values[i + 1].data.d_region.x; x = values[i + 1].data.d_region.x;
y = values[i + 1].data.d_region.y; y = values[i + 1].data.d_region.y;
w = values[i + 1].data.d_region.width; w = values[i + 1].data.d_region.width;
h = values[i + 1].data.d_region.height; h = values[i + 1].data.d_region.height;
intermediate_val = sc->vptr->cons (sc, temp_val = sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, x), sc->vptr->mk_integer (sc, x),
sc->vptr->cons (sc, sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, y), sc->vptr->mk_integer (sc, y),
@ -1596,7 +1589,7 @@ script_fu_marshal_procedure_call (scheme *sc,
sc->vptr->mk_integer (sc, h), sc->vptr->mk_integer (sc, h),
sc->NIL)))); sc->NIL))));
return_val = sc->vptr->cons (sc, return_val = sc->vptr->cons (sc,
intermediate_val, temp_val,
return_val); return_val);
set_safe_foreign (sc, return_val); set_safe_foreign (sc, return_val);
break; break;
@ -1606,34 +1599,37 @@ script_fu_marshal_procedure_call (scheme *sc,
case GIMP_PDB_PARASITE: case GIMP_PDB_PARASITE:
{ {
if (values[i + 1].data.d_parasite.name == NULL) if (values[i + 1].data.d_parasite.name == NULL)
{
return_val = foreign_error (sc, "Error: null parasite", 0); return_val = foreign_error (sc, "Error: null parasite", 0);
}
else else
{ {
GimpParasite *p = &values[i + 1].data.d_parasite;
pointer temp_val;
/* don't move the mk_foo() calls outside this function call, /* don't move the mk_foo() calls outside this function call,
* otherwise they might be garbage collected away! */ * otherwise they might be garbage collected away!
intermediate_val = sc->vptr->cons (sc, */
sc->vptr->mk_string (sc, temp_val = sc->vptr->cons (sc,
values[i + 1].data.d_parasite.name), sc->vptr->mk_string (sc, p->name),
sc->vptr->cons (sc, sc->vptr->cons (sc,
sc->vptr->mk_integer (sc, sc->vptr->mk_integer (sc, p->flags),
values[i + 1].data.d_parasite.flags),
sc->vptr->cons (sc, sc->vptr->cons (sc,
sc->vptr->mk_counted_string (sc, sc->vptr->mk_counted_string (sc,
values[i + 1].data.d_parasite.data, p->data,
values[i + 1].data.d_parasite.size), p->size),
sc->NIL))); sc->NIL)));
return_val = sc->vptr->cons (sc, return_val = sc->vptr->cons (sc,
intermediate_val, temp_val,
return_val); return_val);
set_safe_foreign (sc, return_val); set_safe_foreign (sc, return_val);
#if DEBUG_MARSHALL #if DEBUG_MARSHALL
g_printerr (" name '%s'\n", values[i+1].data.d_parasite.name); g_printerr (" name '%s'\n", p->name);
g_printerr (" flags %d", values[i+1].data.d_parasite.flags); g_printerr (" flags %d", p->flags);
g_printerr (", size %d\n", values[i+1].data.d_parasite.size); g_printerr (", size %d\n", p->size);
g_printerr (" data '%.*s'\n", g_printerr (" data '%.*s'\n",
values[i+1].data.d_parasite.size, p->size, (gchar *) p->data);
(char *)values[i+1].data.d_parasite.data);
#endif #endif
} }
} }
@ -1653,8 +1649,9 @@ script_fu_marshal_procedure_call (scheme *sc,
break; break;
} }
/* If we have no return value(s) from PDB call, return */ /* If we have no return value(s) from PDB call, return
/* either TRUE or FALSE to indicate if call succeeded. */ * either TRUE or FALSE to indicate if call succeeded.
*/
if (return_val == sc->NIL) if (return_val == sc->NIL)
{ {
if (values[0].data.d_status == GIMP_PDB_SUCCESS) if (values[0].data.d_status == GIMP_PDB_SUCCESS)
@ -1692,7 +1689,6 @@ script_fu_marshal_procedure_call (scheme *sc,
#endif #endif
return return_val; return return_val;
} }
static void static void