Exemplo n.º 1
0
void tcaxlib_convert_tcas_list_to_buf(PyObject *tcasList, tcas_unit **pTcasBuf, tcas_u32 *pCount) {
    int i, count;
    PyObject *pyTcasItem;
    tcas_s16 x, y;
    tcas_u32 rgb;
    tcas_byte alpha;
    tcas_unit *tcasBuf;
    count = PyList_GET_SIZE(tcasList);
    /* tcas buffer from user tcax py script: (Start, End, Layer_Type_Pair, PosX, PosY, RGB, Alpha) */
    /* a raw tcas chunk defined in TCC file format specification: (Start, End, Layer_Type_Pair, Pos, RGBA) */
    tcasBuf = (tcas_unit *)malloc(count * 5 * sizeof(tcas_unit));
    for (i = 0; i < count; i++) {
        pyTcasItem = PyList_GET_ITEM(tcasList, i);
        x = (tcas_s16)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 3));
        y = (tcas_s16)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 4));
        rgb = (tcas_u32)PyLong_AsUnsignedLong(PyTuple_GET_ITEM(pyTcasItem, 5));
        alpha = (tcas_byte)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 6));
        tcasBuf[5 * i + 0] = (tcas_s32)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 0));    /* Start */
        tcasBuf[5 * i + 1] = (tcas_s32)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 1));    /* End */
        tcasBuf[5 * i + 2] = (tcas_unit)PyLong_AsUnsignedLong(PyTuple_GET_ITEM(pyTcasItem, 2));    /* Layer_Type_Pair */
        tcasBuf[5 * i + 3] = MAKEPOS(x, y);
        tcasBuf[5 * i + 4] = (rgb | ((tcas_u32)alpha << 24));
    }
    *pTcasBuf = tcasBuf;
    *pCount = count;
}
Exemplo n.º 2
0
bool_t gen_mcev_from_evrepr(PyObject *evrepr, uint_t *tick, midicev_t *mcev)
{
  Py_ssize_t    list_len = PyTuple_Size(evrepr);
  unsigned long chan, type, val1, val2;

  if (list_len < 5)
    return FALSE;
  /* todo: more test */
  *tick = (uint_t) PyLong_AsUnsignedLong(PyTuple_GetItem(evrepr, 0));
  chan  = PyLong_AsUnsignedLong(PyTuple_GetItem(evrepr, 1));
  type  = PyLong_AsUnsignedLong(PyTuple_GetItem(evrepr, 2));
  val1  = PyLong_AsUnsignedLong(PyTuple_GetItem(evrepr, 3));
  val2  = PyLong_AsUnsignedLong(PyTuple_GetItem(evrepr, 4));
  mcev->chan = (byte_t) chan;
  mcev->type = (byte_t) type;
  switch (type)
    {
    case NOTEOFF:
    case NOTEON:
      mcev->event.note.num = (byte_t) val1;
      mcev->event.note.val = (byte_t) val2;
      break;
    case CONTROLCHANGE:
      mcev->event.ctrl.num = (byte_t) val1;
      mcev->event.ctrl.val = (byte_t) val2;
      break;
    case PITCHWHEELCHANGE:
      mcev->event.pitchbend.Lval = (byte_t) val1;
      mcev->event.pitchbend.Hval = (byte_t) val2;
      break;
    default:
      ;
    }
  return TRUE;
}
Exemplo n.º 3
0
static PyObject* pyGLTexture__enter__(pyGLTexture* self) {
    // Is the image already loaded?
    PyObjectRef bindcode = PyObject_GetAttrString(self->m_blenderImage, "bindcode");

    // bindcode changed to a sequence in 2.77. We want the first element for a 2D texture.
    // Why did we make this change, exactly?
    if (PySequence_Check(bindcode)) {
        bindcode = PySequence_GetItem(bindcode, TEXTARGET_TEXTURE_2D);
    }

    // Now we should have a GLuint...
    if (!PyLong_Check(bindcode)) {
        PyErr_SetString(PyExc_TypeError, "Image bindcode isn't a long?");
        return NULL;
    }

    glGetIntegerv(GL_TEXTURE_BINDING_2D, &self->m_prevImage);
    GLuint image_bindcode = PyLong_AsUnsignedLong(bindcode);
    self->m_ownIt = image_bindcode == 0;

    // Load image into GL
    if (self->m_ownIt) {
        PyObjectRef new_bind = PyObject_CallMethod(self->m_blenderImage, "gl_load", NULL);
        if (!PyLong_Check(new_bind)) {
            PyErr_SetString(PyExc_TypeError, "gl_load() did not return a long");
            return NULL;
        }
        ssize_t result = PyLong_AsSize_t(new_bind);
        if (result != GL_NO_ERROR) {
            PyErr_Format(PyExc_RuntimeError, "gl_load() error: %d", result);
            return NULL;
        }
        bindcode = PyObject_GetAttrString(self->m_blenderImage, "bindcode");
        if (PySequence_Check(bindcode)) {
            bindcode = PySequence_GetItem(bindcode, TEXTARGET_TEXTURE_2D);
        }
        // Now we should have a GLuint...
        if (!PyLong_Check(bindcode)) {
            PyErr_SetString(PyExc_TypeError, "Image bindcode isn't a long?");
            return NULL;
        }
        image_bindcode = PyLong_AsUnsignedLong(bindcode);
    }

    // Set image as current in GL
    if (self->m_prevImage != image_bindcode) {
        self->m_changedState = true;
        glBindTexture(GL_TEXTURE_2D, image_bindcode);
    }

    // Misc GL state
    glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, &self->m_mipmapState);

    Py_INCREF(self);
    return (PyObject*)self;
}
Exemplo n.º 4
0
// @object PySPropTagArray|A sequence of integers
BOOL PyMAPIObject_AsSPropTagArray(PyObject *obta, SPropTagArray **ppta)
{
	if (obta==Py_None) {
		*ppta = NULL;
		return TRUE;
	}
	BOOL bSeq = TRUE;
	int seqLen;
	if (PySequence_Check(obta)) {
		seqLen = PySequence_Length(obta);
	} else if (PyInt_Check(obta)) {
		seqLen = 1;
		bSeq = FALSE;
	} else {
		PyErr_SetString(PyExc_TypeError, "SPropTagArray must be a sequence of integers");
		return FALSE;
	}

	DWORD cBytes = (seqLen * sizeof(ULONG)) + sizeof(ULONG);
	SPropTagArray *pta;
	HRESULT hr = MAPIAllocateBuffer(cBytes, (void **)&pta);
	if (FAILED(hr)) {
		OleSetOleError(hr);
		return FALSE;
	}
	pta->cValues = seqLen;
	if (bSeq) {
		for (ULONG i=0;i<(ULONG)seqLen;i++) {
			PyObject *obItem = PySequence_GetItem(obta, i);
			if (obItem==NULL) {
				MAPIFreeBuffer(pta);
				return FALSE;
			}
			pta->aulPropTag[i] = PyLong_AsUnsignedLong(obItem);
			if (PyErr_Occurred()) {
				Py_DECREF(obItem);
				MAPIFreeBuffer(pta);
				return FALSE;
			}
			Py_DECREF(obItem);
		}
	} else {
		// Simple int.
		pta->aulPropTag[0] = PyLong_AsUnsignedLong(obta);
	}
	*ppta = pta;
	return TRUE;
}
Exemplo n.º 5
0
static int convertTo_std_vector_1900(PyObject *sipPy,void **sipCppPtrV,int *sipIsErr,PyObject *sipTransferObj)
{
    std::vector<uint> **sipCppPtr = reinterpret_cast<std::vector<uint> **>(sipCppPtrV);

#line 330 "/home/kdbanman/browseRDF/tulip-3.8.0-src/library/tulip-python/stl/vector.sip"
   // Check if type is compatible
   if (sipIsErr == NULL) {
       if (!PyList_Check(sipPy)) {
          return 0;
       }
       for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i) {
            PyObject *item = PyList_GET_ITEM(sipPy, i);
            if (!PyLong_Check(item)) {
                printErrorMessage("TypeError : object in list of type " + std::string(item->ob_type->tp_name) + " can not be converted to int");
                return 0;
            }
       }
       return 1;
   }

   // Convert Python list of integers to a std::vector<int>
   std::vector<unsigned int> *v = new std::vector<unsigned int>();
   v->reserve(PyList_GET_SIZE(sipPy));
   for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i) {
       v->push_back(PyLong_AsUnsignedLong(PyList_GET_ITEM(sipPy, i)));
   }

   *sipCppPtr = v;
   return sipGetState(sipTransferObj);
