Exemplo n.º 1
0
 def __init__(self,larg,internal=False):
     SHMOBJ.__init__(self, larg, internal)
     if isinstance(larg,list):
         self.addr = py2shmobj.shmlist_init()
         if self.addr is None:
             raise Exception('SHMLST allocation failed: out of memory')
         for e in larg:
             if not isinstance(e, SHMOBJ):
                 raise TypeError("** invalid type being inserted in shmlist")
             ep = e.get_ptr()
             np = py2shmobj.shmlnode_alloc()
             (datatype, datalen) = get_type_and_len(e)
             py2shmobj.shmlnode_init(np,ep,datatype,datalen)
             py2shmobj.shmlist_append(self.addr,np)
     elif self.addr is None:
         raise TypeError("invalid type %s assigned to SHMLST" % type(arg))
Exemplo n.º 2
0
    def insert(self, idx, item):
        SHMOBJ.protect(self)
        mylen = len(self)
        if(idx < 0):
            idx += mylen
        if(idx < 0):
            idx = 0
        if(idx > mylen):
            idx = mylen

        if not isinstance(item, SHMOBJ):
            raise TypeError("cannot insert type '%s' into SHMLST" % type(item))
        datatype, datalen = get_type_and_len(item)
        ep = item.get_ptr()
        np = py2shmobj.shmlnode_alloc()
        if np is None:
            raise Exception('shmlnode_alloc failed: out of memory')
        py2shmobj.shmlnode_init(np,ep,datatype,datalen)
        py2shmobj.shmlist_insert(self.addr, idx, np)
        return None