Skip to content

Commit

Permalink
fix: pyobject falls back to newstruct operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Dreyer committed Aug 1, 2012
1 parent 632c3a6 commit b2aa086
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
11 changes: 4 additions & 7 deletions Singular/newstruct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ struct newstruct_desc_s
int id; // the type id assigned to this bb
};

int newstruct_desc_size()
{
return sizeof(newstruct_desc_s);
}

char * newstruct_String(blackbox *b, void *d)
{
Expand Down Expand Up @@ -663,13 +667,6 @@ BOOLEAN newstruct_set_proc(const char *bbname,const char *func, int args,procinf
blackboxIsCmd(bbname,id);
blackbox *bb=getBlackboxStuff(id);
newstruct_desc desc=(newstruct_desc)bb->data;
if (desc == NULL)
{
desc=(newstruct_desc)omAlloc0(sizeof(*desc));
desc->size=0;
bb->data = (void*)desc;
}

newstruct_proc p=(newstruct_proc)omAlloc(sizeof(*p));
p->next=desc->procs; desc->procs=p;

Expand Down
1 change: 1 addition & 0 deletions Singular/newstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
typedef struct newstruct_desc_s *newstruct_desc;

void newstruct_setup(const char * name, newstruct_desc d);
int newstruct_desc_size();
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);
Expand Down
44 changes: 24 additions & 20 deletions Singular/pyobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "config.h"
#include <kernel/mod2.h>
#include <misc/auxiliary.h>
#include "newstruct.h"

#include <omalloc/omalloc.h>

Expand Down Expand Up @@ -106,8 +107,10 @@ class PythonObject
public:
typedef PyObject* ptr_type;
struct sequence_tag{};
struct null_tag {};

PythonObject(): m_ptr(Py_None) { }
PythonObject(null_tag): m_ptr(NULL) { }
PythonObject(ptr_type ptr): m_ptr(ptr) {if (!ptr) handle_exception();}

ptr_type check_context(ptr_type ptr) const {
Expand All @@ -127,8 +130,7 @@ class PythonObject
if (op == PythonInterpreter::id())
return *this;

Werror("unary operation '%s` not implemented for 'pyobject`", iiTwoOps(op));
return self();
return self(null_tag());
}

/// Binary and n-ary operations
Expand All @@ -147,9 +149,7 @@ class PythonObject
case LIST_CMD: return args2list(arg);
case '.': case COLONCOLON: case ATTRIB_CMD: return attr(arg);
}
Werror("binary operation '%d` not implemented for 'pyobject`", iiTwoOps(op));

return self();
return self(null_tag());
}

/// Ternary operations
Expand All @@ -159,9 +159,8 @@ class PythonObject
{
case ATTRIB_CMD: PyObject_SetAttr(*this, arg1, arg2); return self();
}

Werror("ternary operation %s not implemented for 'pyobject`", iiTwoOps(op));
return self();
return self(null_tag());
}

/// Get item
Expand All @@ -184,7 +183,7 @@ class PythonObject

BOOLEAN assign_to(leftv result)
{
return (m_ptr == Py_None? none_to(result): python_to(result));
return (m_ptr? (m_ptr == Py_None? none_to(result): python_to(result)): TRUE);
}

void import_as(const char* name) const {
Expand Down Expand Up @@ -514,19 +513,13 @@ BOOLEAN pyobject_Op1(int op, leftv res, leftv head)
res->data = (void*) omStrDup("pyobject");
res->rtyp = STRING_CMD;
return FALSE;

case LIST_CMD:
return FALSE;

}

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

return PythonCastStatic<>(head)(op).assign_to(res);
BOOLEAN newstruct_Op1(int, leftv, leftv); // forward declaration
return newstruct_Op1(op, res, head);
}


Expand All @@ -546,8 +539,14 @@ BOOLEAN pyobject_Op2(int op, leftv res, leftv arg1, leftv arg2)
case '.': case COLONCOLON: case ATTRIB_CMD:
return lhs.attr(get_attrib_name(arg2)).assign_to(res);
}

PythonCastDynamic rhs(arg2);
return lhs(op, rhs).assign_to(res);
if (!lhs(op, rhs).assign_to(res))
return FALSE;

BOOLEAN newstruct_Op2(int, leftv, leftv, leftv); // forward declaration
return newstruct_Op2(op, res, arg1, arg2);

}

/// blackbox support - ternary operations
Expand Down Expand Up @@ -578,7 +577,11 @@ BOOLEAN pyobject_OpM(int op, leftv res, leftv args)
}

typedef PythonCastStatic<PythonObject::sequence_tag> seq_type;
return PythonCastStatic<>(args)(op, seq_type(args->next)).assign_to(res);
if (! PythonCastStatic<>(args)(op, seq_type(args->next)).assign_to(res))
return FALSE;

BOOLEAN newstruct_OpM(int, leftv, leftv); // forward declaration
return newstruct_OpM(op, res, args);
}

/// blackbox support - destruction
Expand Down Expand Up @@ -651,6 +654,7 @@ void pyobject_init()
b->blackbox_Op2 = pyobject_Op2;
b->blackbox_Op3 = pyobject_Op3;
b->blackbox_OpM = pyobject_OpM;
b->data = omAlloc0(newstruct_desc_size());

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

Expand Down

0 comments on commit b2aa086

Please sign in to comment.