#line 76 "/home/kdbanman/browseRDF/tulip-3.8.0-src/build/library/tulip-python/stl/sipstlstdvector1900.cpp"
}
Exemplo n.º 6
0
static int lightblueobex_add4byteheader(obex_t *obex, obex_object_t *obj, uint8_t hi, PyObject *value)
{
    obex_headerdata_t hv;
    uint32_t intvalue;

    DEBUG("%s()\n", __func__);

    if (value == NULL)
        return -1;

    if (PyInt_Check(value)) {
        intvalue = PyInt_AsLong(value);
        if (PyErr_Occurred()) {
            DEBUG("\tcan't convert header 0x%02x int value to long", hi);
            PyErr_Clear();
            return -1;
        }
    } else if (PyLong_Check(value)) {
        intvalue = PyLong_AsUnsignedLong(value);
        if (PyErr_Occurred()) {
            DEBUG("\tcan't convert header 0x%02x long value to long", hi);
            PyErr_Clear();
            return -1;
        }
    } else {
        DEBUG("\theader value for id 0x%02x must be int or long, was %s\n",
                hi, value->ob_type->tp_name);
        return -1;
    }

    hv.bq4 = intvalue;
    return OBEX_ObjectAddHeader(obex, obj, hi, hv, 4, OBEX_FL_FIT_ONE_PACKET);
}
static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        if (unlikely(Py_SIZE(x) < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return PyLong_AsUnsignedLong(x);
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}
Exemplo n.º 8
0
bool IntType<SPECIFY_TYPE>::isSameType(PyObject* pyValue)
{
	int ival = 0;
	if(PyLong_Check(pyValue))
	{
		ival = (int)PyLong_AsLong(pyValue);
		if(PyErr_Occurred())
		{
			PyErr_Clear();
			ival = (int)PyLong_AsUnsignedLong(pyValue);
			if (PyErr_Occurred())
			{
				OUT_TYPE_ERROR("INT");
				return false;
			}
		}
	}
	else
	{
		OUT_TYPE_ERROR("INT");
		return false;
	}

	SPECIFY_TYPE val = (SPECIFY_TYPE)ival;
	if(ival != int(val))
	{
		ERROR_MSG("IntType::isSameType:%d is out of range (currVal = %d).\n", ival, int(val));
		return false;
	}
	return true;
}
Exemplo n.º 9
0
 static T extract(PyObject* intermediate)
 {
     unsigned long x = PyLong_AsUnsignedLong(intermediate);
     if (PyErr_Occurred())
         throw_error_already_set();
     return numeric_cast<T>(x);
 }
Exemplo n.º 10
0
PyObject *
Blame_getitem(Blame *self, PyObject *value)
{
    size_t i;
    const git_blame_hunk *hunk;

    if (PyLong_Check(value) < 0) {
        PyErr_SetObject(PyExc_IndexError, value);
        return NULL;
    }

    i = PyLong_AsUnsignedLong(value);
    if (PyErr_Occurred()) {
        PyErr_SetObject(PyExc_IndexError, value);
        return NULL;
    }

    hunk = git_blame_get_hunk_byindex(self->blame, i);
    if (!hunk) {
        PyErr_SetObject(PyExc_IndexError, value);
        return NULL;
    }

    return wrap_blame_hunk(hunk, self);
}
Exemplo n.º 11
0
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return (signed long)PyLong_AsUnsignedLong(x);
        } else {
            return (signed long)PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}
