pike.git
/
src
/
operators.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/operators.c:1:
/* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: operators.c,v 1.
203
2005/
01
/
14
10
:
00
:
54
nilsson
Exp $
+
|| $Id: operators.c,v 1.
204
2005/
04
/
08
16
:
59
:
18
grubba
Exp $
*/ #include "global.h" #include <math.h> #include "interpret.h" #include "svalue.h" #include "multiset.h" #include "mapping.h" #include "array.h" #include "stralloc.h"
pike.git/src/operators.c:5060:
extern int generate_call_function(node *n); /*! @class string_assignment */ struct program *string_assignment_program; #undef THIS #define THIS ((struct string_assignment_storage *)(CURRENT_STORAGE))
-
/*! @decl int `[](int i
, int j
)
+
/*! @decl int `[](int i)
*! *! String index operator. */ static void f_string_assignment_index(INT32 args) {
-
ptrdiff_t len
= THIS->s->len
;
+
ptrdiff_t len;
INT_TYPE i, p;
-
get_all_args("string[]",args,"%i",&p);
+
+
get_all_args("string[]",
args,
"%i",
&p);
+
+
if (!THIS->s) {
+
Pike_error("Indexing uninitialized string_assignment.\n");
+
}
+
+
len = THIS->s->len;
i = p < 0 ? p + len : p; if(i<0 || i>=len) Pike_error("Index %"PRINTPIKEINT"d is out of string range " "%"PRINTPTRDIFFT"d..%"PRINTPTRDIFFT"d.\n", p, -len, len - 1); else i=index_shared_string(THIS->s,i); pop_n_elems(args); push_int(i); }
pike.git/src/operators.c:5100:
get_all_args("string[]=",args,"%i%i",&p,&j); if((u=get_pointer_if_this_type(THIS->lval, T_STRING))) { len = u->string->len; i = p < 0 ? p + len : p; if(i<0 || i>=len) Pike_error("Index %"PRINTPIKEINT"d is out of string range " "%"PRINTPTRDIFFT"d..%"PRINTPTRDIFFT"d.\n", p, -len, len - 1);
-
free_string(THIS->s);
+
if (THIS->s)
free_string(THIS->s);
u->string=modify_shared_string(u->string,i,j); copy_shared_string(THIS->s, u->string); } else{ lvalue_to_svalue_no_free(sp,THIS->lval); sp++; dmalloc_touch_svalue(Pike_sp-1); if(sp[-1].type != T_STRING) Pike_error("string[]= failed.\n"); len = sp[-1].u.string->len;
pike.git/src/operators.c:5128:
pop_stack(); } pop_n_elems(args); push_int(j); } static void init_string_assignment_storage(struct object *o) {
-
THIS->lval[0].type=T_INT;
-
THIS->lval[1].type=T_INT;
-
THIS->s=
0
;
+
THIS->lval[0].type
=
T_INT;
+
THIS->lval[1].type
=
T_INT;
+
THIS->s
=
NULL
;
} static void exit_string_assignment_storage(struct object *o) { free_svalues(THIS->lval, 2, BIT_MIXED); if(THIS->s) free_string(THIS->s); } /*! @endclass