Пример #1
0
 PySequence_Repeat(IntPtr objPtr, int count)
 {
     try
     {
         IntPtr typePtr = CPyMarshal.ReadPtrField(objPtr, typeof(PyObject), "ob_type");
         IntPtr seqPtr  = CPyMarshal.ReadPtrField(typePtr, typeof(PyTypeObject), "tp_as_sequence");
         if (seqPtr != IntPtr.Zero)
         {
             IntPtr sq_repeat = CPyMarshal.ReadPtrField(seqPtr, typeof(PySequenceMethods), "sq_repeat");
             if (sq_repeat != IntPtr.Zero)
             {
                 dgt_ptr_ptrint dgt = (dgt_ptr_ptrint)CPyMarshal.ReadFunctionPtrField(
                     seqPtr, typeof(PySequenceMethods), "sq_repeat", typeof(dgt_ptr_ptrint));
                 return(dgt(objPtr, count));
             }
         }
         object obj = this.Retrieve(objPtr);
         if ((!Builtin.isinstance(obj, TypeCache.PythonType)) &&
             Builtin.hasattr(this.scratchContext, obj, "__len__") &&
             Builtin.hasattr(this.scratchContext, obj, "__getitem__"))
         {
             return(this.Store(PythonOperator.mul(this.scratchContext, obj, (int)count)));
         }
         throw PythonOps.TypeError("PySequence_Repeat: failed to convert {0} to sequence", obj);
     }
     catch (Exception e)
     {
         this.LastException = e;
         return(IntPtr.Zero);
     }
 }