Exemplo n.º 12
0
static int Stroke_texture_id_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure))
{
	unsigned int i = PyLong_AsUnsignedLong(value);
	if (PyErr_Occurred())
		return -1;
	self->s->setTextureId(i);
	return 0;
}
Exemplo n.º 13
0
static int FEdgeSmooth_material_index_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
{
	unsigned int i = PyLong_AsUnsignedLong(value);
	if (PyErr_Occurred())
		return -1;
	self->fes->setFrsMaterialIndex(i);
	return 0;
}
 void _extract(PyObject *obj, unsigned long &val)
 {
     if (PyInt_Check(obj))
         val = (unsigned long)PyInt_AsUnsignedLongMask(obj);
     else if (PyFloat_Check(obj))
         val = (unsigned long)PyFloat_AsDouble(obj);
     else
         val = PyLong_AsUnsignedLong(obj);
 }
Exemplo n.º 15
0
static void to_td_val(td_val_t *out, PyObject *pVal)
{
    PyObject *pStr;
    td_array_t *arr;
    PyArrayObject *pArr;
    td_tag_t tag = py_type_to_td(pVal);
    switch (tag) {
    case TD_INT32:
        out->tag = TD_INT32;
        if (PyInt_Check(pVal))
            out->int32_val = PyInt_AS_LONG(pVal);
        else
            out->int32_val = PyLong_AsLong(pVal);
        break;
    case TD_UINT32:
        out->tag = TD_UINT32;
        out->uint32_val = PyLong_AsUnsignedLong(pVal);
        break;
    case TD_INT64:
        out->tag = TD_INT64;
        out->int64_val = PyLong_AsLongLong(pVal);
        break;
    case TD_UINT64:
        out->tag = TD_UINT64;
        out->uint64_val = PyLong_AsUnsignedLongLong(pVal);
        break;
    case TD_DOUBLE:
        out->tag = TD_DOUBLE;
        out->double_val = PyFloat_AsDouble(pVal);
        break;
    case TD_UTF8:
        pStr = pVal;
        if (PyUnicode_Check(pStr)) pStr = PyUnicode_AsUTF8String(pStr);
        size_t len = PyString_Size(pStr);
        char* data = malloc((len+1)*sizeof(char));
        strcpy(PyString_AsString(pStr), data);
        td_string_t *obj = malloc(sizeof(td_string_t));
        obj->length = len;
        obj->data = (void*) data;
        out->tag = TD_UTF8;
        out->object = (void*) obj;
        break;
    case TD_ARRAY:
        arr = (td_array_t *)malloc(sizeof(td_array_t));
        pArr = (PyArrayObject *) pVal;
        arr->data = PyArray_DATA(pArr);
        arr->length = PyArray_SIZE(pArr);
        arr->eltype = numpy_type_to_td(PyArray_TYPE(pArr));
        arr->ndims = PyArray_NDIM(pArr);
        break;
    default:
        out->tag = TD_OBJECT;
        out->owner = td_env_python(NULL, NULL);
        out->object = pVal;
    }
}
Exemplo n.º 16
0
static int convertTo_QPair_1900_1900(PyObject *sipPy,void **sipCppPtrV,int *sipIsErr,PyObject *sipTransferObj)
{
     ::QPair<uint,uint> **sipCppPtr = reinterpret_cast< ::QPair<uint,uint> **>(sipCppPtrV);

#line 63 "/home/thais/Faculdade/TCC/NEW/PyQt4_gpl_x11-4.12/sip/QtCore/qpair.sip"
    // Check the type if that is all that is required.
    if (sipIsErr == NULL)
        return (PyTuple_Size(sipPy) == 2);

    QPair<unsigned, unsigned> *qp = new QPair<unsigned, unsigned>;
 
    qp->first = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(sipPy, 0));
    qp->second = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(sipPy, 1));

    *sipCppPtr = qp;
 
    return sipGetState(sipTransferObj);
