ported python c extention to python 3
This commit is contained in:
parent
b30c989858
commit
d4d7fdf761
@ -10,6 +10,9 @@
|
|||||||
*
|
*
|
||||||
* History:
|
* History:
|
||||||
*
|
*
|
||||||
|
* 2024-09-08 Fredrick W. Warren
|
||||||
|
* Ported from python 2 to python 3
|
||||||
|
*
|
||||||
* 2003-06-24 Kristoffer Erlandsson
|
* 2003-06-24 Kristoffer Erlandsson
|
||||||
* Added some additional event handling.
|
* Added some additional event handling.
|
||||||
*
|
*
|
||||||
@ -29,10 +32,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include "structmember.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#define PY_SSIZE_T_CLEAN
|
||||||
|
#include <Python.h>
|
||||||
|
#include "structmember.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -83,11 +87,12 @@ char **pyListToStrs(PyObject *l) {
|
|||||||
s = PySequence_GetItem(l, i);
|
s = PySequence_GetItem(l, i);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return NULL; /* Shouldn't happen. */
|
return NULL; /* Shouldn't happen. */
|
||||||
if (!PyString_Check(s)) {
|
if (!PyUnicode_Check(s)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "String expected.");
|
PyErr_SetString(PyExc_TypeError, "String expected.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
target[i] = PyString_AsString(s);
|
// target[i] = strdup(PyUnicode_AsString(s));
|
||||||
|
target[i] = strdup(PyUnicode_AsUTF8(s));
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@ -363,8 +368,7 @@ static PyMethodDef Drawable_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static PyTypeObject drawable_DrawableType = {
|
static PyTypeObject drawable_DrawableType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
0, /*ob_size*/
|
|
||||||
"pyywmgeneral.Drawable", /*tp_name*/
|
"pyywmgeneral.Drawable", /*tp_name*/
|
||||||
sizeof(drawable_DrawableObject), /*tp_basicsize*/
|
sizeof(drawable_DrawableObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -787,23 +791,29 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
|
static struct PyModuleDef pywmgeneral_module = {
|
||||||
#define PyMODINIT_FUNC void
|
PyModuleDef_HEAD_INIT, /* m_base */
|
||||||
#endif
|
"pywmgeneral", /* m_name */
|
||||||
|
NULL, /* m_doc */
|
||||||
|
-1, /* m_size */
|
||||||
|
PyWmgeneralMethods /* m_methods */
|
||||||
|
};
|
||||||
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
initpywmgeneral(void) {
|
PyInit_pywmgeneral(void)
|
||||||
|
{
|
||||||
PyObject* m;
|
PyObject* m;
|
||||||
|
|
||||||
drawable_DrawableType.tp_new = PyType_GenericNew;
|
drawable_DrawableType.tp_new = PyType_GenericNew;
|
||||||
if (PyType_Ready(&drawable_DrawableType) < 0)
|
if (PyType_Ready(&drawable_DrawableType) < 0)
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
m = Py_InitModule3("pywmgeneral", PyWmgeneralMethods,
|
m = PyModule_Create(&pywmgeneral_module);
|
||||||
"base C module for wmdocklib");
|
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
Py_INCREF(&drawable_DrawableType);
|
Py_INCREF(&drawable_DrawableType);
|
||||||
PyModule_AddObject(m, "Drawable", (PyObject *)&drawable_DrawableType);
|
PyModule_AddObject(m, "Drawable", (PyObject *)&drawable_DrawableType);
|
||||||
|
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user