PostgreSQL Source Code: contrib/hstore_plpython/hstore_plpython.c Source File (original) (raw)

2

7

9 .name = "hstore_plpython",

10 .version = PG_VERSION

11);

12

13

14typedef char *(*PLyObject_AsString_t) (PyObject *plrv);

16typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);

18

19

30

31

32

33

34

35void

37{

38

42 true, NULL);

46 true, NULL);

50 true, NULL);

54 true, NULL);

58 true, NULL);

62 true, NULL);

66 true, NULL);

67}

68

69

70

71#define PLyObject_AsString PLyObject_AsString_p

72#define PLyUnicode_FromStringAndSize PLyUnicode_FromStringAndSize_p

73#define hstoreUpgrade hstoreUpgrade_p

74#define hstoreUniquePairs hstoreUniquePairs_p

75#define hstorePairs hstorePairs_p

76#define hstoreCheckKeyLen hstoreCheckKeyLen_p

77#define hstoreCheckValLen hstoreCheckValLen_p

78

79

81

84{

86 int i;

88 char *base = STRPTR(in);

90 PyObject *dict;

91

92 dict = PyDict_New();

93 if (!dict)

95 (errcode(ERRCODE_OUT_OF_MEMORY),

96 errmsg("out of memory")));

97

98 for (i = 0; i < count; i++)

99 {

100 PyObject *key;

101

105 PyDict_SetItem(dict, key, Py_None);

106 else

107 {

109

112 PyDict_SetItem(dict, key, value);

113 Py_XDECREF(value);

114 }

115 Py_XDECREF(key);

116 }

117

119}

120

121

123

126{

127 PyObject *dict;

128 PyObject *volatile items;

129 Py_ssize_t pcount;

130 HStore *volatile out;

131

133

134

135

136

137

138

139 if (PySequence_Check(dict) || !PyMapping_Check(dict))

141 (errcode(ERRCODE_WRONG_OBJECT_TYPE),

142 errmsg("not a Python mapping")));

143

144 pcount = PyMapping_Size(dict);

145 items = PyMapping_Items(dict);

146

148 {

150 Py_ssize_t i;

152

153 pairs = palloc(pcount * sizeof(*pairs));

154

155 for (i = 0; i < pcount; i++)

156 {

157 PyObject *tuple;

158 PyObject *key;

160

161 tuple = PyList_GetItem(items, i);

162 key = PyTuple_GetItem(tuple, 0);

163 value = PyTuple_GetItem(tuple, 1);

164

168

169 if (value == Py_None)

170 {

171 pairs[i].val = NULL;

174 }

175 else

176 {

180 }

181 }

182

184 out = hstorePairs(pairs, pcount, buflen);

185 }

187 {

188 Py_DECREF(items);

189 }

191

193}

#define AssertVariableIsOfType(varname, typename)

void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

#define PG_GETARG_POINTER(n)

#define PG_RETURN_POINTER(x)

#define HSTORE_KEY(arr_, str_, i_)

#define PG_GETARG_HSTORE_P(x)

#define HSTORE_VALISNULL(arr_, i_)

#define HSTORE_VALLEN(arr_, i_)

#define HSTORE_KEYLEN(arr_, i_)

#define HSTORE_VAL(arr_, str_, i_)

Datum plpython_to_hstore(PG_FUNCTION_ARGS)

#define PLyUnicode_FromStringAndSize

int(* hstoreUniquePairs_t)(Pairs *a, int32 l, int32 *buflen)

static hstoreUpgrade_t hstoreUpgrade_p

static hstoreCheckKeyLen_t hstoreCheckKeyLen_p

HStore *(* hstoreUpgrade_t)(Datum orig)

#define hstoreCheckKeyLen

#define hstoreUniquePairs

PyObject *(* PLyUnicode_FromStringAndSize_t)(const char *s, Py_ssize_t size)

static hstorePairs_t hstorePairs_p

static PLyObject_AsString_t PLyObject_AsString_p

PG_MODULE_MAGIC_EXT(.name="hstore_plpython",.version=PG_VERSION)

Datum hstore_to_plpython(PG_FUNCTION_ARGS)

char *(* PLyObject_AsString_t)(PyObject *plrv)

static hstoreCheckValLen_t hstoreCheckValLen_p

static hstoreUniquePairs_t hstoreUniquePairs_p

size_t(* hstoreCheckValLen_t)(size_t len)

static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p

#define hstoreCheckValLen

HStore *(* hstorePairs_t)(Pairs *pairs, int32 pcount, int32 buflen)

PG_FUNCTION_INFO_V1(hstore_to_plpython)

size_t(* hstoreCheckKeyLen_t)(size_t len)

#define PLyObject_AsString

static Datum PointerGetDatum(const void *X)