Skip to content

Commit

Permalink
first error pass to get python3 to build. Does not work yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaakapallo committed May 9, 2018
1 parent 38f3d28 commit f807ad6
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 96 deletions.
4 changes: 2 additions & 2 deletions build/gnumake-mac-gcc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

_LOCAL_FRAMEWORK := /Library/Frameworks/Python.framework/Versions/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)
_SYSTEM_FRAMEWORK := /System/Library/Frameworks/Python.framework/Versions/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)
_LOCAL_LIBRARY := /Library/Python/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)
_LOCAL_LIBRARY := /usr/local/lib/Python/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)
_SYSTEM_LIBRARY := /System/Library/Python/$(PY_MAJOR_VERSION).$(PY_MINOR_VERSION)

DEFS += -DPY_EXPORTS
#INCPATH += -F/Library/Frameworks -framework Python
#INCPATH += -F/Library/Frameworks

ifeq ($(PY_DEFAULT),1)
LIBS += $(_SYSTEM_FRAMEWORK)/Python
Expand Down
4 changes: 2 additions & 2 deletions source/bound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ PyObject *pyext::pyext_bind(PyObject *,PyObject *args)
PyObject *self,*meth,*name;
if(!PyArg_ParseTuple(args, "OOO:pyext_bind", &self,&name,&meth)) // borrowed references
post("py/pyext - Wrong arguments!");
else if(!PyInstance_Check(self) || !PyCallable_Check(meth)) {
else if(!PySequence_Check(self) || !PyCallable_Check(meth)) {
post("py/pyext - Wrong argument types!");
}
else {
Expand Down Expand Up @@ -131,7 +131,7 @@ PyObject *pyext::pyext_unbind(PyObject *,PyObject *args)
PyObject *self,*meth,*name;
if(!PyArg_ParseTuple(args, "OOO:pyext_bind", &self,&name,&meth)) // borrowed references
post("py/pyext - Wrong arguments!");
else if(!PyInstance_Check(self) || !PyCallable_Check(meth)) {
else if(!PySequence_Check(self) || !PyCallable_Check(meth)) {
post("py/pyext - Wrong argument types!");
}
else {
Expand Down
18 changes: 9 additions & 9 deletions source/clmeth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ PyObject* pyext::pyext__str__(PyObject *,PyObject *args)
return NULL;
}

return PyString_FromFormat("<pyext object %p>",self);
return PyUnicode_FromFormat("<pyext object %p>",self);
}

PyObject* pyext::pyext_setattr(PyObject *,PyObject *args)
Expand All @@ -108,7 +108,7 @@ PyObject* pyext::pyext_setattr(PyObject *,PyObject *args)
}
*/
if(!handled) {
if(PyInstance_Check(self))
if(PySequence_Check(self))

This comment has been minimized.

Copy link
@grrrr

grrrr May 10, 2018

Owner

Why is PyInstance_Check replaced by PySequence_Check?

This comment has been minimized.

Copy link
@Vaakapallo

Vaakapallo May 11, 2018

Author

That is what the compilation error check suggests:

error: use of undeclared identifier 'PyInstance_Check'; did you mean 'PySequence_Check'?

I went with the idea that the direct replacements would be correct.

PyDict_SetItem(((PyInstanceObject *)self)->in_dict, name,val);
else
ERRINTERNAL();
Expand All @@ -126,8 +126,8 @@ PyObject* pyext::pyext_getattr(PyObject *,PyObject *args)
ERRINTERNAL();
}

if(PyString_Check(name)) {
char* sname = PyString_AS_STRING(name);
if(PyMapping_Check(name)) {

This comment has been minimized.

Copy link
@grrrr

grrrr May 10, 2018

Owner

Why is PyString_Check replaced by PyMapping_Check? I would assume it should rather be PyUnicode_Check, no?

This comment has been minimized.

Copy link
@Vaakapallo

Vaakapallo May 11, 2018

Author

Ah, yes. Unicode_Check is definitely correct.

Same error replacement issue here:

source/clmeth.cpp:129:8: error: use of undeclared identifier 'PyString_Check'; did you mean 'PyMapping_Check'?

I guess I thought these suggestions would be based on API updates, not just similarities in name.

char* sname = PyUnicode_AsUTF8(name);
if(sname) {
#ifdef FLEXT_THREADS
if(!strcmp(sname,"_shouldexit")) {
Expand Down Expand Up @@ -158,7 +158,7 @@ PyObject* pyext::pyext_getattr(PyObject *,PyObject *args)
#if PY_VERSION_HEX >= 0x02020000
ret = PyObject_GenericGetAttr(self,name); // new reference (?)
#else
if(PyInstance_Check(self))
if(PySequence_Check(self))
// borrowed reference
ret = PyDict_GetItem(((PyInstanceObject *)self)->in_dict,name);
#endif
Expand All @@ -181,8 +181,8 @@ PyObject *pyext::pyext_outlet(PyObject *,PyObject *args)

if(
sz >= 2 &&
(self = PyTuple_GET_ITEM(args,0)) != NULL && PyInstance_Check(self) &&
(outl = PyTuple_GET_ITEM(args,1)) != NULL && PyInt_Check(outl)
(self = PyTuple_GET_ITEM(args,0)) != NULL && PySequence_Check(self) &&
(outl = PyTuple_GET_ITEM(args,1)) != NULL && PyLong_Check(outl)
) {
pyext *ext = GetThis(self);
if(!ext) {
Expand Down Expand Up @@ -211,7 +211,7 @@ PyObject *pyext::pyext_outlet(PyObject *,PyObject *args)
val = PyTuple_GetSlice(args,2,sz); // new ref
#endif

int o = PyInt_AS_LONG(outl);
int o = PyLong_AsLong(outl);
if(o >= 1 && o <= ext->Outlets()) {
// offset outlet by signal outlets
o += ext->sigoutlets;
Expand Down Expand Up @@ -312,7 +312,7 @@ PyObject *pyext::pyext_tocanvas(PyObject *,PyObject *args)
PyObject *self; // borrowed ref
if(
sz >= 1 &&
(self = PyTuple_GET_ITEM(args,0)) != NULL && PyInstance_Check(self)
(self = PyTuple_GET_ITEM(args,0)) != NULL && PySequence_Check(self)
) {
pyext *ext = GetThis(self);
if(!ext) {
Expand Down
4 changes: 2 additions & 2 deletions source/modmeth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ PyObject *pybase::py_searchpaths(PyObject *self,PyObject *args)
PyObject *ret = PyList_New(0);
char *dir;
for(int i = 0; (dir = namelist_get(sys_searchpath,i)) != NULL; ++i)
PyList_Append(ret,PyString_FromString(dir));
PyList_Append(ret,PyUnicode_FromString(dir));
return ret;
#else
Py_INCREF(Py_None);
Expand All @@ -131,7 +131,7 @@ PyObject *pybase::py_helppaths(PyObject *self,PyObject *args)
PyObject *ret = PyList_New(0);
char *dir;
for(int i = 0; (dir = namelist_get(sys_helppath,i)) != NULL; ++i)
PyList_Append(ret,PyString_FromString(dir));
PyList_Append(ret,PyUnicode_FromString(dir));
return ret;
#else
Py_INCREF(Py_None);
Expand Down
14 changes: 7 additions & 7 deletions source/pyargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ static PyObject *MakePyAtom(const t_atom &at)
// if a number can be an integer... let it be an integer!
int ival = flext::GetAInt(at);
double fval = flext::GetAFloat(at);
return (double)ival == fval?PyInt_FromLong(ival):PyFloat_FromDouble(fval);
return (double)ival == fval?PyLong_FromLong(ival):PyFloat_FromDouble(fval);
}
#else
else if(flext::IsFloat(at))
return PyFloat_FromDouble(flext::GetFloat(at));
else if(flext::IsInt(at))
return PyInt_FromLong(flext::GetInt(at));
return PyLong_FromLong(flext::GetInt(at));
#endif
return NULL;
}
Expand Down Expand Up @@ -69,7 +69,7 @@ PyObject *pybase::MakePyArgs(const t_symbol *s,int argc,const t_atom *argv,int i
int pix = 0;

if(inlet >= 0)
PyTuple_SET_ITEM(ret,pix++,PyInt_FromLong(inlet));
PyTuple_SET_ITEM(ret,pix++,PyLong_FromLong(inlet));

if(any)
PyTuple_SET_ITEM(ret,pix++,pySymbol_FromSymbol(s));
Expand Down Expand Up @@ -126,7 +126,7 @@ PyObject *pybase::MakePyArg(const t_symbol *s,int argc,const t_atom *argv)

inline bool issym(PyObject *p)
{
return PyString_Check(p) || pySymbol_Check(p);
return PyMapping_Check(p) || pySymbol_Check(p);
}

inline bool isseq(PyObject *p)
Expand All @@ -136,16 +136,16 @@ inline bool isseq(PyObject *p)

const t_symbol *pybase::getone(t_atom &at,PyObject *arg)
{
if(PyInt_Check(arg)) { flext::SetInt(at,PyInt_AsLong(arg)); return sym_fint; }
if(PyLong_Check(arg)) { flext::SetInt(at,PyLong_AsLong(arg)); return sym_fint; }
else if(PyLong_Check(arg)) { flext::SetInt(at,PyLong_AsLong(arg)); return sym_fint; }
else if(PyFloat_Check(arg)) { flext::SetFloat(at,(float)PyFloat_AsDouble(arg)); return flext::sym_float; }
else if(pySymbol_Check(arg)) { flext::SetSymbol(at,pySymbol_AS_SYMBOL(arg)); return flext::sym_symbol; }
else if(PyString_Check(arg)) { flext::SetString(at,PyString_AS_STRING(arg)); return flext::sym_symbol; }
else if(PyMapping_Check(arg)) { flext::SetString(at,PyUnicode_AsUTF8(arg)); return flext::sym_symbol; }
else {
PyObject *tp = PyObject_Type(arg);
PyObject *stp = tp?PyObject_Str(tp):NULL;
const char *tmp = "";
if(stp) tmp = PyString_AS_STRING(stp);
if(stp) tmp = PyUnicode_AsUTF8(stp);
flext::post("py/pyext: Could not convert argument %s",tmp);
Py_XDECREF(stp);
Py_XDECREF(tp);
Expand Down
75 changes: 58 additions & 17 deletions source/pybase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ void initsymbol();
void initsamplebuffer();
void initbundle();




void pybase::lib_setup()
{
post("");
Expand Down Expand Up @@ -150,20 +153,56 @@ void pybase::lib_setup()
#endif

// sys.argv must be set to empty tuple
const char *nothing = "";
PySys_SetArgv(0,const_cast<char **>(&nothing));

//const char *nothing = "";
// TEST, though deprecated
wchar_t* nothing = L"";
PySys_SetArgv(0,const_cast<wchar_t **>(&nothing));

// TESTING DIFFERENT INITIALIZATION FOR MODULES
static struct PyModuleDef pyExtMod =
{
PyModuleDef_HEAD_INIT,
PYEXT_MODULE, /* name of module */
"", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
func_tbl
};

static struct PyModuleDef pyExtStdOutMod =
{
PyModuleDef_HEAD_INIT,
"stdout", /* name of module */
"", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
StdOut_Methods
};

static struct PyModuleDef pyExtStdErrMod =
{
PyModuleDef_HEAD_INIT,
"stderr", /* name of module */
"", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
StdOut_Methods
};

//PyMODINIT_FUNC PyInit_pyExtMod(void)
//{
// return PyModule_Create(&pyExtMod);
//}


// register/initialize pyext module only once!
module_obj = Py_InitModule(const_cast<char *>(PYEXT_MODULE), func_tbl);
module_obj = PyModule_Create(&pyExtMod);
module_dict = PyModule_GetDict(module_obj); // borrowed reference

PyModule_AddStringConstant(module_obj,"__doc__",(char *)py_doc);

// redirect stdout
PyObject* py_out;
py_out = Py_InitModule(const_cast<char *>("stdout"), StdOut_Methods);
py_out = PyModule_Create(&pyExtStdOutMod);
PySys_SetObject(const_cast<char *>("stdout"), py_out);
py_out = Py_InitModule(const_cast<char *>("stderr"), StdOut_Methods);
py_out = PyModule_Create(&pyExtStdErrMod);
PySys_SetObject(const_cast<char *>("stderr"), py_out);

// get garbage collector function
Expand Down Expand Up @@ -310,10 +349,10 @@ void pybase::m__doc(PyObject *obj)
ThrLock lock;

PyObject *docf = PyDict_GetItemString(obj,"__doc__"); // borrowed!!!
if(docf && PyString_Check(docf)) {
if(docf && PyMapping_Check(docf)) {

post("");
const char *s = PyString_AS_STRING(docf);
const char *s = PyUnicode_AsUTF8(docf);

// FIX: Python doc strings can easily be larger than 1k characters
// -> split into separate lines
Expand Down Expand Up @@ -431,7 +470,9 @@ void pybase::SetArgs()
}

// the arguments to the module are only recognized once! (at first use in a patcher)
PySys_SetArgv(argc+1,sargv);

// NEEDS UPDATING
//PySys_SetArgv(argc+1,sargv);

for(int j = 0; j <= argc; ++j) delete[] sargv[j];
delete[] sargv;
Expand Down Expand Up @@ -650,7 +691,7 @@ void pybase::AddToPath(const char *dir)
if(dir && *dir) {
PyObject *pobj = PySys_GetObject(const_cast<char *>("path"));
if(pobj && PyList_Check(pobj)) {
PyObject *ps = PyString_FromString(dir);
PyObject *ps = PyUnicode_FromString(dir);
if(!PySequence_Contains(pobj,ps))
PyList_Append(pobj,ps); // makes new reference
Py_DECREF(ps);
Expand Down Expand Up @@ -745,30 +786,30 @@ PyObject* pybase::StdOut_Write(PyObject* self, PyObject* args)
for(int i = 0; i < sz; ++i) {
PyObject *val = PyTuple_GET_ITEM(args,i); // borrowed reference
PyObject *str = PyObject_Str(val); // new reference
char *cstr = PyString_AS_STRING(str);
char *cstr = PyUnicode_AsUTF8(str);
char *lf = strchr(cstr,'\n');

// line feed in string
if(!lf) {
// no -> just append
if(output)
PyString_ConcatAndDel(&output,str); // str is decrefd
PyBytes_ConcatAndDel(&output,str); // str is decrefd
else
output = str; // take str reference
}
else {
// yes -> append up to line feed, reset output buffer to string remainder
PyObject *part = PyString_FromStringAndSize(cstr,lf-cstr); // new reference
PyObject *part = PyUnicode_FromStringAndSize(cstr,lf-cstr); // new reference
if(output)
PyString_ConcatAndDel(&output,part); // str is decrefd
PyBytes_ConcatAndDel(&output,part); // str is decrefd
else
output = part; // take str reference

// output concatenated string
post(PyString_AS_STRING(output));
post(PyUnicode_AsUTF8(output));

Py_DECREF(output);
output = PyString_FromString(lf+1); // new reference
output = PyUnicode_FromString(lf+1); // new reference
}
}

Expand Down Expand Up @@ -928,7 +969,7 @@ bool pybase::collect()
PyObject *ret = PyObject_CallObject(gcollect,NULL);
if(ret) {
#ifdef FLEXT_DEBUG
int refs = PyInt_AsLong(ret);
int refs = PyLong_AsLong(ret);
if(refs) post("py/pyext - Garbage collector reports %i unreachable objects",refs);
#endif
Py_DECREF(ret);
Expand Down
Loading

0 comments on commit f807ad6

Please sign in to comment.