Hi All,
I found some issues in pyglue.cc
Correct me if I am wrong.
Thanks.
First,
For nw_src type it should use htonl instead of htons.
@@ -184,7 +185,7 @@
PyObject* nw_src = PyDict_GetItemString(pymatch, "nw_src");
if (nw_src) {
- match.nw_src = htons(from_python<uint32_t>(nw_src));
+ match.nw_src = htonl(from_python<uint32_t>(nw_src));
@@ -201,7 +202,7 @@
PyObject* nw_dst = PyDict_GetItemString(pymatch, "nw_dst");
if (nw_dst) {
- match.nw_dst = htons(from_python<uint32_t>(nw_dst));
+ match.nw_dst = htonl(from_python<uint32_t>(nw_dst));
Second,
For unsigned int type, the maximum value passed to long_from_python will become
-1 instead of 4294967295 because of the long int maximum.
My intuitive solution is to extend the long int to long long int type.
Third,
PyInt_AsLong(obj) can't handle unsigned int value which over 2147483647.
PyInt_AsLong(obj) will return -1 and print "OverflowError: ..."
Then I change PyInt_AsLong(obj) to PyInt_AsUnsignedLongMask(obj).
/* Convert 'obj' into a long int, clamp the value between 'maximum' and
* 'minimum', reporting any error, and return the final value. */
-static inline long int
+static inline long long int
long_from_python(PyObject* obj, const char *type_name,
- long int minimum, long int maximum)
+ long long int minimum, long long int maximum)
{
- long int value = PyInt_AsLong(obj);
+ long long int value = PyInt_AsUnsignedLongMask(obj);
if (value == -1 && PyErr_Occurred()) {
PyErr_Print();
} else if (value < minimum) {
PyErr_Format(PyExc_RuntimeError,
- "Value %ld is less than minimum for %s (%ld)",
+ "Value %lld is less than minimum for %s (%lld)",
value, type_name, minimum);
value = minimum;
} else if (value > maximum) {
PyErr_Format(PyExc_RuntimeError,
- "Value %ld is greater than maximum for %s (%ld)",
+ "Value %lld is greater than maximum for %s (%lld)",
value, type_name, maximum);
value = maximum;
}
_______________________________________________
nox-dev mailing list
[email protected]
http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org