#line 83 "/home/thais/Faculdade/TCC/NEW/PyQt4_gpl_x11-4.12/QtCore/sipQtCoreQPair19001900.cpp"
}
Exemplo n.º 17
0
PyObject *
Diff_getitem(Diff *self, PyObject *value)
{
    size_t i;

    if (!PyLong_Check(value))
        return NULL;

    i = PyLong_AsUnsignedLong(value);
    return diff_get_patch_byindex(self->diff, i);
}
Exemplo n.º 18
0
static PyObject *
_wrap_sugar_key_grabber_get_key(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "keycode", "state", NULL };
    PyObject *py_keycode = NULL, *py_state = NULL;
    gchar *ret;
    guint keycode = 0, state = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"OO:Sugar.KeyGrabber.get_key", kwlist, &py_keycode, &py_state))
        return NULL;
    if (py_keycode) {
        if (PyLong_Check(py_keycode))
            keycode = PyLong_AsUnsignedLong(py_keycode);
        else if (PyInt_Check(py_keycode))
            keycode = PyInt_AsLong(py_keycode);
        else
            PyErr_SetString(PyExc_TypeError, "Parameter 'keycode' must be an int or a long");
        if (PyErr_Occurred())
            return NULL;
    }
    if (py_state) {
        if (PyLong_Check(py_state))
            state = PyLong_AsUnsignedLong(py_state);
        else if (PyInt_Check(py_state))
            state = PyInt_AsLong(py_state);
        else
            PyErr_SetString(PyExc_TypeError, "Parameter 'state' must be an int or a long");
        if (PyErr_Occurred())
            return NULL;
    }
    
    ret = sugar_key_grabber_get_key(SUGAR_KEY_GRABBER(self->obj), keycode, state);
    
    if (ret) {
        PyObject *py_ret = PyString_FromString(ret);
        g_free(ret);
        return py_ret;
    }
    Py_INCREF(Py_None);
    return Py_None;
}
// ---------------------------------------------------
//
// Gateway Implementation
STDMETHODIMP PyGPropertyDescriptionList::GetCount(UINT * pcElem)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetCount", &result);
	if (FAILED(hr)) return hr;
	*pcElem = PyLong_AsUnsignedLong(result);
	if (*pcElem == (UINT)-1 && PyErr_Occurred())
		hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetCount");
	Py_DECREF(result);
	return hr;
}
Exemplo n.º 20
0
static int convertTo_std_pair_1900_1900(PyObject *sipPy,void **sipCppPtrV,int *sipIsErr,PyObject *sipTransferObj)
{
    std::pair<uint,uint> **sipCppPtr = reinterpret_cast<std::pair<uint,uint> **>(sipCppPtrV);

#line 391 "/home/kdbanman/browseRDF/tulip-3.8.0-src/library/tulip-python/stl/pair.sip"
    PyObject *itm1 = NULL;
    PyObject *itm2 = NULL;

    if (sipIsErr == NULL) {
        if (!(PyTuple_Check(sipPy) && PyTuple_Size(sipPy) == 2))
            return 0;

        itm1 = PyTuple_GetItem(sipPy, 0);
        itm2 = PyTuple_GetItem(sipPy, 1);

        bool ok = PyLong_Check(itm1);
        ok = ok && PyLong_Check(itm2);

        if (!ok) {
            return 0;
        }

        return 1;
    }

    itm1 = PyTuple_GetItem(sipPy, 0);
    itm2 = PyTuple_GetItem(sipPy, 1);

    int t1State = 0;
    int t2State = 0;

    unsigned int ui1 = PyLong_AsUnsignedLong(itm1);
    unsigned int ui2 = PyLong_AsUnsignedLong(itm2);

    std::pair<unsigned int, unsigned int> *p = new std::pair<unsigned int, unsigned int>(ui1, ui2);

    *sipCppPtr = p;
    return sipGetState(sipTransferObj);
#line 85 "/home/kdbanman/browseRDF/tulip-3.8.0-src/build/library/tulip-python/stl/sipstlstdpair19001900.cpp"
}
Exemplo n.º 21
0
//-------------------------------------------------------------------------------------
void SpaceAvatarSelect::kbengine_onEvent(const KBEngine::EventData* lpEventData)
{
	switch(lpEventData->id)
	{
		case CLIENT_EVENT_SCRIPT:
			{
				const KBEngine::EventData_Script* peventdata = static_cast<const KBEngine::EventData_Script*>(lpEventData);
				if(peventdata->name == "update_avatars")
				{
					if(peventdata->argsSize > 0)
					{
						PyObject* pyitem = PyTuple_GetItem(peventdata->pyDatas, 0);
						for(KBEngine::uint32 i=0; i<g_avatars.size(); i++)
						{
							mTrayMgr->destroyWidget(g_avatars[i]);
						}
						
						g_avatars.clear();

						PyObject *key, *value;
						Py_ssize_t pos = 0;
						while (PyDict_Next(pyitem, &pos, &key, &value)) 
						{
							wchar_t* PyUnicode_AsWideCharStringRet0 = PyUnicode_AsWideCharString(PyDict_GetItemString(value, "name"), NULL);
							char* name = wchar2char(PyUnicode_AsWideCharStringRet0);
							PyMem_Free(PyUnicode_AsWideCharStringRet0);
							
							KBEngine::DBID dbid = 0;
							dbid = PyLong_AsUnsignedLongLong(key);
 							if (PyErr_Occurred())																	
 							{																						
								dbid = PyLong_AsUnsignedLong(key);														
							}	
 							if (PyErr_Occurred())																	
 							{																						
								PyErr_PrintEx(0);																	
							}	

							Ogre::String str = Ogre::String(name) + "_" + KBEngine::StringConv::val2str(dbid);
							g_avatars.push_back(str);
							mTrayMgr->createButton(OgreBites::TL_CENTER, str, str, 300);

							free(name);
						}																					
					}
				}
			}
			break;
		default:
			break;
	};
}
Exemplo n.º 22
0
STDMETHODIMP PyGShellItemArray::GetCount(
		/* [out] */ DWORD * pdwNumItems)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetCount", &result);
	if (FAILED(hr)) return hr;
	// Process the Python results, and convert back to the real params
	*pdwNumItems = PyLong_AsUnsignedLong(result);
	hr = PyCom_SetAndLogCOMErrorFromPyException("GetCount", IID_IShellItemArray);
	Py_DECREF(result);
	return hr;
}
Exemplo n.º 23
0
PyObject *
set_flags(PyObject *self, PyObject *args)
{
    PyTypeObject *cls;
    PyLongObject *flags_object;

    if (!PyArg_UnpackTuple(args, "set_flags", 2, 2, &cls, &flags_object))
        return NULL;

    unsigned long flags = PyLong_AsUnsignedLong(flags_object);
    cls->tp_flags = flags;
    Py_RETURN_NONE;
}
Exemplo n.º 24
0
static int
get_ulong(PyObject *v, unsigned long *p)
{
	if (PyLong_Check(v)) {
		unsigned long x = PyLong_AsUnsignedLong(v);
		if (x == (unsigned long)(-1) && PyErr_Occurred())
			return -1;
		*p = x;
		return 0;
	}
	else {
		return get_long(v, (long *)p);
	}
}
// ---------------------------------------------------
//
// Gateway Implementation
STDMETHODIMP PyGShellItemResources::GetAttributes(
		/* [out] */ DWORD * pdwAttributes)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetAttributes", &result);
	if (FAILED(hr)) return hr;
	// Process the Python results, and convert back to the real params
	*pdwAttributes = PyLong_AsUnsignedLong(result);
	if (*pdwAttributes == -1 && PyErr_Occurred())
		hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetAttributes");
	Py_DECREF(result);
	return hr;
}
Exemplo n.º 26
0
    Interface(int beam_width,
            PyObject * py_early_stop_callback,
            PyObject * py_shift_callback,
            PyObject * py_reduce_callback,
            PyObject * py_feature_cb
            ){
        if(PyLong_Check(py_shift_callback)){
            shifted_state_generator=(State_Generator *) PyLong_AsUnsignedLong(py_shift_callback);
        }else{
            shifted_state_generator=new Python_State_Generator(py_shift_callback);
        };

        reduced_state_generator=NULL;
        if(py_reduce_callback!=Py_None){
            reduced_state_generator=new Python_Reduced_State_Generator(py_reduce_callback);
        };

        if(PyLong_Check( py_feature_cb)){
            feature_generator=(Feature_Generator*) PyLong_AsUnsignedLong( py_feature_cb);
        }else{
            feature_generator=new Python_Feature_Generator( py_feature_cb);
        };
        early_stop_checker=NULL;
        if(py_early_stop_callback!=Py_None){
            early_stop_checker=new Python_Early_Stop_Checker(py_early_stop_callback);
        }

        raw=NULL;
        this->beam_width=beam_width;
        this->data=new General_Searcher_Data(
                early_stop_checker,
                shifted_state_generator,
                reduced_state_generator,
                feature_generator);
        this->push_down=new My_Searcher(this->data,beam_width);

    };
