ported python c extention to python 3

This commit is contained in:
Fredrick W. Warren 2024-09-09 01:20:02 -06:00
parent b30c989858
commit d4d7fdf761

View File

@ -10,6 +10,9 @@
*
* History:
*
* 2024-09-08 Fredrick W. Warren
* Ported from python 2 to python 3
*
* 2003-06-24 Kristoffer Erlandsson
* Added some additional event handling.
*
@ -29,10 +32,11 @@
*
*/
#include <Python.h>
#include "structmember.h"
#include <stdlib.h>
#include <stdio.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "structmember.h"
#include <string.h>
#include <unistd.h>
#include <ctype.h>
@ -83,11 +87,12 @@ char **pyListToStrs(PyObject *l) {
s = PySequence_GetItem(l, i);
if (s == NULL)
return NULL; /* Shouldn't happen. */
if (!PyString_Check(s)) {
if (!PyUnicode_Check(s)) {
PyErr_SetString(PyExc_TypeError, "String expected.");
return NULL;
}
target[i] = PyString_AsString(s);
// target[i] = strdup(PyUnicode_AsString(s));
target[i] = strdup(PyUnicode_AsUTF8(s));
}
return target;
}
@ -363,8 +368,7 @@ static PyMethodDef Drawable_methods[] = {
};
static PyTypeObject drawable_DrawableType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
PyVarObject_HEAD_INIT(NULL, 0)
"pyywmgeneral.Drawable", /*tp_name*/
sizeof(drawable_DrawableObject), /*tp_basicsize*/
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 */
#define PyMODINIT_FUNC void
#endif
static struct PyModuleDef pywmgeneral_module = {
PyModuleDef_HEAD_INIT, /* m_base */
"pywmgeneral", /* m_name */
NULL, /* m_doc */
-1, /* m_size */
PyWmgeneralMethods /* m_methods */
};
PyMODINIT_FUNC
initpywmgeneral(void) {
PyInit_pywmgeneral(void)
{
PyObject* m;
drawable_DrawableType.tp_new = PyType_GenericNew;
if (PyType_Ready(&drawable_DrawableType) < 0)
return;
return NULL;
m = Py_InitModule3("pywmgeneral", PyWmgeneralMethods,
"base C module for wmdocklib");
m = PyModule_Create(&pywmgeneral_module);
if (m == NULL)
return;
return NULL;
Py_INCREF(&drawable_DrawableType);
PyModule_AddObject(m, "Drawable", (PyObject *)&drawable_DrawableType);
return m;
}