Skip to content

Instantly share code, notes, and snippets.

@OrangeTux
Created December 30, 2015 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OrangeTux/df1c57ab660e79e9d3db to your computer and use it in GitHub Desktop.
Save OrangeTux/df1c57ab660e79e9d3db to your computer and use it in GitHub Desktop.
// Create a new C tuple object of size 3.
typle = PyTuple_New(3)
// Manually check if tuple is created correctly.
if (tuple == NULL)
return NULL;
for (i=0; i<3; i++) {
// Create Python integer.
item = PyInt_FromLong(42);
// Again, manually check if everything went well.
// If not, decrease reference counter of tulpe object.
if (item == NULL) {
// Decrease references counter to tuple object.
Py_DECREF(tuple);
return NULL;
}
// Set i-th item of tuple to 42.
PyTuple_SET_ITEM(tuple, i, item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment