Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Objectify and ObjectifyWithAttributes reject input objects which are not plain lists or records #5554

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/ref/create.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ and why it is useful to have a declaration part and an implementation part.

<Description>
New objects are created by <Ref Func="Objectify"/>.
<A>data</A> is a list or a record, and <A>type</A> is the type that the
desired object shall have.
<A>data</A> must be a plain list or a plain record, and <A>type</A>
is the type that the desired object shall have.
<Ref Func="Objectify"/> turns <A>data</A> into an object with type
<A>type</A>.
That is, <A>data</A> is changed, and afterwards it will not be a list or a
Expand Down
4 changes: 2 additions & 2 deletions lib/type1.g
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ end );
## will take a lot of time for type changes.
## You can avoid this by setting the attributes immediately while the
## object is created, as follows.
## <Ref Func="ObjectifyWithAttributes"/>
## changes the type of object <A>obj</A> to type <A>type</A>
## <Ref Func="ObjectifyWithAttributes"/> takes a plain list or record
## <A>obj</A> and turns it an object just like <Ref Func="Objectify"/>
## and sets attribute <A>attr1</A> to <A>val1</A>,
## sets attribute <A>attr2</A> to <A>val2</A> and so forth.
## <P/>
Expand Down
24 changes: 9 additions & 15 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,17 @@
break;

default:
if (IS_STRING_REP(obj)) {
// FIXME/TODO: Hap calls Objectify on a string...
if (!IS_PLIST(obj)) {
ErrorMayQuit("cannot change type of a %s", (Int)TNAM_OBJ(obj), 0);

Check warning on line 232 in src/objects.c

View check run for this annotation

Codecov / codecov/patch

src/objects.c#L232

Added line #L232 was not covered by tests
}
else if (IS_PLIST(obj)) {
// TODO: we should also reject immutable plists, but that risks
// breaking existing code
#ifdef HPCGAP
MEMBAR_WRITE();
MEMBAR_WRITE();
#endif
RetypeBag(obj, T_POSOBJ);
SET_TYPE_POSOBJ(obj, type);
CHANGED_BAG(obj);
}
else {
ErrorMayQuit("cannot change type of a %s", (Int)TNAM_OBJ(obj), 0);
}
RetypeBag(obj, T_POSOBJ);
SET_TYPE_POSOBJ(obj, type);
CHANGED_BAG(obj);
break;
}
}
Expand Down Expand Up @@ -1338,10 +1335,7 @@
case T_POSOBJ:
break;
default:
if (IS_STRING_REP(obj)) {
// FIXME/TODO: Hap calls Objectify on a string...
}
else if (!IS_PLIST(obj)) {
if (!IS_PLIST(obj)) {
ErrorMayQuit("You can't make a positional object from a %s",
(Int)TNAM_OBJ(obj), 0);
}
Expand Down