Exemple #1
0
PyMODINIT_FUNC
PyInit__lsprof(void)
{
    PyObject *module, *d;
    module = PyModule_Create(&_lsprofmodule);
    if (module == NULL)
        return NULL;
    d = PyModule_GetDict(module);
    if (PyType_Ready(&PyProfiler_Type) < 0)
        return NULL;
    PyDict_SetItemString(d, "Profiler", (PyObject *)&PyProfiler_Type);

    if (!initialized) {
        if (PyStructSequence_InitType2(&StatsEntryType,
                                       &profiler_entry_desc) < 0)
            return NULL;
        if (PyStructSequence_InitType2(&StatsSubEntryType,
                                       &profiler_subentry_desc) < 0)
            return NULL;
    }
    Py_INCREF((PyObject*) &StatsEntryType);
    Py_INCREF((PyObject*) &StatsSubEntryType);
    PyModule_AddObject(module, "profiler_entry",
                       (PyObject*) &StatsEntryType);
    PyModule_AddObject(module, "profiler_subentry",
                       (PyObject*) &StatsSubEntryType);
    empty_tuple = PyTuple_New(0);
    initialized = 1;
    return module;
}
Exemple #2
0
PyObject *term_to_nametuple(const char *s, int arity, term_t t) {
  PyObject *o;
#if PY_MAJOR_VERSION >= 3
  PyTypeObject *typp;
  PyObject *key = PyUnicode_FromString(s);
  if (py_F2P && PyDict_Contains(py_F2P, key)) {
    typp = (PyTypeObject *)PyDict_GetItem(py_F2P, key);
  } else {

    typp = PyMem_Malloc(sizeof(PyTypeObject));
    PyStructSequence_Desc *desc = PyMem_Malloc(sizeof(PyStructSequence_Desc));

    desc->name = PyUnicode_AsUTF8(key);
    desc->doc = "YAPTerm";
    desc->fields = pnull;
    desc->n_in_sequence = 32;
    if (PyStructSequence_InitType2(typp, desc) < 0)
      return NULL;
    typp->tp_str = structseq_str;
    typp->tp_repr = structseq_repr;
    //     typp = PyStructSequence_NewType(desc);
    Py_INCREF(typp);
    //	typp->tp_flags |= Py_TPFLAGS_HEAPTYPE;
    PyModule_AddObject(py_Yapex, s, (PyObject *)typp);
    if (py_F2P)
      PyDict_SetItem(py_F2P, key, (PyObject *)typp);
  }
  o = PyTuple_New(typp);
#else
  o = PyTuple_New(arity);
#endif
  term_t tleft = PL_new_term_ref();
  int i;

  for (i = 0; i < arity; i++) {
    PyObject *pArg;
    if (!PL_get_arg(i + 1, t, tleft))
      return NULL;
    pArg = term_to_python(tleft, false);
    if (pArg == NULL)
      return NULL;
#if PY_MAJOR_VERSION >= 3
    /* pArg reference stolen here: */
    PyStructSequence_SET_ITEM(o, i, pArg);
  }
  ((PyStructSequence *)o)->ob_base.ob_size = arity;
  return o;
#else
    /* pArg reference stolen here: */
    PyTuple_SET_ITEM(o, i, pArg);
  }
