summaryrefslogtreecommitdiff
path: root/usr/src/lib/pylibbe/common/libbe_py.c
diff options
context:
space:
mode:
authorAndy Fiddaman <omnios@citrus-it.co.uk>2018-10-13 21:12:19 +0000
committerDan McDonald <danmcd@joyent.com>2018-10-24 15:27:58 -0400
commite8921a52c53ee69f7b65f054d9b2e886139daa59 (patch)
tree47ff09b2c3cf4a36bb54f09c2f24debb5f5f513a /usr/src/lib/pylibbe/common/libbe_py.c
parente24b44e5c3120c9b5c8e9b7440bc10c8b7413bfb (diff)
downloadillumos-joyent-e8921a52c53ee69f7b65f054d9b2e886139daa59.tar.gz
9894 Deliver python3 modules
9904 Split python modules out into separate packages 5571 Provide 64-bit python modules Reviewed by: Alexander Pyhalov <apyhalov@gmail.com> Reviewed by: Toomas Soome <tsoome@me.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/pylibbe/common/libbe_py.c')
-rw-r--r--usr/src/lib/pylibbe/common/libbe_py.c66
1 files changed, 49 insertions, 17 deletions
diff --git a/usr/src/lib/pylibbe/common/libbe_py.c b/usr/src/lib/pylibbe/common/libbe_py.c
index fb5102bdb6..3b4a3a3c42 100644
--- a/usr/src/lib/pylibbe/common/libbe_py.c
+++ b/usr/src/lib/pylibbe/common/libbe_py.c
@@ -60,7 +60,6 @@ PyObject *beUnmount(PyObject *, PyObject *);
PyObject *bePrintErrors(PyObject *, PyObject *);
PyObject *beGetErrDesc(PyObject *, PyObject *);
char *beMapLibbePyErrorToString(int);
-void initlibbe_py();
static boolean_t convertBEInfoToDictionary(be_node_list_t *be,
PyObject **listDict);
@@ -204,8 +203,8 @@ beCopy(PyObject *self, PyObject *args)
}
while (PyDict_Next(beNameProperties, &pos, &pkey, &pvalue)) {
if (!convertPyArgsToNvlist(&beProps, 2,
- PyString_AsString(pkey),
- PyString_AsString(pvalue))) {
+ PyBytes_AS_STRING(pkey),
+ PyBytes_AS_STRING(pvalue))) {
nvlist_free(beProps);
nvlist_free(beAttrs);
return (Py_BuildValue("[iss]", BE_PY_ERR_NVLIST,
@@ -833,21 +832,21 @@ convertBEInfoToDictionary(be_node_list_t *be, PyObject **listDict)
{
if (be->be_node_name != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_ORIG_BE_NAME,
- PyString_FromString(be->be_node_name)) != 0) {
+ PyUnicode_FromString(be->be_node_name)) != 0) {
return (B_FALSE);
}
}
if (be->be_rpool != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_ORIG_BE_POOL,
- PyString_FromString(be->be_rpool)) != 0) {
+ PyUnicode_FromString(be->be_rpool)) != 0) {
return (B_FALSE);
}
}
if (be->be_mntpt != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_MOUNTPOINT,
- PyString_FromString(be->be_mntpt)) != 0) {
+ PyUnicode_FromString(be->be_mntpt)) != 0) {
return (B_FALSE);
}
}
@@ -881,7 +880,7 @@ convertBEInfoToDictionary(be_node_list_t *be, PyObject **listDict)
if (be->be_root_ds != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_ROOT_DS,
- PyString_FromString(be->be_root_ds)) != 0) {
+ PyUnicode_FromString(be->be_root_ds)) != 0) {
return (B_FALSE);
}
}
@@ -895,14 +894,14 @@ convertBEInfoToDictionary(be_node_list_t *be, PyObject **listDict)
if (be->be_policy_type != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_POLICY,
- PyString_FromString(be->be_policy_type)) != 0) {
+ PyUnicode_FromString(be->be_policy_type)) != 0) {
return (B_FALSE);
}
}
if (be->be_uuid_str != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_UUID_STR,
- PyString_FromString(be->be_uuid_str)) != 0) {
+ PyUnicode_FromString(be->be_uuid_str)) != 0) {
return (B_FALSE);
}
}
@@ -915,7 +914,7 @@ convertDatasetInfoToDictionary(be_dataset_list_t *ds, PyObject **listDict)
{
if (ds->be_dataset_name != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_DATASET,
- PyString_FromString(ds->be_dataset_name)) != 0) {
+ PyUnicode_FromString(ds->be_dataset_name)) != 0) {
return (B_FALSE);
}
}
@@ -927,7 +926,7 @@ convertDatasetInfoToDictionary(be_dataset_list_t *ds, PyObject **listDict)
if (ds->be_ds_mntpt != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_MOUNTPOINT,
- PyString_FromString(ds->be_ds_mntpt)) != 0) {
+ PyUnicode_FromString(ds->be_ds_mntpt)) != 0) {
return (B_FALSE);
}
}
@@ -947,14 +946,14 @@ convertDatasetInfoToDictionary(be_dataset_list_t *ds, PyObject **listDict)
if (ds->be_dataset_name != 0) {
if (PyDict_SetItemString(*listDict, BE_ATTR_DATASET,
- PyString_FromString(ds->be_dataset_name)) != 0) {
+ PyUnicode_FromString(ds->be_dataset_name)) != 0) {
return (B_FALSE);
}
}
if (ds->be_ds_plcy_type != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_POLICY,
- PyString_FromString(ds->be_ds_plcy_type)) != 0) {
+ PyUnicode_FromString(ds->be_ds_plcy_type)) != 0) {
return (B_FALSE);
}
}
@@ -974,7 +973,7 @@ convertSnapshotInfoToDictionary(be_snapshot_list_t *ss, PyObject **listDict)
{
if (ss->be_snapshot_name != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_SNAP_NAME,
- PyString_FromString(ss->be_snapshot_name)) != 0) {
+ PyUnicode_FromString(ss->be_snapshot_name)) != 0) {
return (B_FALSE);
}
}
@@ -988,7 +987,7 @@ convertSnapshotInfoToDictionary(be_snapshot_list_t *ss, PyObject **listDict)
if (ss->be_snapshot_type != NULL) {
if (PyDict_SetItemString(*listDict, BE_ATTR_POLICY,
- PyString_FromString(ss->be_snapshot_type)) != 0) {
+ PyUnicode_FromString(ss->be_snapshot_type)) != 0) {
return (B_FALSE);
}
}
@@ -1103,9 +1102,42 @@ static struct PyMethodDef libbeMethods[] = {
{NULL, NULL, 0, NULL}
};
-void
-initlibbe_py()
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef libbe_module = {
+ PyModuleDef_HEAD_INIT,
+ "libbe_py",
+ NULL,
+ -1,
+ libbeMethods
+};
+#endif
+
+static PyObject *
+moduleinit()
{
/* PyMODINIT_FUNC; */
+#if PY_MAJOR_VERSION >= 3
+ return (PyModule_Create(&libbe_module));
+#else
+ /*
+ * Python2 module initialisation functions are void and may not return
+ * a value. However, they will set an exception if appropriate.
+ */
(void) Py_InitModule("libbe_py", libbeMethods);
+ return (NULL);
+#endif
+}
+
+#if PY_MAJOR_VERSION >= 3
+PyMODINIT_FUNC
+PyInit_libbe_py(void)
+{
+ return (moduleinit());
+}
+#else
+PyMODINIT_FUNC
+initlibbe_py(void)
+{
+ (void) moduleinit();
}
+#endif