]> granicus.if.org Git - python/commitdiff
Merged revisions 76822,76824 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sun, 13 Dec 2009 21:30:54 +0000 (21:30 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sun, 13 Dec 2009 21:30:54 +0000 (21:30 +0000)
svn+ssh://pythondev@svn.python.org/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
........

Include/datetime.h
Modules/_testcapimodule.c

index 4b506b2e72e4ffe78541b9db8e222e835b2c5148..d14ead1f86c8530a1e80b1a1be26bc9ec9203401 100644 (file)
@@ -182,7 +182,7 @@ typedef struct {
 #else
 
 /* Define global variable for the C API and a macro for setting it. */
-static PyDateTime_CAPI *PyDateTimeAPI;
+static PyDateTime_CAPI *PyDateTimeAPI = NULL;
 
 #define PyDateTime_IMPORT \
         PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
index aca860adc5e701bfe2306100e0f7b6eeb1b5a191..6244f3ff8290d09ef2818643e5ccdf90d5208cd5 100644 (file)
@@ -10,6 +10,7 @@
 #include "Python.h"
 #include <float.h>
 #include "structmember.h"
+#include "datetime.h"
 
 #ifdef WITH_THREAD
 #include "pythread.h"
@@ -935,6 +936,20 @@ raise_exception(PyObject *self, PyObject *args)
 
 #ifdef WITH_THREAD
 
+static PyObject *
+test_datetime_capi(PyObject *self, PyObject *args) {
+       if (PyDateTimeAPI) {
+               PyErr_SetString(PyExc_AssertionError,
+                               "PyDateTime_CAPI somehow initialized");
+               return NULL;
+       }
+       PyDateTime_IMPORT;
+        if (PyDateTimeAPI)
+               Py_RETURN_NONE;
+       else
+               return NULL;
+}
+
 /* test_thread_state spawns a thread of its own, and that thread releases
  * `thread_done` when it's finished.  The driver code has to know when the
  * thread finishes, because the thread uses a PyObject (the callable) that
@@ -1531,6 +1546,7 @@ static PyMethodDef TestMethods[] = {
        {"raise_exception",     raise_exception,                 METH_VARARGS},
        {"raise_memoryerror",   (PyCFunction)raise_memoryerror,  METH_NOARGS},
        {"test_config",         (PyCFunction)test_config,        METH_NOARGS},
+       {"test_datetime_capi",  test_datetime_capi,              METH_NOARGS},
        {"test_list_api",       (PyCFunction)test_list_api,      METH_NOARGS},
        {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
        {"test_lazy_hash_inheritance",  (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS},