File tree Expand file tree Collapse file tree 4 files changed +35
-27
lines changed
Expand file tree Collapse file tree 4 files changed +35
-27
lines changed Original file line number Diff line number Diff line change @@ -959,7 +959,7 @@ Obj NewFunctionT (
959959 }
960960
961961 /* enter the arguments and the names */
962- SET_NAME_FUNC (func , ConvImmString (name ));
962+ SET_NAME_FUNC (func , name ? ImmutableString (name ) : 0 );
963963 SET_NARG_FUNC (func , narg );
964964 SET_NAMS_FUNC (func , nams );
965965 SET_NLOC_FUNC (func , 0 );
@@ -1376,10 +1376,10 @@ Obj FuncSET_NAME_FUNC(
13761376{
13771377 while (!IsStringConv (name )) {
13781378 name = ErrorReturnObj ("SET_NAME_FUNC( <func>, <name> ): <name> must be a string, not a %s" ,
1379- (Int )TNAM_OBJ (name ), 0 , "YOu can return a new name to continue" );
1379+ (Int )TNAM_OBJ (name ), 0 , "You can return a new name to continue" );
13801380 }
13811381 if (TNUM_OBJ (func ) == T_FUNCTION ) {
1382- SET_NAME_FUNC (func , ConvImmString (name ));
1382+ SET_NAME_FUNC (func , ImmutableString (name ));
13831383 CHANGED_BAG (func );
13841384 } else
13851385 DoOperation2Args (SET_NAME_FUNC_Oper , func , name );
Original file line number Diff line number Diff line change @@ -3199,7 +3199,7 @@ void InstallGlobalFunction (
31993199 }
32003200 memcpy (ADDR_OBJ (oper ), CONST_ADDR_OBJ (func ), SIZE_OBJ (func ));
32013201
3202- SET_NAME_FUNC (oper , ConvImmString (name ));
3202+ SET_NAME_FUNC (oper , name ? ImmutableString (name ) : 0 );
32033203 CHANGED_BAG (oper );
32043204}
32053205
Original file line number Diff line number Diff line change @@ -1314,11 +1314,27 @@ Obj CopyToStringRep(
13141314 }
13151315 CHARS_STRING (copy )[lenString ] = '\0' ;
13161316 }
1317- CHANGED_BAG (copy );
1318- return (copy );
1317+ return copy ;
13191318}
13201319
13211320
1321+ /****************************************************************************
1322+ **
1323+ *F ImmutableString( <string> ) . . . copy to immutable string in string rep.
1324+ **
1325+ ** 'ImmutableString' returns an immutable string in string representation
1326+ ** equal to <string>. This may return <string> if it already satisfies these
1327+ ** criteria.
1328+ */
1329+ Obj ImmutableString (Obj string )
1330+ {
1331+ if (!IS_STRING_REP (string ) || !IS_MUTABLE_OBJ (string )) {
1332+ string = CopyToStringRep (string );
1333+ MakeImmutableString (string );
1334+ }
1335+ return string ;
1336+ }
1337+
13221338
13231339/****************************************************************************
13241340**
@@ -1386,22 +1402,6 @@ Int IsStringConv (
13861402}
13871403
13881404
1389- Obj ConvImmString (Obj str )
1390- {
1391- Obj result ;
1392- size_t len ;
1393- if (!str || !IsStringConv (str ))
1394- return (Obj ) 0 ;
1395- if (!IS_MUTABLE_OBJ (str ))
1396- return str ;
1397- len = GET_LEN_STRING (str );
1398- result = NEW_STRING (len );
1399- memcpy (CHARS_STRING (result ), CHARS_STRING (str ), len );
1400- MakeImmutableString (result );
1401- return result ;
1402- }
1403-
1404-
14051405/****************************************************************************
14061406**
14071407*F * * * * * * * * * * * * * * GAP level functions * * * * * * * * * * * * *
Original file line number Diff line number Diff line change @@ -281,13 +281,24 @@ extern Int IsString (
281281**
282282*F CopyToStringRep( <string> ) . . . copy a string to string representation
283283**
284- ** 'CopyToStringRep' copies the string <string> to a new string in string
285- ** representation.
284+ ** 'CopyToStringRep' copies the string <string> to a new mutable string in
285+ ** string representation.
286286*/
287287extern Obj CopyToStringRep (
288288 Obj string );
289289
290290
291+ /****************************************************************************
292+ **
293+ *F ImmutableString( <string> ) . . . copy to immutable string in string rep.
294+ **
295+ ** 'ImmutableString' returns an immutable string in string representation
296+ ** equal to <string>. This may return <string> if it already satisfies these
297+ ** criteria.
298+ */
299+ extern Obj ImmutableString (Obj string );
300+
301+
291302/****************************************************************************
292303**
293304*F ConvString( <string> ) . . . . convert a string to string representation
@@ -352,9 +363,6 @@ static inline Obj MakeImmString(const Char * cstr)
352363}
353364
354365
355- Obj ConvImmString (Obj str );
356-
357-
358366/****************************************************************************
359367**
360368*F C_NEW_STRING_DYN( <string>, <cstring> ) . . . . . . . . create GAP string
You can’t perform that action at this time.
0 commit comments