Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b01a83

Browse files
author
Skip Montanaro
committed
use PyModule_Add{Int,String}Constant() where appropriate
(thanks to Neal Norwitz for the code review, BTW)
1 parent 577c7a7 commit 7b01a83

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

Modules/_csv.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module instead.
1212
1313
*/
1414

15+
#define MODULE_VERSION "1.0"
16+
1517
#include "Python.h"
1618
#include "structmember.h"
1719

@@ -1440,9 +1442,6 @@ PyMODINIT_FUNC
14401442
init_csv(void)
14411443
{
14421444
PyObject *module;
1443-
PyObject *rev;
1444-
PyObject *v;
1445-
int res;
14461445
StyleDesc *style;
14471446

14481447
if (PyType_Ready(&Dialect_Type) < 0)
@@ -1460,10 +1459,8 @@ init_csv(void)
14601459
return;
14611460

14621461
/* Add version to the module. */
1463-
rev = PyString_FromString("1.0");
1464-
if (rev == NULL)
1465-
return;
1466-
if (PyModule_AddObject(module, "__version__", rev) < 0)
1462+
if (PyModule_AddStringConstant(module, "__version__",
1463+
MODULE_VERSION) == -1)
14671464
return;
14681465

14691466
/* Add _dialects dictionary */
@@ -1475,11 +1472,8 @@ init_csv(void)
14751472

14761473
/* Add quote styles into dictionary */
14771474
for (style = quote_styles; style->name; style++) {
1478-
v = PyInt_FromLong(style->style);
1479-
if (v == NULL)
1480-
return;
1481-
res = PyModule_AddObject(module, style->name, v);
1482-
if (res < 0)
1475+
if (PyModule_AddIntConstant(module, style->name,
1476+
style->style) == -1)
14831477
return;
14841478
}
14851479

0 commit comments

Comments
 (0)