@@ -53,7 +53,7 @@ static PyObject *t_atom_to_PyObject( t_atom *atom )
5353
5454 case A_SYMBOL :
5555 // symbols are returned as strings
56- return PyString_FromString ( atom -> a_w .w_symbol -> s_name );
56+ return PyUnicode_FromString ( atom -> a_w .w_symbol -> s_name );
5757
5858 case A_NULL :
5959 Py_RETURN_NONE ;
@@ -96,8 +96,7 @@ static void PyObject_to_atom( PyObject *value, t_atom *atom )
9696 else if (value == Py_False ) SETFLOAT ( atom , 0.0 );
9797 else if ( PyFloat_Check (value )) SETFLOAT ( atom , (float ) PyFloat_AsDouble ( value ));
9898 else if ( PyLong_Check (value )) SETFLOAT ( atom , (float ) PyLong_AsLong ( value ));
99- else if ( PyInt_Check (value )) SETFLOAT ( atom , (float ) PyLong_AsLong ( value ));
100- else if ( PyString_Check (value )) SETSYMBOL ( atom , gensym ( PyString_AsString (value ) ));
99+ else if ( PyUnicode_Check (value )) SETSYMBOL ( atom , gensym ( PyUnicode_AsUTF8 (value ) ));
101100 else SETSYMBOL ( atom , gensym ("error" ));
102101}
103102/****************************************************************/
@@ -132,8 +131,7 @@ static void emit_outlet_message( PyObject *value, t_outlet *x_outlet )
132131 // scalar numbers of various types come out as float
133132 else if ( PyFloat_Check (value )) outlet_float ( x_outlet , (float ) PyFloat_AsDouble ( value ));
134133 else if ( PyLong_Check (value )) outlet_float ( x_outlet , (float ) PyLong_AsLong ( value ));
135- else if ( PyInt_Check (value )) outlet_float ( x_outlet , (float ) PyLong_AsLong ( value ));
136- else if ( PyString_Check (value )) outlet_symbol ( x_outlet , gensym ( PyString_AsString (value ) ));
134+ else if ( PyUnicode_Check (value )) outlet_symbol ( x_outlet , gensym ( PyUnicode_AsUTF8 (value ) ));
137135
138136 else if ( PyList_Check (value ) ) {
139137 // Create an atom array representing a 1D Python list.
@@ -251,7 +249,7 @@ static void *pdpython_new(t_symbol *selector, int argcount, t_atom *argvec)
251249 // present. This will help the module import to find Python modules
252250 // located in the same folder as the patch.
253251 t_symbol * canvas_path = canvas_getcurrentdir ();
254- PyObject * modulePath = PyString_FromString ( canvas_path -> s_name );
252+ PyObject * modulePath = PyUnicode_FromString ( canvas_path -> s_name );
255253 PyObject * sysPath = PySys_GetObject ( (char * ) "path" ); // borrowed reference
256254
257255 if ( !PySequence_Contains ( sysPath , modulePath )) {
@@ -332,6 +330,19 @@ static PyMethodDef pdgui_methods[] = {
332330 { NULL , NULL , 0 , NULL }
333331};
334332
333+ static struct PyModuleDef pdguimodule = {
334+ PyModuleDef_HEAD_INIT ,
335+ "pdgui" , /* name of module */
336+ NULL , /* module documentation, may be NULL */
337+ -1 , /* size of per-interpreter state of the module,
338+ or -1 if the module keeps state in global variables. */
339+ pdgui_methods };
340+
341+ PyMODINIT_FUNC
342+ PyInit_pdgui (void )
343+ {
344+ return PyModule_Create (& pdguimodule );
345+ }
335346/****************************************************************/
336347/// Initialization entry point for the Pd 'python' external. This is
337348/// automatically called by Pd after loading the dynamic module to initialize
@@ -352,18 +363,39 @@ void python_setup(void)
352363 // inlet-callback function.
353364 class_addanything ( pdpython_class , (t_method ) pdpython_eval ); // (t_class *c, t_method fn)
354365
366+ wchar_t * program ;
367+ program = Py_DecodeLocale ("py" , NULL );
368+ if (program == NULL ) {
369+ exit (1 );
370+ }
371+
372+ Py_SetProgramName (program );
373+
355374 // static initialization follows
356- Py_SetProgramName ("pd" );
375+ // Py_SetProgramName("pd");
357376 Py_Initialize ();
358377
359- // Make sure that sys.argv is defined.
360- static char * arg0 = NULL ;
378+ // Make sure that sys.argv is defined.
379+ // static char *arg0 = NULL;
380+ static wchar_t * arg0 = NULL ;
361381 PySys_SetArgv ( 0 , & arg0 );
362382
363383 // make the internal pdgui wrapper module available for Python->C callbacks
364- if (Py_InitModule ("pdgui" , pdgui_methods ) == NULL ) {
384+
385+ if (PyInit_pdgui () == NULL )
386+ {
365387 post ("Error: unable to create the pdgui module." );
366- }
388+ }
389+
390+ // if (Py_InitModule("pdgui", pdgui_methods ) == NULL) {
391+ // post("Error: unable to create the pdgui module.");
392+ // }
367393}
394+
395+ // PyMODINIT_FUNC
396+ // PyInit_pdgui(void)
397+ // {
398+ // return PyModule_Create(&pdguimodule);
399+ // }
368400/****************************************************************/
369401
0 commit comments