Changeset 29fc843 in git for Singular/pyobject.cc
- Timestamp:
- Aug 1, 2012, 11:31:30 PM (11 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'ad2543eab51733612ba7d118afc77edca719600e')
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/pyobject.cc
ra04a05 r29fc843 21 21 22 22 #include <kernel/febase.h> 23 #include <kernel/intvec.h> 23 24 24 25 #include "subexpr.h" … … 298 299 class PythonCastStatic: 299 300 public PythonObject { 301 typedef PythonCastStatic self; 300 302 public: 301 303 … … 309 311 ptr_type get(ptr_type value) { return value; } 310 312 ptr_type get(long value) { return PyInt_FromLong(value); } 313 ptr_type get(int value) { return PyInt_FromLong((long)value); } 311 314 ptr_type get(const char* value) { return PyString_FromString(value); } 312 315 ptr_type get(char* value) { return get(const_cast<const char*>(value)); } 316 ptr_type get(intvec* value); // inlined below 313 317 ptr_type get(lists value); // inlined after PythonObjectDynamic 314 318 }; 315 319 316 320 template <class CastType> 321 inline PythonObject::ptr_type 322 PythonCastStatic<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 } 317 330 318 331 /** @class PythonCastDynamic … … 337 350 case STRING_CMD: return PythonCastStatic<const char*>(value); 338 351 case LIST_CMD: return PythonCastStatic<lists>(value); 352 case INTVEC_CMD: return PythonCastStatic<intvec*>(value); 339 353 } 340 354 … … 521 535 res->data = (void*) omStrDup("pyobject"); 522 536 res->rtyp = STRING_CMD; 523 return FALSE; 537 return FALSE; 524 538 } 525 539 … … 575 589 BOOLEAN pyobject_OpM(int op, leftv res, leftv args) 576 590 { 577 typedef PythonCastStatic<PythonObject::sequence_tag> seq_type;578 579 591 switch(op) // built-in return types first 580 592 { … … 586 598 return FALSE; 587 599 } 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 } 590 624 typedef PythonCastStatic<PythonObject::sequence_tag> seq_type; 591 625 if (! PythonCastStatic<>(args)(op, seq_type(args->next)).assign_to(res))
Note: See TracChangeset
for help on using the changeset viewer.