Exemple #3
0
PyMODINIT_FUNC
PyInit_spwd(void)
{
    PyObject *m;
    m=PyModule_Create(&spwdmodule);
    if (m == NULL)
        return NULL;
    if (!initialized) {
        if (PyStructSequence_InitType2(&StructSpwdType,
                                       &struct_spwd_type_desc) < 0)
            return NULL;
    }
    Py_INCREF((PyObject *) &StructSpwdType);
    PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType);
    initialized = 1;
    return m;
}
Exemple #4
0
PyMODINIT_FUNC
PyInit_btrfsutil(void)
{
	PyObject *m;

	BtrfsUtilError_type.tp_base = (PyTypeObject *)PyExc_OSError;
	if (PyType_Ready(&BtrfsUtilError_type) < 0)
		return NULL;

	if (PyStructSequence_InitType2(&SubvolumeInfo_type, &SubvolumeInfo_desc) < 0)
		return NULL;

	SubvolumeIterator_type.tp_new = PyType_GenericNew;
	if (PyType_Ready(&SubvolumeIterator_type) < 0)
		return NULL;

	QgroupInherit_type.tp_new = PyType_GenericNew;
	if (PyType_Ready(&QgroupInherit_type) < 0)
		return NULL;

	m = PyModule_Create(&btrfsutilmodule);
	if (!m)
		return NULL;

	Py_INCREF(&BtrfsUtilError_type);
	PyModule_AddObject(m, "BtrfsUtilError",
			   (PyObject *)&BtrfsUtilError_type);

	Py_INCREF(&SubvolumeInfo_type);
	PyModule_AddObject(m, "SubvolumeInfo", (PyObject *)&SubvolumeInfo_type);

	Py_INCREF(&SubvolumeIterator_type);
	PyModule_AddObject(m, "SubvolumeIterator",
			   (PyObject *)&SubvolumeIterator_type);

	Py_INCREF(&QgroupInherit_type);
	PyModule_AddObject(m, "QgroupInherit",
			   (PyObject *)&QgroupInherit_type);

	add_module_constants(m);

	return m;
}
Exemple #5
0
int imapparser_add_parser_types(PyObject *m)
{
	if (PyStructSequence_InitType2(&AddressType, &address_desc) < 0)
		return -1;
	Py_INCREF(&AddressType);
	PyModule_AddObject(m, "Address", (PyObject *)&AddressType);

	if (PyStructSequence_InitType2(&TextBodyType, &text_body_desc) < 0)
		return -1;
	Py_INCREF(&TextBodyType);
	PyModule_AddObject(m, "TextBody", (PyObject *)&TextBodyType);

	if (PyStructSequence_InitType2(&MessageBodyType, &message_body_desc) < 0)
		return -1;
	Py_INCREF(&MessageBodyType);
	PyModule_AddObject(m, "MessageBody", (PyObject *)&MessageBodyType);

	if (PyStructSequence_InitType2(&BasicBodyType, &basic_body_desc) < 0)
		return -1;
	Py_INCREF(&BasicBodyType);
	PyModule_AddObject(m, "BasicBody", (PyObject *)&BasicBodyType);

	if (PyStructSequence_InitType2(&MultipartBodyType, &multipart_body_desc) < 0)
		return -1;
	Py_INCREF(&MultipartBodyType);
	PyModule_AddObject(m, "MultipartBody", (PyObject *)&MultipartBodyType);

	if (PyStructSequence_InitType2(&ContinueReqType,
				       &continue_req_desc) < 0)
		return -1;
	Py_INCREF(&ContinueReqType);
	PyModule_AddObject(m, "ContinueReq", (PyObject *)&ContinueReqType);

	if (PyStructSequence_InitType2(&EnvelopeType, &envelope_desc) < 0)
		return -1;
	Py_INCREF(&EnvelopeType);
	PyModule_AddObject(m, "Envelope", (PyObject *)&EnvelopeType);

	if (PyStructSequence_InitType2(&EsearchType, &esearch_desc) < 0)
		return -1;
	Py_INCREF(&EsearchType);
	PyModule_AddObject(m, "Esearch", (PyObject *)&EsearchType);

	if (PyStructSequence_InitType2(&FetchType, &fetch_desc) < 0)
		return -1;
	Py_INCREF(&FetchType);
	PyModule_AddObject(m, "Fetch", (PyObject *)&FetchType);

	if (PyStructSequence_InitType2(&ListType, &list_desc) < 0)
		return -1;
	Py_INCREF(&ListType);
	PyModule_AddObject(m, "List", (PyObject *)&ListType);

	if (PyStructSequence_InitType2(&ResponseTextType,
				       &response_text_desc) < 0)
		return -1;
	Py_INCREF(&ResponseTextType);
	PyModule_AddObject(m, "ResponseText", (PyObject *)&ResponseTextType);

	if (PyStructSequence_InitType2(&StatusType, &status_desc) < 0)
		return -1;
	Py_INCREF(&StatusType);
	PyModule_AddObject(m, "Status", (PyObject *)&StatusType);

	if (PyStructSequence_InitType2(&TaggedResponseType,
				       &tagged_response_desc) < 0)
		return -1;
	Py_INCREF(&TaggedResponseType);
	PyModule_AddObject(m, "TaggedResponse", (PyObject *)&TaggedResponseType);

	if (PyStructSequence_InitType2(&UntaggedResponseType,
				       &untagged_response_desc) < 0)
		return -1;
	Py_INCREF(&UntaggedResponseType);
	PyModule_AddObject(m, "UntaggedResponse", (PyObject *)&UntaggedResponseType);

	return 0;
}
Exemple #6
0
PyObject*
PyThread_GetInfo(void)
{
    PyObject *threadinfo, *value;
    int pos = 0;
#if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \
     && defined(_CS_GNU_LIBPTHREAD_VERSION))
    char buffer[255];
    int len;
#endif

    if (ThreadInfoType.tp_name == 0) {
        if (PyStructSequence_InitType2(&ThreadInfoType, &threadinfo_desc) < 0)
            return NULL;
    }

    threadinfo = PyStructSequence_New(&ThreadInfoType);
    if (threadinfo == NULL)
        return NULL;

    value = PyUnicode_FromString(PYTHREAD_NAME);
    if (value == NULL) {
        Py_DECREF(threadinfo);
        return NULL;
    }
    PyStructSequence_SET_ITEM(threadinfo, pos++, value);

#ifdef _POSIX_THREADS
#ifdef USE_SEMAPHORES
    value = PyUnicode_FromString("semaphore");
#else
    value = PyUnicode_FromString("mutex+cond");
#endif
    if (value == NULL) {
        Py_DECREF(threadinfo);
        return NULL;
    }
#else
    Py_INCREF(Py_None);
    value = Py_None;
#endif
    PyStructSequence_SET_ITEM(threadinfo, pos++, value);

#if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \
     && defined(_CS_GNU_LIBPTHREAD_VERSION))
    value = NULL;
    len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
    if (1 < len && len < sizeof(buffer)) {
        value = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1);
        if (value == NULL)
            PyErr_Clear();
    }
    if (value == NULL)
#endif
    {
        Py_INCREF(Py_None);
        value = Py_None;
    }
    PyStructSequence_SET_ITEM(threadinfo, pos++, value);
    return threadinfo;
}