Changeset 29fc843 in git


Ignore:
Timestamp:
Aug 1, 2012, 11:31:30 PM (10 years ago)
Author:
Alexander Dreyer <alexander.dreyer@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '96ce329119711a2b80858c8365abd29f8460bbfa')
Children:
4e59df46c64bb033f20a2ce6b6f131f03b06e6eb
Parents:
a04a05cbf86469aad8cb230b8c9418b1b96c2925
git-author:
Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-08-01 23:31:30+02:00
git-committer:
Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-08-01 23:32:11+02:00
Message:
new: convert pyobject <-> intvec
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/pyobject.cc

    ra04a05 r29fc843  
    2121
    2222#include <kernel/febase.h>
     23#include <kernel/intvec.h>
    2324
    2425#include "subexpr.h"
     
    298299class PythonCastStatic:
    299300  public PythonObject {
     301  typedef PythonCastStatic self;
    300302public:
    301303
     
    309311  ptr_type get(ptr_type value)       { return value; }
    310312  ptr_type get(long value)           { return PyInt_FromLong(value); }
     313  ptr_type get(int value)            { return PyInt_FromLong((long)value); }
    311314  ptr_type get(const char* value)    { return PyString_FromString(value); }
    312315  ptr_type get(char* value) { return get(const_cast<const char*>(value)); }
     316  ptr_type get(intvec* value);       // inlined below
    313317  ptr_type get(lists value);         // inlined after PythonObjectDynamic
    314318};
    315319
    316 
     320template <class CastType>
     321inline PythonObject::ptr_type
     322PythonCastStatic<CastType>::get(intvec* value)
     323{
     324  ptr_type pylist(PyList_New(0));
     325  for (int idx = 0; idx < value->length(); ++idx)
     326    PyList_Append(pylist, self::get((*value)[idx]));
     327
     328  return pylist;
     329}
    317330
    318331/** @class PythonCastDynamic
     
    337350    case STRING_CMD: return PythonCastStatic<const char*>(value);
    338351    case LIST_CMD:   return PythonCastStatic<lists>(value);
     352    case INTVEC_CMD: return PythonCastStatic<intvec*>(value);
    339353    }
    340354
     
    521535      res->data = (void*) omStrDup("pyobject");
    522536      res->rtyp = STRING_CMD; 
    523       return FALSE; 
     537      return FALSE;
    524538  }
    525539
     
    575589BOOLEAN pyobject_OpM(int op, leftv res, leftv args)
    576590{
    577   typedef PythonCastStatic<PythonObject::sequence_tag> seq_type;
    578 
    579591  switch(op)                    // built-in return types first
    580592  {
     
    586598      return FALSE;
    587599    }
    588   }
    589 
     600
     601    case INTVEC_CMD:
     602      PythonObject obj = PythonCastStatic<>(args->Data());
     603      unsigned long len = obj.size();
     604
     605      intvec* vec = new intvec(len);
     606      for(unsigned long idx = 0; idx != len; ++idx) {
     607        long value = PyInt_AsLong(obj[idx]);
     608        (*vec)[idx] = static_cast<int>(value);
     609
     610        if ((value == -1) &&  PyErr_Occurred()) {
     611          value = 0;
     612          PyErr_Clear();
     613        }
     614        if (value != long((*vec)[idx])) {
     615          delete vec;
     616          Werror("'pyobject` cannot be converted to intvec");
     617          return TRUE;
     618        }
     619      }
     620      res->data = (void *)vec;
     621      res->rtyp = op;
     622      return FALSE;
     623  }
    590624  typedef PythonCastStatic<PythonObject::sequence_tag> seq_type;
    591625  if (! PythonCastStatic<>(args)(op, seq_type(args->next)).assign_to(res))
  • Tst/Short/pyobject.res.gz.uu

    ra04a05 r29fc843  
    11begin 644 pyobject.res.gz
    2 M'XL("(\QZD\``W!Y;V)J96-T+G)E<P#M66UOVS80_NY?P1H#;">N8[W+R>*A
    3 M[89MP-`-RX!]Z#)%EAE;BR0:DMS$_?6[$\DC_;)FV8<!`]:B*<F[YWAWO#N>
    4 MF)M?OO[^/6/,F;,?OG_+^FW33HI\T;_JW2B*.V>PF.15W@Y'5SW\G\WG;+,3
    5 MBS]XUDXJ_CAIVK0E@#=G-/8G[.*"O6F:?%65O&J9N&=-6^?5BA5YR^NT:%A:
    6 M+5E>M7S%ZX:`P81V@`%`V#7KIP=82\MP;O.+B@._8\B1I5,\,>/91$J_Z@T.
    7 MA0\TDS.=2Y%7/8?6'"/0<8U`Q^L,?K?FV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C#`?*.VVZ5XWVC]W50(^SK?IM$=Z04Y-'3++")R,S/NY4*LO<J
     44MDWY5F;<DL<IDSFF-1V_$\]<5>[4);A(5=<+ASD!N/7FH[S0#/D"_36YK!J?F
     45MB/W334/9?#QH'?87VP=V7[[PY0\#H@_V^H9S1:<[.C;H85O30"'6T?UQ>IE!
     46MK.KS0M1/O)%IOQ.R72D%@IKJB1>$FXST"GOR[2[@K#BEEPMV*TDZ^..#9"X^
     47ME`*XBOT,*Y)CG<2WVUSW@V$XM*W0(`GVF2-O"PPEZ^-&:9"`RHIG7T5^R9:@
     48M3D!)2,G]!O@M4DSH9X9M</?`M1,:V>[,IZP%-\8%#P/;:I.^[U,1QI1O$>I.
     49M[?/<"#S8W8;KAJLL-]4G`^:M>+718EU1#96DTZ^;0?F9VNW`[_^G9DA?,\,K
     50M0OT79G""%[9XY9?3YMH?O@RKC?4[\%[93,;6,Z)(61KKM:GML0>I;4`IZ;LM
     51MU.2]@6I_-]5M,!I%,^Q6]_TAN_5>O!G\N?6J#:3#VV"&,^\SCOW9;$8Q(0V=
     52<+:*1_)B-WZNWK=/C#;#'^[NS?P/;IO'4#A\`````
    4753`
    4854end
  • Tst/Short/pyobject.stat

    ra04a05 r29fc843  
    1 1 >> tst_memory_0 :: 1295945736:3120- exported :3-1-2:ix86-Linux:mamawutz:185276
    2 1 >> tst_memory_1 :: 1295945736:3120- exported :3-1-2:ix86-Linux:mamawutz:1466368
    3 1 >> tst_memory_2 :: 1295945736:3120- exported :3-1-2:ix86-Linux:mamawutz:1466368
    4 1 >> tst_timer_1 :: 1295945736:3120- exported :3-1-2:ix86-Linux:mamawutz:11
     11 >> tst_memory_0 :: 1340802591:3144- exported :3-1-4:x86_64-Linux:lts035:220512
     21 >> tst_memory_1 :: 1340802591:3144- exported :3-1-4:x86_64-Linux:lts035:3239936
     31 >> tst_memory_2 :: 1340802591:3144- exported :3-1-4:x86_64-Linux:lts035:3239936
     41 >> tst_timer_1 :: 1340802591:3144- exported :3-1-4:x86_64-Linux:lts035:9
  • Tst/Short/pyobject.tst

    ra04a05 r29fc843  
    142142ll_empty;
    143143
     144// converting to and from intvec
     145intvec v0;
     146v0;
     147pyobject obj0 = v0;
     148obj0;
     149
     150intvec v=(1,2,3);
     151pyobject obj = v;
     152obj;
     153intvec(obj);
     154
     155intvec(python_eval("[1,2,9999999999]")); // -> error
     156intvec(python_eval("[1,2,list()]"));     // -> error
     157
     158ring r=0,x,lp;
     159def rl = ringlist(r);
     160
     161python_eval("tuple")(list(rl[1..3]));
    144162
    145163tst_status(1);
Note: See TracChangeset for help on using the changeset viewer.