Content-Length: 795039 | pFad | http://github.com/4cecoder/go-python/commit/bf65570ba5f575e4f8e3a9058f60fd08dd960522

89 applied go1rename and error gofix changes · 4cecoder/go-python@bf65570 · GitHub
Skip to content

Commit bf65570

Browse files
author
Sebastien Binet
committed
applied go1rename and error gofix changes
1 parent a120f71 commit bf65570

File tree

7 files changed

+54
-60
lines changed

7 files changed

+54
-60
lines changed

pkg/python/dict.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ package python
66
//int _gopy_PyDict_Check(PyObject *o) { return PyDict_Check(o); }
77
//int _gopy_PyDict_CheckExact(PyObject *o) { return PyDict_CheckExact(o); }
88
import "C"
9-
import "unsafe"
10-
import "os"
9+
import (
10+
"errors"
11+
"unsafe"
12+
)
1113

1214
// int PyDict_Check(PyObject *p)
1315
// Return true if p is a dict object or an instance of a subtype of the dict type.
@@ -47,12 +49,11 @@ func PyDict_Clear(self *PyObject) {
4749
C.PyDict_Clear(topy(self))
4850
}
4951

50-
5152
// int PyDict_Contains(PyObject *p, PyObject *key)
5253
// Determine if dictionary p contains key. If an item in p is matches key, return 1, otherwise return 0. On error, return -1. This is equivalent to the Python expression key in p.
5354
//
5455
// New in version 2.4.
55-
func PyDict_Contains(self, key *PyObject) (bool, os.Error) {
56+
func PyDict_Contains(self, key *PyObject) (bool, error) {
5657
err := C.PyDict_Contains(topy(self), topy(key))
5758
if err != -1 {
5859
return int2bool(err), nil
@@ -73,7 +74,7 @@ func PyDict_Copy(self *PyObject) *PyObject {
7374
// Insert value into the dictionary p with a key of key. key must be hashable; if it isn’t, TypeError will be raised. Return 0 on success or -1 on failure.
7475
// int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
7576
// Insert value into the dictionary p using key as a key. key should be a char*. The key object is created using PyString_FromString(key). Return 0 on success or -1 on failure.
76-
func PyDict_SetItem(self, key, val *PyObject) os.Error {
77+
func PyDict_SetItem(self, key, val *PyObject) error {
7778
err := C.PyDict_SetItem(topy(self), topy(key), topy(val))
7879
return int2err(err)
7980
}
@@ -82,7 +83,7 @@ func PyDict_SetItem(self, key, val *PyObject) os.Error {
8283
// Remove the entry in dictionary p with key key. key must be hashable; if it isn’t, TypeError is raised. Return 0 on success or -1 on failure.
8384
// int PyDict_DelItemString(PyObject *p, char *key)
8485
// Remove the entry in dictionary p which has a key specified by the string key. Return 0 on success or -1 on failure.
85-
func PyDict_DelItem(self, key *PyObject) os.Error {
86+
func PyDict_DelItem(self, key *PyObject) error {
8687
err := C.PyDict_DelItem(topy(self), topy(key))
8788
return int2err(err)
8889
}
@@ -162,9 +163,9 @@ func PyDict_Size(self *PyObject) int {
162163
// Py_DECREF(o);
163164
// }
164165
// Changed in version 2.5: This function used an int * type for ppos. This might require changes in your code for properly supporting 64-bit systems.
165-
func PyDict_Next(self *PyObject, pos *int, key, value **PyObject) os.Error {
166+
func PyDict_Next(self *PyObject, pos *int, key, value **PyObject) error {
166167
if pos == nil {
167-
return os.NewError("invalid position")
168+
return errors.New("invalid position")
168169
}
169170

170171
c_pos := C.Py_ssize_t(*pos)
@@ -184,7 +185,7 @@ func PyDict_Next(self *PyObject, pos *int, key, value **PyObject) os.Error {
184185
// Iterate over mapping object b adding key-value pairs to dictionary a. b may be a dictionary, or any object supporting PyMapping_Keys() and PyObject_GetItem(). If override is true, existing pairs in a will be replaced if a matching key is found in b, otherwise pairs will only be added if there is not a matching key in a. Return 0 on success or -1 if an exception was raised.
185186
//
186187
// New in version 2.2.
187-
func PyDict_Merge(a, b *PyObject, override int) os.Error {
188+
func PyDict_Merge(a, b *PyObject, override int) error {
188189
err := C.PyDict_Merge(topy(a), topy(b), C.int(override))
189190
return int2err(err)
190191
}
@@ -193,7 +194,7 @@ func PyDict_Merge(a, b *PyObject, override int) os.Error {
193194
// This is the same as PyDict_Merge(a, b, 1) in C, or a.update(b) in Python. Return 0 on success or -1 if an exception was raised.
194195
//
195196
// New in version 2.2.
196-
func PyDict_Update(a, b *PyObject) os.Error {
197+
func PyDict_Update(a, b *PyObject) error {
197198
err := C.PyDict_Update(topy(a), topy(b))
198199
return int2err(err)
199200
}
@@ -206,7 +207,7 @@ func PyDict_Update(a, b *PyObject) os.Error {
206207
// if override or key not in a:
207208
// a[key] = value
208209
// New in version 2.2.
209-
func PyDict_MergeFromSeq2(a, seq2 *PyObject, override int) os.Error {
210+
func PyDict_MergeFromSeq2(a, seq2 *PyObject, override int) error {
210211
err := C.PyDict_MergeFromSeq2(topy(a), topy(seq2), C.int(override))
211212
return int2err(err)
212213
}

pkg/python/exceptions.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int _gopy_PyErr_WarnPy3k(char *message, int stacklevel)
2020
*/
2121
import "C"
2222
import "unsafe"
23-
import "os"
23+
2424
//import "fmt"
2525

2626
// void PyErr_PrintEx(int set_sys_last_vars)
@@ -192,7 +192,6 @@ func PyErr_SetExcFromWindowsErrWithFilename(typ *PyObject, ierr bool, filename s
192192
return togo(C.PyErr_SetExcFromWindowsErrWithFilename(topy(typ), c_ierr, c_filename))
193193
}
194194

195-
196195
// void PyErr_BadInternalCall()
197196
// This is a shorthand for PyErr_SetString(PyExc_SystemError, message), where message indicates that an internal operation (e.g. a Python/C API function) was invoked with an illegal argument. It is mostly for internal use.
198197
func PyErr_BadInternalCall() {
@@ -207,7 +206,7 @@ func PyErr_BadInternalCall() {
207206
// Warning categories must be subclasses of Warning; the default warning category is RuntimeWarning. The standard Python warning categories are available as global variables whose names are PyExc_ followed by the Python exception name. These have the type PyObject*; they are all class objects. Their names are PyExc_Warning, PyExc_UserWarning, PyExc_UnicodeWarning, PyExc_DeprecationWarning, PyExc_SyntaxWarning, PyExc_RuntimeWarning, and PyExc_FutureWarning. PyExc_Warning is a subclass of PyExc_Exception; the other warning categories are subclasses of PyExc_Warning.
208207
//
209208
// For information about warning control, see the documentation for the warnings module and the -W option in the command line documentation. There is no C API for warning control.
210-
func PyErr_WarnEx(category *PyObject, message string, stacklevel int) os.Error {
209+
func PyErr_WarnEx(category *PyObject, message string, stacklevel int) error {
211210
c_message := C.CString(message)
212211
defer C.free(unsafe.Pointer(c_message))
213212

@@ -223,7 +222,7 @@ Deprecated; use PyErr_WarnEx() instead.
223222

224223
// int PyErr_WarnExplicit(PyObject *category, const char *message, const char *filename, int lineno, const char *module, PyObject *registry)
225224
// Issue a warning message with explicit control over all warning attributes. This is a straightforward wrapper around the Python function warnings.warn_explicit(), see there for more information. The module and registry arguments may be set to NULL to get the default effect described there.
226-
func PyErr_WarnExplicit(category *PyObject, message, filename string, lineno int, module string, registry *PyObject) os.Error {
225+
func PyErr_WarnExplicit(category *PyObject, message, filename string, lineno int, module string, registry *PyObject) error {
227226
c_message := C.CString(message)
228227
defer C.free(unsafe.Pointer(c_message))
229228

@@ -240,7 +239,7 @@ func PyErr_WarnExplicit(category *PyObject, message, filename string, lineno int
240239
// int PyErr_WarnPy3k(char *message, int stacklevel)
241240
// Issue a DeprecationWarning with the given message and stacklevel if the Py_Py3kWarningFlag flag is enabled.
242241
// New in version 2.6.
243-
func PyErr_WarnPy3k(message string, stacklevel int) os.Error {
242+
func PyErr_WarnPy3k(message string, stacklevel int) error {
244243
c_message := C.CString(message)
245244
defer C.free(unsafe.Pointer(c_message))
246245

pkg/python/object.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ type gopy_err struct {
6767
err string
6868
}
6969

70-
func (self *gopy_err) String() string {
70+
func (self *gopy_err) Error() string {
7171
return self.err
7272
}
7373

74-
func int2err(i C.int) os.Error {
74+
func int2err(i C.int) error {
7575
if i == 0 {
7676
return nil
7777
}
@@ -334,5 +334,4 @@ func (self *PyObject) Type() *PyObject {
334334
return togo(C.PyObject_Type(topy(self)))
335335
}
336336

337-
338337
// EOF

pkg/python/otherobjects.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ int _gopy_PyModule_CheckExact(PyObject *p) { return PyModule_CheckExact(p); }
3838
*/
3939
import "C"
4040
import "unsafe"
41-
import "os"
4241

4342
//github.com/// module //github.com///
4443

@@ -95,7 +94,7 @@ func PyModule_GetFilename(self *PyObject) string {
9594
// Add an object to module as name. This is a convenience function which can be used from the module’s initialization function. This steals a reference to value. Return -1 on error, 0 on success.
9695
//
9796
// New in version 2.0.
98-
func PyModule_AddObject(self *PyObject, name string, value *PyObject) os.Error {
97+
func PyModule_AddObject(self *PyObject, name string, value *PyObject) error {
9998
c_name := C.CString(name)
10099
defer C.free(unsafe.Pointer(c_name))
101100

@@ -106,7 +105,7 @@ func PyModule_AddObject(self *PyObject, name string, value *PyObject) os.Error {
106105
// Add an integer constant to module as name. This convenience function can be used from the module’s initialization function. Return -1 on error, 0 on success.
107106
//
108107
// New in version 2.0.
109-
func PyModule_AddIntConstant(self *PyObject, name string, value int) os.Error {
108+
func PyModule_AddIntConstant(self *PyObject, name string, value int) error {
110109
c_name := C.CString(name)
111110
defer C.free(unsafe.Pointer(c_name))
112111

@@ -117,7 +116,7 @@ func PyModule_AddIntConstant(self *PyObject, name string, value int) os.Error {
117116
// Add a string constant to module as name. This convenience function can be used from the module’s initialization function. The string value must be null-terminated. Return -1 on error, 0 on success.
118117
//
119118
// New in version 2.0.
120-
func PyModule_AddStringConstant(self *PyObject, name, value string) os.Error {
119+
func PyModule_AddStringConstant(self *PyObject, name, value string) error {
121120
c_name := C.CString(name)
122121
defer C.free(unsafe.Pointer(c_name))
123122

@@ -131,15 +130,15 @@ func PyModule_AddStringConstant(self *PyObject, name, value string) os.Error {
131130
// Add an int constant to module. The name and the value are taken from macro. For example PyModule_AddConstant(module, AF_INET) adds the int constant AF_INET with the value of AF_INET to module. Return -1 on error, 0 on success.
132131
//
133132
// New in version 2.6.
134-
func PyModule_AddIntMacro(self *PyObject, macro interface{}) os.Error {
133+
func PyModule_AddIntMacro(self *PyObject, macro interface{}) error {
135134
//FIXME ?
136135
panic("not implemented")
137136
}
138137

139138
// int PyModule_AddStringMacro(PyObject *module, macro)
140139
// Add a string constant to module.
141140
// New in version 2.6.
142-
func PyModule_AddStringMacro(self *PyObject, macro interface{}) os.Error {
141+
func PyModule_AddStringMacro(self *PyObject, macro interface{}) error {
143142
//FIXME ?
144143
panic("not implemented")
145144
}
@@ -230,7 +229,7 @@ func PyFunction_GetDefaults(op *PyObject) *PyObject {
230229
// Set the argument default values for the function object op. defaults must be Py_None or a tuple.
231230
//
232231
// Raises SystemError and returns -1 on failure.
233-
func PyFunction_SetDefaults(op, defaults *PyObject) os.Error {
232+
func PyFunction_SetDefaults(op, defaults *PyObject) error {
234233
return int2err(C.PyFunction_SetDefaults(topy(op), topy(defaults)))
235234
}
236235

@@ -245,7 +244,7 @@ func PyFunction_GetClosure(op *PyObject) *PyObject {
245244
// Set the closure associated with the function object op. closure must be Py_None or a tuple of cell objects.
246245
//
247246
// Raises SystemError and returns -1 on failure.
248-
func PyFunction_SetClosure(op, closure *PyObject) os.Error {
247+
func PyFunction_SetClosure(op, closure *PyObject) error {
249248
return int2err(C.PyFunction_SetClosure(topy(op), topy(closure)))
250249
}
251250

@@ -341,7 +340,7 @@ func PySlice_New(start, stop, step *PyObject) *PyObject {
341340
// You probably do not want to use this function. If you want to use slice objects in versions of Python prior to 2.3, you would probably do well to incorporate the source of PySlice_GetIndicesEx(), suitably renamed, in the source of your extension.
342341
//
343342
// Changed in version 2.5: This function used an int type for length and an int * type for start, stop, and step. This might require changes in your code for properly supporting 64-bit systems.
344-
func PySlice_GetIndices(slice *PySliceObject, length int) (start, stop, step int, err os.Error) {
343+
func PySlice_GetIndices(slice *PySliceObject, length int) (start, stop, step int, err error) {
345344
c_start := C.Py_ssize_t(0)
346345
c_stop := C.Py_ssize_t(0)
347346
c_step := C.Py_ssize_t(0)
@@ -364,7 +363,7 @@ func PySlice_GetIndices(slice *PySliceObject, length int) (start, stop, step int
364363
// New in version 2.3.
365364
//
366365
// Changed in version 2.5: This function used an int type for length and an int * type for start, stop, step, and slicelength. This might require changes in your code for properly supporting 64-bit systems.
367-
func PySlice_GetIndicesEx(slice *PySliceObject, length int) (start, stop, step, slicelength int, err os.Error) {
366+
func PySlice_GetIndicesEx(slice *PySliceObject, length int) (start, stop, step, slicelength int, err error) {
368367

369368
c_start := C.Py_ssize_t(0)
370369
c_stop := C.Py_ssize_t(0)
@@ -490,7 +489,7 @@ func PyCapsule_IsValid(capsule *PyObject, name string) bool {
490489
// Set the context pointer inside capsule to context.
491490
//
492491
// Return 0 on success. Return nonzero and set an exception on failure.
493-
func PyCapsule_SetContext(capsule *PyObject, context *C.char) os.Error {
492+
func PyCapsule_SetContext(capsule *PyObject, context *C.char) error {
494493
//FIXME use interface{} instead of *C.char ?
495494
return int2err(C.PyCapsule_SetContext(topy(capsule), unsafe.Pointer(context)))
496495
}
@@ -499,29 +498,27 @@ func PyCapsule_SetContext(capsule *PyObject, context *C.char) os.Error {
499498
// Set the destructor inside capsule to destructor.
500499
//
501500
// Return 0 on success. Return nonzero and set an exception on failure.
502-
func PyCapsule_SetDestructor(capsule *PyObject, dtor C.PyCapsule_Destructor) os.Error {
501+
func PyCapsule_SetDestructor(capsule *PyObject, dtor C.PyCapsule_Destructor) error {
503502
//FIXME use go-PyCapsule_Destructor instead of cgo one ?
504503
return int2err(C.PyCapsule_SetDestructor(topy(capsule), dtor))
505504
}
506505

507-
508506
// int PyCapsule_SetName(PyObject *capsule, const char *name)
509507
// Set the name inside capsule to name. If non-NULL, the name must outlive the capsule. If the previous name stored in the capsule was not NULL, no attempt is made to free it.
510508
//
511509
// Return 0 on success. Return nonzero and set an exception on failure.
512-
func PyCapsule_SetName(capsule *PyObject, name string) os.Error {
510+
func PyCapsule_SetName(capsule *PyObject, name string) error {
513511
c_name := C.CString(name)
514512
defer C.free(unsafe.Pointer(c_name))
515513

516514
return int2err(C.PyCapsule_SetName(topy(capsule), c_name))
517515
}
518516

519-
520517
// int PyCapsule_SetPointer(PyObject *capsule, void *pointer)
521518
// Set the void pointer inside capsule to pointer. The pointer may not be NULL.
522519
//
523520
// Return 0 on success. Return nonzero and set an exception on failure.
524-
func PyCapsule_SetPointer(capsule *PyObject, pointer *C.char) os.Error {
521+
func PyCapsule_SetPointer(capsule *PyObject, pointer *C.char) error {
525522
//FIXME use interface{} instead of *C.char ?
526523
return int2err(C.PyCapsule_SetPointer(topy(capsule), unsafe.Pointer(pointer)))
527524
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/4cecoder/go-python/commit/bf65570ba5f575e4f8e3a9058f60fd08dd960522

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy