develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35050 - trunk/compilers/pirc/src

From:
kjs
Date:
January 6, 2009 08:48
Subject:
[svn:parrot] r35050 - trunk/compilers/pirc/src
Message ID:
20090106164817.AC93ACB9F9@x12.develooper.com
Author: kjs
Date: Tue Jan  6 08:48:16 2009
New Revision: 35050

Modified:
   trunk/compilers/pirc/src/pircompunit.c
   trunk/compilers/pirc/src/pircompunit.h
   trunk/compilers/pirc/src/pirpcc.c

Log:
[pirc] fix a NULL pointer bug. Can't unshift onto an empty list.

Modified: trunk/compilers/pirc/src/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/src/pircompunit.c	(original)
+++ trunk/compilers/pirc/src/pircompunit.c	Tue Jan  6 08:48:16 2009
@@ -709,7 +709,8 @@
 =item C<argument *
 new_argument(lexer_state * const lexer, expression * const expr)>
 
-Create a new argument node which wraps C<expr>.
+Create a new argument node which wraps C<expr>. The new argument node
+is circular linked, meaning its C<next> pointer points to itself.
 
 =cut
 
@@ -776,13 +777,19 @@
 A (last) and B (first), but the pointer to the "last" is not updated,
 so that A stays the last.
 
+The function returns a pointer to the last node in the list.
+
 =cut
 
 */
-void
+argument *
 unshift_arg(argument *last, argument * const newarg) {
-    newarg->next = last->next;
-    last->next   = newarg;
+    if (last) {
+        newarg->next = last->next;
+        last->next   = newarg;
+        return last;
+    }
+    return newarg;
 }
 
 /*

Modified: trunk/compilers/pirc/src/pircompunit.h
==============================================================================
--- trunk/compilers/pirc/src/pircompunit.h	(original)
+++ trunk/compilers/pirc/src/pircompunit.h	Tue Jan  6 08:48:16 2009
@@ -417,7 +417,7 @@
 /* functions for argument node creation and storing */
 argument *new_argument(struct lexer_state * const lexer, expression * const expr);
 argument *add_arg(argument *arg1, argument * const arg2);
-void unshift_arg(argument *last, argument * const newarg);
+argument *unshift_arg(argument *last, argument * const newarg);
 
 target *add_param(struct lexer_state * const lexer, pir_type type, char const * const name);
 target *set_param_alias(struct lexer_state * const lexer, char const * const alias);

Modified: trunk/compilers/pirc/src/pirpcc.c
==============================================================================
--- trunk/compilers/pirc/src/pirpcc.c	(original)
+++ trunk/compilers/pirc/src/pirpcc.c	Tue Jan  6 08:48:16 2009
@@ -617,10 +617,13 @@
 */
 static void
 convert_pcc_methodcall(lexer_state * const lexer, invocation * const inv) {
+    fprintf(stderr, "convert pcc method call\n");
     new_sub_instr(lexer, PARROT_OP_set_args_pc, "set_args_pc", inv->num_arguments);
 
     /* in a methodcall, the invocant object is passed as the first argument */
-    unshift_arg(inv->arguments, new_argument(lexer, expr_from_target(lexer, inv->sub)));
+    inv->arguments = unshift_arg(inv->arguments,
+                                 new_argument(lexer, expr_from_target(lexer, inv->sub)));
+
     arguments_to_operands(lexer, inv->arguments, inv->num_arguments);
 
     new_sub_instr(lexer, PARROT_OP_get_results_pc, "get_results_pc", inv->num_results);
@@ -628,6 +631,7 @@
 
     new_sub_instr(lexer, PARROT_OP_callmethodcc_p_sc, "callmethodcc_p_sc", 0);
     add_operands(lexer, "%T%E", inv->sub, inv->method);
+    fprintf(stderr, "convert pcc method call done\n");
 }
 
 /*



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About