Skip to content

Commit 778850d

Browse files
committed
Make sure exception subclasses have TPFLAGS_BASE_EXC_SUBCLASS set for ExceptionClassCheck
1 parent 5aeba6f commit 778850d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

notes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Note byte code is from python 3.3!
22

3+
FIXME need to be able to tell classes an instances apart!
4+
35
Put C modules in sub directory
46
Make an all submodule so can insert all of them easily with
57

py/exception.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Exception struct {
1919

2020
var (
2121
// Exception heirachy
22-
BaseException = ObjectType.NewType("BaseException", "Common base class for all exceptions", ExceptionNew, nil)
22+
BaseException = ObjectType.NewTypeFlags("BaseException", "Common base class for all exceptions", ExceptionNew, nil, ObjectType.Flags|TPFLAGS_BASE_EXC_SUBCLASS)
2323
SystemExit = BaseException.NewType("SystemExit", "Request to exit from the interpreter.", nil, nil)
2424
KeyboardInterrupt = BaseException.NewType("KeyboardInterrupt", "Program interrupted by user.", nil, nil)
2525
GeneratorExit = BaseException.NewType("GeneratorExit", "Request that a generator exit.", nil, nil)
@@ -182,6 +182,9 @@ func MakeException(r interface{}) *Exception {
182182
// Checks that the object passed in is a class and is an exception
183183
func ExceptionClassCheck(err Object) bool {
184184
if t, ok := err.(*Type); ok {
185+
// FIXME not telling instances and classes apart
186+
// properly! This could be an instance of something
187+
// here
185188
return t.Flags&TPFLAGS_BASE_EXC_SUBCLASS != 0
186189
}
187190
return false

py/type.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func NewTypeX(Name string, Doc string, New NewFunc, Init InitFunc) *Type {
227227
// Make a subclass of a type
228228
//
229229
// For making Go types
230-
func (t *Type) NewType(Name string, Doc string, New NewFunc, Init InitFunc) *Type {
230+
func (t *Type) NewTypeFlags(Name string, Doc string, New NewFunc, Init InitFunc, Flags int) *Type {
231231
// inherit constructors
232232
if New == nil {
233233
New = t.New
@@ -242,12 +242,21 @@ func (t *Type) NewType(Name string, Doc string, New NewFunc, Init InitFunc) *Typ
242242
Doc: Doc,
243243
New: New,
244244
Init: Init,
245-
Flags: t.Flags, // FIXME not sure this is correct!
245+
Flags: Flags,
246246
}
247247
//tt.Ready()
248248
return tt
249249
}
250250

251+
// Make a subclass of a type
252+
//
253+
// For making Go types
254+
func (t *Type) NewType(Name string, Doc string, New NewFunc, Init InitFunc) *Type {
255+
// Inherit flags from superclass
256+
// FIXME not sure this is correct!
257+
return t.NewTypeFlags(Name, Doc, New, Init, t.Flags)
258+
}
259+
251260
// Determine the most derived metatype.
252261
func (metatype *Type) CalculateMetaclass(bases Tuple) *Type {
253262
// Determine the proper metatype to deal with this,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy