Skip to content

Commit 3877fe9

Browse files
author
Alexander Dreyer
committed
fix: newstruct's string operator may be overloaded
1 parent 9165865 commit 3877fe9

4 files changed

Lines changed: 160 additions & 0 deletions

File tree

Singular/newstruct.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ char * newstruct_String(blackbox *b, void *d)
4949
else
5050
{
5151
newstruct_desc ad=(newstruct_desc)(b->data);
52+
53+
newstruct_proc p=ad->procs;
54+
while((p!=NULL)&&(p->t!=STRING_CMD))
55+
p=p->next;
56+
57+
if (p!=NULL)
58+
{
59+
leftv sl;
60+
sleftv tmp;
61+
memset(&tmp,0,sizeof(tmp));
62+
tmp.rtyp=ad->id;
63+
void * newstruct_Copy(blackbox*, void *); //forward declaration
64+
tmp.data=(void*)newstruct_Copy(b,d);
65+
idrec hh;
66+
memset(&hh,0,sizeof(hh));
67+
hh.id=Tok2Cmdname(p->t);
68+
hh.typ=PROC_CMD;
69+
hh.data.pinf=p->p;
70+
sl=iiMake_proc(&hh,NULL,&tmp);
71+
72+
if (sl->Typ() == STRING_CMD)
73+
{
74+
char *res = omStrDup((char*)sl->Data());
75+
sl->CleanUp();
76+
return res;
77+
}
78+
else
79+
sl->CleanUp();
80+
}
81+
5282
lists l=(lists)d;
5383
newstruct_member a=ad->member;
5484
StringSetS("");

Tst/Short/bug_newstruct3.res.gz.uu

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
begin 644 bug_newstruct2.res.gz
2+
M'XL(",(;[$\``V)U9U]N97=S=')U8W0R+G)E<P"=5\MNVSH0W?LK!L)=2`VK
3+
MBI+U@A$M;K(I4'33[@W%D@.BLF1(<F.CZ+_?(2630]=Q<R,D,<5Y'LZ9H?/M
4+
M^^/GKP#`"_CR^5]PQF'T&_'DK!;?9DE8`&ZN12M&UULMY"<4!3P=GM=M_3*,
5+
M_6$SACXN_6$L1VT6%:#72Q_V?;>!2OP40]>O][UH1W=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/HSE[50HU[F&+?@9X*C<_T&"&
22+
ML:!):./E)<JK6J2I\\2"NW[I.S2^`IJG%M#T74`G]Q;<C,(5[:;K^WHSXD#%
23+
M[Q.8^EA73.'7\#&W\M",5OUN%)<'IK@\.!=7G:NPD;Y>5QZ\L:[S9:W=$Z0\
24+
MB$@>V$4&==N]0-?*.T15^Z7K?PR@#\(NH?807T!^__'Q("&9X0"7_SK-ES#F
25+
,_\_B/X+A?Q!P#0``
26+
`
27+
end

Tst/Short/bug_newstruct3.stat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 >> tst_memory_0 :: 1340873666:3144- exported :3-1-4:x86_64-Linux:lts035:204848
2+
1 >> tst_memory_1 :: 1340873666:3144- exported :3-1-4:x86_64-Linux:lts035:3100672
3+
1 >> tst_memory_2 :: 1340873666:3144- exported :3-1-4:x86_64-Linux:lts035:3100672
4+
1 >> tst_timer_1 :: 1340873666:3144- exported :3-1-4:x86_64-Linux:lts035:10

Tst/Short/bug_newstruct3.tst

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
LIB "tst.lib";
2+
tst_init();
3+
4+
proc divisor_print(divisor D)
5+
{
6+
"Divisor = ("+string(D.den)+") - ("+string(D.num)+")";
7+
}
8+
proc divisor_status(divisor D)
9+
{
10+
return ("status");
11+
}
12+
proc divisor_test(divisor D)
13+
{
14+
return ("test");
15+
}
16+
proc divisor_gcd(divisor D, divisor D2)
17+
{
18+
return ("gcd");
19+
}
20+
proc divisor_extgcd(divisor D, divisor D2)
21+
{
22+
return ("extgcd");
23+
}
24+
proc divisor_diff(divisor D, divisor D2)
25+
{
26+
return ("diff");
27+
}
28+
29+
newstruct("divisor","ideal den,ideal num");
30+
newstruct("formaldivisor","list summands");
31+
newstruct("pdivisor","list summands, cone tail");
32+
33+
system("install","divisor","status",divisor_status, 4);
34+
system("install","divisor","test",divisor_test,4);
35+
system("install","divisor","gcd",divisor_gcd,2);
36+
system("install","divisor","extgcd",divisor_extgcd,2);
37+
38+
39+
system("install","divisor","print",divisor_print,1);
40+
41+
ring r=0,(x,y),dp;
42+
43+
divisor C;
44+
C.num = ideal(x);
45+
C.den = ideal(y);
46+
47+
C;
48+
test(C);
49+
status(C);
50+
gcd(C,C);
51+
extgcd(C,C);
52+
// -------------------------------------------------------
53+
newstruct("myunion", "poly p,int i");
54+
proc to_poly(myunion uni)
55+
{
56+
return (uni.p);
57+
}
58+
59+
proc to_int(myunion uni)
60+
{
61+
return (uni.i);
62+
}
63+
64+
ring r=0,x,dp;
65+
66+
myunion uni;
67+
uni.p = x+1;
68+
uni.i = 17;
69+
70+
system("install", "myunion", "poly", to_poly, 1);
71+
system("install", "myunion", "int", to_int, 1);
72+
73+
poly(uni); // -> x+1
74+
int(uni); // -> 17
75+
76+
// ---------------------------------------------------------
77+
78+
newstruct("stringifiable", "int i");
79+
stringifiable stry;
80+
stry;
81+
string(stry);
82+
83+
proc to_str(def arg) { return ("(overloaded)"); }
84+
system("install", "stringifiable", "string", to_str,1);
85+
stry; // print falls back to string
86+
string(stry);
87+
88+
proc to_str_wrong(def arg) { return (17); }
89+
system("install", "stringifiable", "string", to_str_wrong,1);
90+
stry; // incorrectly converted, fall back to default
91+
string(stry);
92+
93+
proc printing(def arg) { ("(overloaded)"); }
94+
system("install", "stringifiable", "print", printing,1);
95+
96+
stry; // now only print works correctly
97+
string(stry); // incorrectly converted, fall back to default
98+
99+
tst_status(1);$

0 commit comments

Comments
 (0)