# New Ticket Created by  Nick Glencross 
# Please include the string:  [perl #34964]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=34964 >


This patch fixes a few operations which are badly inherited by string 
from scalar.pmc. increment/decrement have been removed as they aren't 
really required for Strings. 'neg' also also suffered from a similar 
problem, so this patch also stops this example segfaulting:

.sub test
        new $P0, .String
        $P0 = "12"
        neg $P0
        print $P0
        print_newline
.end

You may need to do a make clean or similar to get string.c to be 
properly built...(?)

[My feeling is that scalar should define set_integer_native, 
set_number_native etc. to automatically morph, and then for integer, 
float and string to override these to either not morph (for better 
performance), or just do their own thing (i.e. 
string::set_integer_native to convert the int to a String). That way you 
can't get data being changed without its interpretation.]
Index: classes/scalar.pmc
===================================================================
--- classes/scalar.pmc  (revision 7825)
+++ classes/scalar.pmc  (working copy)
@@ -87,7 +87,6 @@
 =item C<STRING *get_string()>
 
 
-
 =cut
 
 */
@@ -477,10 +476,7 @@
 */
 
     void neg (PMC* dest) {
-        if (dest == SELF)
-            PMC_int_val(SELF) = -DYNSELF.get_integer();
-        else
-            VTABLE_set_integer_native(INTERP, dest, -DYNSELF.get_integer());
+        VTABLE_set_integer_native(INTERP, dest, -DYNSELF.get_integer());
     }
 
 /*
@@ -931,36 +927,9 @@
                 (UINTVAL)value, NULL) );
     }
 
-/*
 
-=item C<void increment()>
-
-Increments the scalar.
-
-=cut
-
-*/
-
-    void increment () {
-        PMC_int_val(SELF) = DYNSELF.get_integer() + 1;
-    }
-
 /*
 
-=item C<void decrement()>
-
-Decrements the scalar.
-
-=cut
-
-*/
-
-    void decrement () {
-        PMC_int_val(SELF) = DYNSELF.get_integer() - 1;
-    }
-
-/*
-
 =item C<INTVAL defined()>
 
 Always returns true.

Reply via email to