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

Skip to content

Commit 91d58bd

Browse files
committed
Merged revisions 76822,76824 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r76822 | benjamin.peterson | 2009-12-13 15:21:43 -0600 (Sun, 13 Dec 2009) | 1 line initialize to NULL ........ r76824 | benjamin.peterson | 2009-12-13 15:27:53 -0600 (Sun, 13 Dec 2009) | 1 line add a test of loading the datetime capi ........
1 parent 5f4ec04 commit 91d58bd

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

Include/datetime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ typedef struct {
182182
#else
183183

184184
/* Define global variable for the C API and a macro for setting it. */
185-
static PyDateTime_CAPI *PyDateTimeAPI;
185+
static PyDateTime_CAPI *PyDateTimeAPI = NULL;
186186

187187
#define PyDateTime_IMPORT \
188188
PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)

Modules/_testcapimodule.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Python.h"
1111
#include <float.h>
1212
#include "structmember.h"
13+
#include "datetime.h"
1314

1415
#ifdef WITH_THREAD
1516
#include "pythread.h"
@@ -935,6 +936,20 @@ raise_exception(PyObject *self, PyObject *args)
935936

936937
#ifdef WITH_THREAD
937938

939+
static PyObject *
940+
test_datetime_capi(PyObject *self, PyObject *args) {
941+
if (PyDateTimeAPI) {
942+
PyErr_SetString(PyExc_AssertionError,
943+
"PyDateTime_CAPI somehow initialized");
944+
return NULL;
945+
}
946+
PyDateTime_IMPORT;
947+
if (PyDateTimeAPI)
948+
Py_RETURN_NONE;
949+
else
950+
return NULL;
951+
}
952+
938953
/* test_thread_state spawns a thread of its own, and that thread releases
939954
* `thread_done` when it's finished. The driver code has to know when the
940955
* thread finishes, because the thread uses a PyObject (the callable) that
@@ -1531,6 +1546,7 @@ static PyMethodDef TestMethods[] = {
15311546
{"raise_exception", raise_exception, METH_VARARGS},
15321547
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
15331548
{"test_config", (PyCFunction)test_config, METH_NOARGS},
1549+
{"test_datetime_capi", test_datetime_capi, METH_NOARGS},
15341550
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
15351551
{"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
15361552
{"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS},

0 commit comments

Comments
 (0)