Skip to content

Commit

Permalink
PyInt_* functions are replaced by PyLong_*
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopelka committed Nov 4, 2013
1 parent e0bbea3 commit 1cbb91f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 7 deletions.
82 changes: 79 additions & 3 deletions cupsconnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,17 @@ cups_dest_cb (void *user_data, unsigned flags, cups_dest_t *dest)
ret = 0;
}

if (result && PyInt_Check (result)) {

if (result && PyLong_Check (result)) {
ret = PyLong_AsLong (result);
debugprintf (" cups_dest_cb: cb func returned %d\n", ret);
}
#if PY_MAJOR_VERSION < 3
else if (result && PyInt_Check (result)) {
ret = PyInt_AsLong (result);
debugprintf (" cups_dest_cb: cb func returned %d\n", ret);
}
#endif

debugprintf ("<- cups_dest_cb (%d)\n", ret);

Expand Down Expand Up @@ -658,7 +665,11 @@ PyObject_from_attr_value (ipp_attribute_t *attr, int i)
break;
case IPP_TAG_INTEGER:
case IPP_TAG_ENUM:
#if PY_MAJOR_VERSION >= 3
val = PyLong_FromLong (ippGetInteger (attr, i));
#else
val = PyInt_FromLong (ippGetInteger (attr, i));
#endif
break;
case IPP_TAG_BOOLEAN:
val = PyBool_FromLong (ippGetBoolean (attr, i));
Expand Down Expand Up @@ -782,7 +793,11 @@ Connection_getPrinters (Connection *self)
!strcmp (ippGetName (attr), "printer-state")) &&
ippGetValueTag (attr) == IPP_TAG_ENUM) {
int ptype = ippGetInteger (attr, 0);
#if PY_MAJOR_VERSION >= 3
val = PyLong_FromLong (ptype);
#else
val = PyInt_FromLong (ptype);
#endif
}
else if ((!strcmp (ippGetName (attr),
"printer-make-and-model") ||
Expand All @@ -801,15 +816,23 @@ Connection_getPrinters (Connection *self)
"printer-is-accepting-jobs") &&
ippGetValueTag (attr) == IPP_TAG_BOOLEAN) {
int b = ippGetBoolean (attr, 0);
#if PY_MAJOR_VERSION >= 3
val = PyLong_FromLong (b);
#else
val = PyInt_FromLong (b);
#endif
}
else if ((!strcmp (ippGetName (attr),
"printer-up-time") ||
!strcmp (ippGetName (attr),
"queued-job-count")) &&
ippGetValueTag (attr) == IPP_TAG_INTEGER) {
int u = ippGetInteger (attr, 0);
#if PY_MAJOR_VERSION >= 3
val = PyLong_FromLong (u);
#else
val = PyInt_FromLong (u);
#endif
}
else if ((!strcmp (ippGetName (attr), "device-uri") ||
!strcmp (ippGetName (attr), "printer-uri-supported")) &&
Expand Down Expand Up @@ -1642,7 +1665,11 @@ Connection_getJobs (Connection *self, PyObject *args, PyObject *kwds)
ippGetValueTag (attr) == IPP_TAG_INTEGER) ||
(!strcmp (ippGetName (attr), "job-state") &&
ippGetValueTag (attr) == IPP_TAG_ENUM))
#if PY_MAJOR_VERSION >= 3
val = PyLong_FromLong (ippGetInteger (attr, 0));
#else
val = PyInt_FromLong (ippGetInteger (attr, 0));
#endif
else if ((!strcmp (ippGetName (attr), "job-name") &&
ippGetValueTag (attr) == IPP_TAG_NAME) ||
(!strcmp (ippGetName (attr), "job-originating-user-name") &&
Expand All @@ -1669,7 +1696,11 @@ Connection_getJobs (Connection *self, PyObject *args, PyObject *kwds)

if (job_id != -1) {
debugprintf ("Adding %d to result dict\n", job_id);
#if PY_MAJOR_VERSION >= 3
PyObject *job_obj = PyLong_FromLong (job_id);
#else
PyObject *job_obj = PyInt_FromLong (job_id);
#endif
PyDict_SetItem (result, job_obj, dict);
Py_DECREF (job_obj);
}
Expand Down Expand Up @@ -2885,10 +2916,16 @@ PyObject_to_string (PyObject *pyvalue)
UTF8_from_PyObj (&value, pyvalue);
} else if (PyBool_Check (pyvalue)) {
value = (pyvalue == Py_True) ? "true" : "false";
} else if (PyLong_Check (pyvalue)) {
long v = PyLong_AsLong (pyvalue);
snprintf (string, sizeof (string), "%ld", v);
value = string;
#if PY_MAJOR_VERSION < 3
} else if (PyInt_Check (pyvalue)) {
long v = PyInt_AsLong (pyvalue);
snprintf (string, sizeof (string), "%ld", v);
value = string;
#endif
} else if (PyFloat_Check (pyvalue)) {
double v = PyFloat_AsDouble (pyvalue);
snprintf (string, sizeof (string), "%f", v);
Expand Down Expand Up @@ -3633,7 +3670,12 @@ Connection_getPPD3 (Connection *self, PyObject *args, PyObject *kwds)
if (!ret)
return NULL;

#if PY_MAJOR_VERSION >= 3
obj = PyLong_FromLong ((long) status);
#else
obj = PyInt_FromLong ((long) status);
#endif

if (!obj) {
Py_DECREF (ret);
return NULL;
Expand Down Expand Up @@ -4181,7 +4223,11 @@ Connection_createSubscription (Connection *self, PyObject *args,

ippDelete (answer);
debugprintf ("<- Connection_createSubscription() = %d\n", i);
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong (i);
#else
return PyInt_FromLong (i);
#endif
}

static PyObject *
Expand All @@ -4206,7 +4252,11 @@ Connection_getNotifications (Connection *self, PyObject *args, PyObject *kwds)
num_ids = PyList_Size (subscription_ids);
for (i = 0; i < num_ids; i++) {
PyObject *id = PyList_GetItem (subscription_ids, i);
#if PY_MAJOR_VERSION >= 3
if (!PyLong_Check (id)) {
#else
if (!PyInt_Check (id)) {
#endif
PyErr_SetString (PyExc_TypeError, "subscription_ids must be a list "
"of integers");
return NULL;
Expand All @@ -4222,7 +4272,11 @@ Connection_getNotifications (Connection *self, PyObject *args, PyObject *kwds)
num_seqs = PyList_Size (sequence_numbers);
for (i = 0; i < num_seqs; i++) {
PyObject *id = PyList_GetItem (sequence_numbers, i);
#if PY_MAJOR_VERSION >= 3
if (!PyLong_Check (id)) {
#else
if (!PyInt_Check (id)) {
#endif
PyErr_SetString (PyExc_TypeError, "sequence_numbers must be a list "
"of integers");
return NULL;
Expand All @@ -4241,17 +4295,23 @@ Connection_getNotifications (Connection *self, PyObject *args, PyObject *kwds)
"notify-subscription-ids", num_ids, NULL);
for (i = 0; i < num_ids; i++) {
PyObject *id = PyList_GetItem (subscription_ids, i);
//attr->values[i].integer = PyInt_AsLong (id);
#if PY_MAJOR_VERSION >= 3
ippSetInteger (request, &attr, i, PyLong_AsLong (id));
#else
ippSetInteger (request, &attr, i, PyInt_AsLong (id));
#endif
}

if (sequence_numbers) {
attr = ippAddIntegers (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
"notify-sequence-numbers", num_seqs, NULL);
for (i = 0; i < num_seqs; i++) {
PyObject *num = PyList_GetItem (sequence_numbers, i);
//attr->values[i].integer = PyInt_AsLong (num);
#if PY_MAJOR_VERSION >= 3
ippSetInteger (request, &attr, i, PyLong_AsLong (num));
#else
ippSetInteger (request, &attr, i, PyInt_AsLong (num));
#endif
}
}

Expand All @@ -4272,14 +4332,22 @@ Connection_getNotifications (Connection *self, PyObject *args, PyObject *kwds)
// Result-wide attributes.
attr = ippFindAttribute (answer, "notify-get-interval", IPP_TAG_INTEGER);
if (attr) {
#if PY_MAJOR_VERSION >= 3
PyObject *val = PyLong_FromLong (ippGetInteger (attr, 0));
#else
PyObject *val = PyInt_FromLong (ippGetInteger (attr, 0));
#endif
PyDict_SetItemString (result, ippGetName (attr), val);
Py_DECREF (val);
}

attr = ippFindAttribute (answer, "printer-up-time", IPP_TAG_INTEGER);
if (attr) {
#if PY_MAJOR_VERSION >= 3
PyObject *val = PyLong_FromLong (ippGetInteger (attr, 0));
#else
PyObject *val = PyInt_FromLong (ippGetInteger (attr, 0));
#endif
PyDict_SetItemString (result, ippGetName (attr), val);
Py_DECREF (val);
}
Expand Down Expand Up @@ -4489,7 +4557,11 @@ Connection_printFile (Connection *self, PyObject *args, PyObject *kwds)
free (title);
free (filename);
free (printer);
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong (jobid);
#else
return PyInt_FromLong (jobid);
#endif
}

static void
Expand Down Expand Up @@ -4599,7 +4671,11 @@ Connection_printFiles (Connection *self, PyObject *args, PyObject *kwds)
free (title);
free_string_list (num_filenames, filenames);
free (printer);
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong (jobid);
#else
return PyInt_FromLong (jobid);
#endif
}

PyMethodDef Connection_methods[] =
Expand Down
27 changes: 24 additions & 3 deletions cupsipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ IPPAttribute_init (IPPAttribute *self, PyObject *args, PyObject *kwds)
case IPP_TAG_INTEGER:
case IPP_TAG_ENUM:
case IPP_TAG_RANGE:
#if PY_MAJOR_VERSION >= 3
valid = PyLong_Check (v);
#else
valid = PyInt_Check (v);
#endif
break;

case IPP_TAG_BOOLEAN:
Expand Down Expand Up @@ -178,13 +182,21 @@ IPPAttribute_repr (IPPAttribute *self)
static PyObject *
IPPAttribute_getGroupTag (IPPAttribute *self, void *closure)
{
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong (self->group_tag);
#else
return PyInt_FromLong (self->group_tag);
#endif
}

static PyObject *
IPPAttribute_getValueTag (IPPAttribute *self, void *closure)
{
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong (self->value_tag);
#else
return PyInt_FromLong (self->value_tag);
#endif
}

static PyObject *
Expand Down Expand Up @@ -371,6 +383,7 @@ IPPRequest_readIO (IPPRequest *self, PyObject *args, PyObject *kwds)
{
PyObject *cb;
char blocking = 1;
ipp_state_t state;
static char *kwlist[] = { "read_fn", "blocking", NULL };

if (!PyArg_ParseTupleAndKeywords (args, kwds, "O|b", kwlist,
Expand All @@ -382,9 +395,13 @@ IPPRequest_readIO (IPPRequest *self, PyObject *args, PyObject *kwds)
return NULL;
}

return PyInt_FromLong (ippReadIO (cb,
(ipp_iocb_t) cupsipp_iocb_read,
blocking, NULL, self->ipp));
state = ippReadIO (cb, (ipp_iocb_t) cupsipp_iocb_read,
blocking, NULL, self->ipp);
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong (state);
#else
return PyInt_FromLong (state);
#endif
}

static PyObject *
Expand Down Expand Up @@ -419,7 +436,11 @@ IPPRequest_getAttributes (IPPRequest *self, void *closure)
case IPP_TAG_INTEGER:
case IPP_TAG_ENUM:
case IPP_TAG_RANGE:
#if PY_MAJOR_VERSION >= 3
value = PyLong_FromLong (ippGetInteger (attr, i));
#else
value = PyInt_FromLong (ippGetInteger (attr, i));
#endif
debugprintf ("i%d", ippGetInteger (attr, i));
break;

Expand Down
6 changes: 5 additions & 1 deletion cupsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,13 @@ initcups (void)
(PyObject *)&cups_IPPAttributeType);

// Constants

#if PY_MAJOR_VERSION >= 3
#define INT_CONSTANT(name) \
PyDict_SetItemString (d, #name, PyLong_FromLong (name))
#else
#define INT_CONSTANT(name) \
PyDict_SetItemString (d, #name, PyInt_FromLong (name))
#endif
#define STR_CONSTANT(name) \
PyDict_SetItemString (d, #name, PyUnicode_FromString (name))

Expand Down
8 changes: 8 additions & 0 deletions cupsppd.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ PPD_markOption (PPD *self, PyObject *args)
static PyObject *
PPD_conflicts (PPD *self)
{
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong (ppdConflicts (self->ppd));
#else
return PyInt_FromLong (ppdConflicts (self->ppd));
#endif
}

static PyObject *
Expand Down Expand Up @@ -1186,7 +1190,11 @@ Option_getUI (Option *self, void *closure)
Py_RETURN_NONE;
}

#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong (self->option->ui);
#else
return PyInt_FromLong (self->option->ui);
#endif
}

static PyObject *
Expand Down

0 comments on commit 1cbb91f

Please sign in to comment.