Sparse Virtual File System  0.4.1
A Sparse Virtual File System.
svfs_util.cpp
Go to the documentation of this file.
1 
32 #include <sstream>
33 
34 #include "svfs_util.h"
35 
36 //PyObject *py_unicode_from_std_string(const std::string &s) {
37 // return PyUnicode_FromKindAndData(PyUnicode_1BYTE_KIND, s.c_str(), s.size());
38 //}
39 //
40 //std::string py_unicode_to_std_string(PyObject *op) {
41 // assert(op);
42 // fprintf(stdout, "py_unicode_to_std_string() op = %p\n", (void *)op);
43 // if (! PyUnicode_Check(op)) {
44 // std::ostringstream os;
45 // os << "py_unicode_to_std_string(): not a unicode object but type \"";
46 // os << Py_TYPE(op) << "\"";
47 // throw ExceptionUtil(os.str());
48 // }
49 // assert(PyUnicode_AsUTF8(op));
51 // std::string ret(PyUnicode_AsUTF8(op), static_cast<unsigned long>(PyUnicode_GET_LENGTH(op)));
52 // return ret;
53 //}
54 
62 PyObject *
63 datetime_from_struct_tm(const std::tm *bdt, int usecond) {
64  PyObject * ret = NULL;
65 
67  assert(!PyErr_Occurred());
68 // // This is calling new_datetime_ex() which increfs tz and sets hastzinfo
69 // ret = PyDateTimeAPI->DateTime_FromDateAndTime(
70 // bdt->tm_year + 1900,
71 // bdt->tm_mon + 1,
72 // bdt->tm_mday,
73 // bdt->tm_hour,
74 // bdt->tm_min,
75 // bdt->tm_sec,
76 // usecond,
77 // NULL,
78 // PyDateTimeAPI->DateTimeType
79 // );
80  ret = PyDateTime_FromDateAndTime(
81  bdt->tm_year + 1900,
82  bdt->tm_mon + 1,
83  bdt->tm_mday,
84  bdt->tm_hour,
85  bdt->tm_min,
86  bdt->tm_sec,
87  usecond
88  );
89  if (!ret) {
90  PyErr_Format(PyExc_RuntimeError, "%s: Can not create datetime.datetime", __FUNCTION__);
91  goto except;
92  }
93  assert(!PyErr_Occurred());
94  assert(ret);
95  goto finally;
96  except:
97  assert(PyErr_Occurred());
98  Py_XDECREF(ret);
99  ret = NULL;
100  finally:
101  return ret;
102 }
PyObject * datetime_from_struct_tm(const std::tm *bdt, int usecond)
Definition: svfs_util.cpp:63
#define IMPORT_DATETIME_IF_UNINITIALISED
Definition: svfs_util.h:43