Changeset b2aa08 in git


Ignore:
Timestamp:
Aug 1, 2012, 11:07:23 PM (10 years ago)
Author:
Alexander Dreyer <alexander.dreyer@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '96ce329119711a2b80858c8365abd29f8460bbfa')
Children:
1161a6145a6ca3b9034865b05528815c65f55cfb
Parents:
632c3a619d605d6b049c3f7f82a323ea8113e34b
Message:
fix: pyobject falls back to newstruct operations
Location:
Singular
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Singular/newstruct.cc

    r632c3a rb2aa08  
    3939};
    4040
     41int newstruct_desc_size()
     42{
     43  return sizeof(newstruct_desc_s);
     44}
    4145
    4246char * newstruct_String(blackbox *b, void *d)
     
    664668  blackbox *bb=getBlackboxStuff(id);
    665669  newstruct_desc desc=(newstruct_desc)bb->data;
    666   if (desc == NULL)
    667   {
    668     desc=(newstruct_desc)omAlloc0(sizeof(*desc));
    669     desc->size=0;
    670     bb->data = (void*)desc;
    671   }
    672 
    673670  newstruct_proc p=(newstruct_proc)omAlloc(sizeof(*p));
    674671  p->next=desc->procs; desc->procs=p;
  • Singular/newstruct.h

    r632c3a rb2aa08  
    55
    66void newstruct_setup(const char * name, newstruct_desc d);
     7int newstruct_desc_size();
    78newstruct_desc newstructFromString(const char *s);
    89newstruct_desc newstructChildFromString(const char *p, const char *s);
  • Singular/pyobject.cc

    r632c3a rb2aa08  
    1616#include <kernel/mod2.h>
    1717#include <misc/auxiliary.h>
     18#include "newstruct.h"
    1819
    1920#include <omalloc/omalloc.h>
     
    107108  typedef PyObject* ptr_type;
    108109  struct sequence_tag{};
     110  struct null_tag {};
    109111
    110112  PythonObject(): m_ptr(Py_None) { }
     113  PythonObject(null_tag): m_ptr(NULL) { }
    111114  PythonObject(ptr_type ptr): m_ptr(ptr) {if (!ptr) handle_exception();}
    112115
     
    128131      return *this;
    129132
    130     Werror("unary operation '%s` not implemented for 'pyobject`", iiTwoOps(op));
    131     return self();
     133    return self(null_tag());
    132134  }
    133135
     
    148150      case '.': case COLONCOLON: case ATTRIB_CMD: return attr(arg);
    149151    }
    150     Werror("binary operation '%d` not implemented for 'pyobject`", iiTwoOps(op));
    151 
    152     return self();
     152    return self(null_tag());
    153153  }
    154154
     
    160160      case ATTRIB_CMD: PyObject_SetAttr(*this, arg1, arg2); return self();
    161161    }
    162 
    163162    Werror("ternary operation %s not implemented for 'pyobject`", iiTwoOps(op));
    164     return self();
     163    return self(null_tag());
    165164  }
    166165
     
    185184  BOOLEAN assign_to(leftv result)
    186185  {
    187     return (m_ptr == Py_None? none_to(result): python_to(result));
     186    return (m_ptr? (m_ptr == Py_None? none_to(result): python_to(result)): TRUE);
    188187  }
    189188
     
    515514      res->rtyp = STRING_CMD; 
    516515      return FALSE;
    517 
    518   case LIST_CMD:
     516  }
     517
     518  if (!PythonCastStatic<>(head)(op).assign_to(res))
    519519    return FALSE;
    520520
    521   }
    522 
    523   if (op > MAX_TOK)       // custom types
    524   {
    525     BOOLEAN newstruct_Op1(int, leftv, leftv);
    526     if (! newstruct_Op1(op, res, head) ) return FALSE;
    527   }
    528 
    529   return PythonCastStatic<>(head)(op).assign_to(res);
     521  BOOLEAN newstruct_Op1(int, leftv, leftv); // forward declaration
     522  return newstruct_Op1(op, res, head);
    530523}
    531524
     
    547540      return lhs.attr(get_attrib_name(arg2)).assign_to(res);
    548541  }
     542
    549543  PythonCastDynamic rhs(arg2);
    550   return lhs(op, rhs).assign_to(res);
     544  if (!lhs(op, rhs).assign_to(res))
     545    return FALSE;
     546
     547  BOOLEAN newstruct_Op2(int, leftv, leftv, leftv); // forward declaration
     548  return newstruct_Op2(op, res, arg1, arg2);
     549
    551550}
    552551
     
    579578
    580579  typedef PythonCastStatic<PythonObject::sequence_tag> seq_type;
    581   return PythonCastStatic<>(args)(op, seq_type(args->next)).assign_to(res);
     580  if (! PythonCastStatic<>(args)(op, seq_type(args->next)).assign_to(res))
     581    return FALSE;
     582
     583  BOOLEAN newstruct_OpM(int, leftv, leftv); // forward declaration
     584  return newstruct_OpM(op, res, args);
    582585}
    583586
     
    652655  b->blackbox_Op3     = pyobject_Op3;
    653656  b->blackbox_OpM     = pyobject_OpM;
     657  b->data             = omAlloc0(newstruct_desc_size());
    654658
    655659  PythonInterpreter::init(setBlackboxStuff(b,"pyobject"));
Note: See TracChangeset for help on using the changeset viewer.