Skip to content

Commit

Permalink
new: newstruct_desc can be utilized by non-newstruc custom types
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Dreyer committed Jun 20, 2012
1 parent e87a68f commit 235f926
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 14 additions & 2 deletions Singular/newstruct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ BOOLEAN newstruct_Assign(leftv l, leftv r)
l->rtyp=r->Typ();
}
}
else // unrelated types - look for custom conversion
{
sleftv tmp;
BOOLEAN newstruct_Op1(int, leftv, leftv); // forward declaration
if (! newstruct_Op1(l->Typ(), &tmp, r)) return newstruct_Assign(l, &tmp);
}
}
if (l->Typ()==r->Typ())
{
Expand Down Expand Up @@ -605,13 +611,19 @@ static newstruct_desc scanNewstructFromString(const char *s, newstruct_desc res)
currRingHdl=save_ring;
return NULL;
}
newstruct_desc newstructFromString(const char *s)

newstruct_desc newstructDesc()
{
newstruct_desc res=(newstruct_desc)omAlloc0(sizeof(*res));
res->size=0;
return res;
}

return scanNewstructFromString(s,res);
newstruct_desc newstructFromString(const char *s)
{
return scanNewstructFromString(s, newstructDesc());
}

newstruct_desc newstructChildFromString(const char *parent, const char *s)
{
// find parent:
Expand Down
2 changes: 1 addition & 1 deletion Singular/newstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
typedef struct newstruct_desc_s *newstruct_desc;

void newstruct_setup(const char * name, newstruct_desc d);
newstruct_desc newstructDesc();
newstruct_desc newstructFromString(const char *s);
newstruct_desc newstructChildFromString(const char *p, const char *s);
BOOLEAN newstruct_set_proc(const char *name,const char *func,int args, procinfov p);
void newstructShow(newstruct_desc d);

#endif
9 changes: 9 additions & 0 deletions Singular/pyobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <Singular/ipid.h>
#include <Singular/blackbox.h>
#include <Singular/newstruct.h>

#include <omalloc/omalloc.h>
#include <kernel/febase.h>
#include <kernel/longrat.h>
Expand Down Expand Up @@ -523,6 +525,12 @@ BOOLEAN pyobject_Op1(int op, leftv res, leftv head)

}

if (op > MAX_TOK) // custom types
{
BOOLEAN newstruct_Op1(int, leftv, leftv);
if (! newstruct_Op1(op, res, head) ) return FALSE;
}

return PythonCastStatic<>(head)(op).assign_to(res);
}

Expand Down Expand Up @@ -648,6 +656,7 @@ void pyobject_init()
b->blackbox_Op2 = pyobject_Op2;
b->blackbox_Op3 = pyobject_Op3;
b->blackbox_OpM = pyobject_OpM;
b->data = newstructDesc();

PythonInterpreter::init(setBlackboxStuff(b,"pyobject"));

Expand Down

0 comments on commit 235f926

Please sign in to comment.