Skip to content

Commit 33337c1

Browse files
author
Alexander Dreyer
committed
new: pyobject can be converted to newstruct, if defined
1 parent 0a64d50 commit 33337c1

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

Singular/pyobject.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <omalloc/omalloc.h>
2020

2121
#include <kernel/febase.h>
22-
// #include <kernel/longrat.h>
2322

2423
#include "subexpr.h"
2524
#include "lists.h"
@@ -128,7 +127,7 @@ class PythonObject
128127
if (op == PythonInterpreter::id())
129128
return *this;
130129

131-
Werror("unary op %d not implemented for pyobject", op);
130+
Werror("unary operation '%s` not implemented for 'pyobject`", iiTwoOps(op));
132131
return self();
133132
}
134133

@@ -148,7 +147,7 @@ class PythonObject
148147
case LIST_CMD: return args2list(arg);
149148
case '.': case COLONCOLON: case ATTRIB_CMD: return attr(arg);
150149
}
151-
Werror("binary op %d not implemented for pyobject!", op);
150+
Werror("binary operation '%d` not implemented for 'pyobject`", iiTwoOps(op));
152151

153152
return self();
154153
}
@@ -161,7 +160,7 @@ class PythonObject
161160
case ATTRIB_CMD: PyObject_SetAttr(*this, arg1, arg2); return self();
162161
}
163162

164-
Werror("ternary op %d not implemented for pyobject!", op);
163+
Werror("ternary operation %s not implemented for 'pyobject`", iiTwoOps(op));
165164
return self();
166165
}
167166

@@ -334,10 +333,18 @@ class PythonCastDynamic:
334333
case INT_CMD: return PythonCastStatic<long>(value);
335334
case STRING_CMD: return PythonCastStatic<const char*>(value);
336335
case LIST_CMD: return PythonCastStatic<lists>(value);
337-
// case UNKNOWN: return PythonCastStatic<const char*>((void*)value->Name());
338336
}
339-
340-
Werror("type # %d incompatible with pyobject", typeId);
337+
338+
if (typeId > MAX_TOK) // custom types
339+
{
340+
blackbox *bbx = getBlackboxStuff(typeId);
341+
sleftv tmp;
342+
if (! bbx->blackbox_Op1(PythonInterpreter::id(), &tmp, value) )
343+
return PythonCastStatic<>(&tmp);
344+
}
345+
else
346+
Werror("type '%s` incompatible with 'pyobject`", iiTwoOps(typeId));
347+
341348
return PythonObject();
342349
}
343350
};
@@ -495,7 +502,7 @@ BOOLEAN pyobject_Op1(int op, leftv res, leftv head)
495502
{
496503
long value = PyInt_AsLong(PythonCastStatic<>(head));
497504
if( (value == -1) && PyErr_Occurred() ) {
498-
Werror("pyobject cannot be converted to integer");
505+
Werror("'pyobject` cannot be converted to integer");
499506
PyErr_Clear();
500507
return TRUE;
501508
}
@@ -512,6 +519,7 @@ BOOLEAN pyobject_Op1(int op, leftv res, leftv head)
512519
return FALSE;
513520

514521
}
522+
515523
return PythonCastStatic<>(head)(op).assign_to(res);
516524
}
517525

0 commit comments

Comments
 (0)