Exemplo n.º 27
0
static int
get_wrapped_ulong(PyObject *v, unsigned long *p)
{
	long x = (long)PyLong_AsUnsignedLong(v);
	if (x == -1 && PyErr_Occurred()) {
		PyObject *wrapped;
		PyErr_Clear();
#ifdef PY_STRUCT_FLOAT_COERCE
		if (PyFloat_Check(v)) {
			PyObject *o;
			int res;
			PyErr_Clear();
			if (PyErr_WarnEx(PyExc_DeprecationWarning, FLOAT_COERCE, 2) < 0)
				return -1;
			o = PyNumber_Int(v);
			if (o == NULL)
				return -1;
			res = get_wrapped_ulong(o, p);
			Py_DECREF(o);
			return res;
		}
#endif
		wrapped = PyNumber_And(v, pylong_ulong_mask);
		if (wrapped == NULL)
			return -1;
		if (PyErr_WarnEx(PyExc_DeprecationWarning, INT_OVERFLOW, 2) < 0) {
			Py_DECREF(wrapped);
			return -1;
		}
		x = (long)PyLong_AsUnsignedLong(wrapped);
		Py_DECREF(wrapped);
		if (x == -1 && PyErr_Occurred())
			return -1;
	}
	*p = (unsigned long)x;
	return 0;
}
Exemplo n.º 28
0
static PyObject *
_wrap_sugar_key_grabber_is_modifier(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "keycode", "mask", NULL };
    PyObject *py_keycode = NULL, *py_mask = NULL;
    int ret;
    guint keycode = 0, mask = -1;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O|O:Sugar.KeyGrabber.is_modifier", kwlist, &py_keycode, &py_mask))
        return NULL;
    if (py_keycode) {
        if (PyLong_Check(py_keycode))
            keycode = PyLong_AsUnsignedLong(py_keycode);
        else if (PyInt_Check(py_keycode))
            keycode = PyInt_AsLong(py_keycode);
        else
            PyErr_SetString(PyExc_TypeError, "Parameter 'keycode' must be an int or a long");
        if (PyErr_Occurred())
            return NULL;
    }
    if (py_mask) {
        if (PyLong_Check(py_mask))
            mask = PyLong_AsUnsignedLong(py_mask);
        else if (PyInt_Check(py_mask))
            mask = PyInt_AsLong(py_mask);
        else
            PyErr_SetString(PyExc_TypeError, "Parameter 'mask' must be an int or a long");
        if (PyErr_Occurred())
            return NULL;
    }
    
    ret = sugar_key_grabber_is_modifier(SUGAR_KEY_GRABBER(self->obj), keycode, mask);
    
    return PyBool_FromLong(ret);

}
Exemplo n.º 29
0
//-------------------------------------------------------------------------------------
PyObject* PyMemoryStream::__unpickle__(PyObject* self, PyObject* args)
{
	Py_ssize_t size = PyTuple_Size(args);
	if (size != 3)
	{
		ERROR_MSG("PyMemoryStream::__unpickle__: args is wrong! (size != 3)");
		S_Return;
	}

	PyObject* pyRpos = PyTuple_GET_ITEM(args, 0);
	PyObject* pyWpos = PyTuple_GET_ITEM(args, 1);

	PyObject* pybytes = PyTuple_GET_ITEM(args, 2);
	if (pybytes == NULL)
	{
		ERROR_MSG("PyMemoryStream::__unpickle__: args is wrong!");
		S_Return;
	}

	PyMemoryStream* pPyMemoryStream = new PyMemoryStream(pybytes);
	pPyMemoryStream->stream().rpos(PyLong_AsUnsignedLong(pyRpos));
	pPyMemoryStream->stream().wpos(PyLong_AsUnsignedLong(pyWpos));
	return pPyMemoryStream;
}
Exemplo n.º 30
0
//-------------------------------------------------------------------------------------
PyObject* Blob::__unpickle__(PyObject* self, PyObject* args)
{
	Py_ssize_t size = PyTuple_Size(args);
	if(size != 3)
	{
		ERROR_MSG("Blob::__unpickle__: args is error! size != 3");
		S_Return;
	}

	PyObject* pyRpos = PyTuple_GET_ITEM(args, 0);
	PyObject* pyWpos = PyTuple_GET_ITEM(args, 1);

	PyObject* pybytes = PyTuple_GET_ITEM(args, 2);
	if(pybytes == NULL)
	{
		ERROR_MSG("Blob::__unpickle__: args is error!");
		S_Return;
	}
	
	Blob* pBlob = new Blob(pybytes);
	pBlob->stream().rpos(PyLong_AsUnsignedLong(pyRpos));
	pBlob->stream().wpos(PyLong_AsUnsignedLong(pyWpos));
	return pBlob;
}