mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
*** empty log message ***
This commit is contained in:
parent
05b6a301d5
commit
a31108fcb8
@ -1414,11 +1414,14 @@ void InterfaceMakerPythonNative::write_module_class(ostream &out, Object *obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compare and hash work together in PY inherit behavior hmm grrr
|
||||||
// __hash__
|
// __hash__
|
||||||
if(has_local_hash == true)
|
if(has_local_hash == true)
|
||||||
{
|
{
|
||||||
out << " // __hash__\n";
|
out << " // __hash__\n";
|
||||||
out << " Dtool_" << ClassName <<".As_PyTypeObject().tp_hash = &DTool_HashKey_"<<ClassName <<";\n";
|
out << " Dtool_" << ClassName <<".As_PyTypeObject().tp_hash = &DTool_HashKey_"<<ClassName <<";\n";
|
||||||
|
out << " Dtool_" << ClassName <<".As_PyTypeObject().tp_compare = &DTOOL_PyObject_Compare;\n";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1987,6 +1990,18 @@ void InterfaceMakerPythonNative::write_function_instance(ostream &out, Interface
|
|||||||
expected_params += "long long";
|
expected_params += "long long";
|
||||||
pname_for_pyobject += param_name;
|
pname_for_pyobject += param_name;
|
||||||
|
|
||||||
|
}else if(TypeManager::is_unsigned_integer(type))
|
||||||
|
{
|
||||||
|
indent(out,indent_level+4) << "PyObject *" << param_name;
|
||||||
|
format_specifiers += "O";
|
||||||
|
parameter_list += ", &" + param_name;
|
||||||
|
extra_convert += " PyObject *" + param_name + "_uint = PyNumber_Long(" + param_name + ");";
|
||||||
|
extra_param_check += "|| (" + param_name + "_uint == NULL)";
|
||||||
|
pexpr_string = "PyLong_AsUnsignedLong(" + param_name + "_uint)";
|
||||||
|
extra_cleanup += " Py_XDECREF(" + param_name + "_uint);";
|
||||||
|
expected_params += "unsigned int";
|
||||||
|
pname_for_pyobject += param_name;
|
||||||
|
|
||||||
}else if (TypeManager::is_integer(type)) {
|
}else if (TypeManager::is_integer(type)) {
|
||||||
indent(out,indent_level+4) << "int " << param_name;
|
indent(out,indent_level+4) << "int " << param_name;
|
||||||
format_specifiers += "i";
|
format_specifiers += "i";
|
||||||
|
@ -194,7 +194,7 @@ EXPORT_THIS Dtool_PyTypedObject Dtool_##CLASS_NAME = {\
|
|||||||
0, /*tp_print*/\
|
0, /*tp_print*/\
|
||||||
0, /*tp_getattr*/\
|
0, /*tp_getattr*/\
|
||||||
0, /*tp_setattr*/\
|
0, /*tp_setattr*/\
|
||||||
&DTOOL_PyObject_Compare, /*tp_compare*/\
|
0, /*tp_compare*/\
|
||||||
0, /*tp_repr*/\
|
0, /*tp_repr*/\
|
||||||
&Dtool_PyNumberMethods_##CLASS_NAME, /*tp_as_number*/\
|
&Dtool_PyNumberMethods_##CLASS_NAME, /*tp_as_number*/\
|
||||||
0, /*tp_as_sequence*/\
|
0, /*tp_as_sequence*/\
|
||||||
@ -205,7 +205,7 @@ EXPORT_THIS Dtool_PyTypedObject Dtool_##CLASS_NAME = {\
|
|||||||
PyObject_GenericGetAttr, /* tp_getattro */\
|
PyObject_GenericGetAttr, /* tp_getattro */\
|
||||||
PyObject_GenericSetAttr, /* tp_setattro */\
|
PyObject_GenericSetAttr, /* tp_setattro */\
|
||||||
0, /* tp_as_buffer */\
|
0, /* tp_as_buffer */\
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES, /* tp_flags */\
|
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES), /* tp_flags */\
|
||||||
0, /* tp_doc */\
|
0, /* tp_doc */\
|
||||||
0, /* tp_traverse */\
|
0, /* tp_traverse */\
|
||||||
0, /* tp_clear */\
|
0, /* tp_clear */\
|
||||||
@ -699,7 +699,7 @@ inline long DTool_HashKey(PyObject * inst)
|
|||||||
XXX of error.
|
XXX of error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline int DTOOL_PyObject_Compare(PyObject *v1, PyObject *v2)
|
inline int DTOOL_PyObject_Compare_old(PyObject *v1, PyObject *v2)
|
||||||
{
|
{
|
||||||
// if we are related..
|
// if we are related..
|
||||||
if(PyType_IsSubtype(v1->ob_type, v2->ob_type))
|
if(PyType_IsSubtype(v1->ob_type, v2->ob_type))
|
||||||
@ -753,5 +753,58 @@ inline int DTOOL_PyObject_Compare(PyObject *v1, PyObject *v2)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline int DTOOL_PyObject_Compare(PyObject *v1, PyObject *v2)
|
||||||
|
{
|
||||||
|
// First try compare to function..
|
||||||
|
PyObject * func = PyObject_GetAttrString(v1, "compareTo");
|
||||||
|
if (func == NULL)
|
||||||
|
{
|
||||||
|
PyErr_Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PyObject * res = NULL;
|
||||||
|
PyObject * args = Py_BuildValue("(O)", v2);
|
||||||
|
if (args != NULL)
|
||||||
|
{
|
||||||
|
res = PyObject_Call(func, args, NULL);
|
||||||
|
Py_DECREF(args);
|
||||||
|
}
|
||||||
|
Py_DECREF(func);
|
||||||
|
PyErr_Clear(); // just in case the function threw an error
|
||||||
|
// only use if the cuntion return an INT... hmm
|
||||||
|
if(res != NULL && PyInt_Check(res))
|
||||||
|
{
|
||||||
|
int answer = PyInt_AsLong(res);
|
||||||
|
Py_DECREF(res);
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
if(res != NULL)
|
||||||
|
Py_DECREF(res);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// try this compare
|
||||||
|
void * v1_this = DTOOL_Call_GetPointerThis(v1);
|
||||||
|
void * v2_this = DTOOL_Call_GetPointerThis(v2);
|
||||||
|
if(v1_this != NULL && v2_this != NULL) // both are our types...
|
||||||
|
{
|
||||||
|
if(v1_this < v2_this)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if(v1_this > v2_this)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ok self compare...
|
||||||
|
if(v1 < v2)
|
||||||
|
return -1;
|
||||||
|
if(v1 > v2)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PY_PANDA_H_
|
#endif // PY_PANDA_H_
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user