Skip to content

Commit 900753b

Browse files
author
Boxiang Sun
committed
Rename pure None to pyston_None, and use Py_None as much as possible. …
When try to support tk. The Py_None is a wrapper of pyston `None`. It will conflict with other library's None. So rename the pure pyston `None` to pyston_None. And use Py_None instead pyston_None when possible. Just like dropbox#1231 for Py_True and Py_False
1 parent c1488b5 commit 900753b

37 files changed

+230
-226
lines changed

from_cpython/Include/object.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,9 @@ where NULL (nil) is not suitable (since NULL often means 'error').
902902
903903
Don't forget to apply Py_INCREF() when returning this value!!!
904904
*/
905-
// Pyston change: replaced Py_None with just None
906-
PyAPI_DATA(PyObject*) None;
907-
#define Py_None None
905+
// Pyston change: replaced _Py_NoneStruct with pyston_None
906+
PyAPI_DATA(PyObject*) pyston_None;
907+
#define Py_None pyston_None
908908
//PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
909909
//#define Py_None (&_Py_NoneStruct)
910910

src/capi/modsupport.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static PyObject* va_build_value(const char* fmt, va_list va, int flags) noexcept
372372
return NULL;
373373

374374
if (n == 0)
375-
return incref(None);
375+
return incref(Py_None);
376376

377377
va_list lva;
378378
__va_copy(lva, va);
@@ -482,8 +482,8 @@ extern "C" int PyModule_AddIntConstant(PyObject* _m, const char* name, long valu
482482
extern "C" PyObject* PyModule_New(const char* name) noexcept {
483483
BoxedModule* module = new BoxedModule();
484484
module->giveAttr("__name__", boxString(name));
485-
module->giveAttr("__doc__", incref(None));
486-
module->giveAttr("__package__", incref(None));
485+
module->giveAttr("__doc__", incref(Py_None));
486+
module->giveAttr("__package__", incref(Py_None));
487487
return module;
488488
}
489489

src/capi/typeobject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ template Box* slotTpGetattrHookInternal<CXX, NOT_REWRITABLE>(Box* self, BoxedStr
11371137
static BoxedString* _new_str = getStaticString("__new__");
11381138
Box* new_attr = typeLookup(self, _new_str);
11391139
assert(new_attr);
1140-
new_attr = processDescriptor(new_attr, None, self);
1140+
new_attr = processDescriptor(new_attr, Py_None, self);
11411141
AUTO_DECREF(new_attr);
11421142

11431143
return runtimeCall(new_attr, ArgPassSpec(1, 0, true, true), self, args, kwds, NULL, NULL);
@@ -2184,7 +2184,7 @@ void add_operators(BoxedClass* cls) noexcept {
21842184
continue;
21852185

21862186
if (*ptr == PyObject_HashNotImplemented) {
2187-
cls->setattr(static_cast<BoxedString*>(p.name_strobj), None, NULL);
2187+
cls->setattr(static_cast<BoxedString*>(p.name_strobj), Py_None, NULL);
21882188
} else {
21892189
auto descr = PyDescr_NewWrapper(cls, &p, *ptr);
21902190
assert(descr);
@@ -3614,7 +3614,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
36143614
if (cls->tp_doc) {
36153615
cls->giveAttr(incref(doc_str), boxString(cls->tp_doc));
36163616
} else {
3617-
cls->giveAttr(incref(doc_str), incref(None));
3617+
cls->giveAttr(incref(doc_str), incref(Py_None));
36183618
}
36193619
}
36203620

src/capi/types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ class BoxedCApiFunction : public Box {
5959
const char* s = static_cast<BoxedCApiFunction*>(b)->method_def->ml_name;
6060
if (s)
6161
return boxString(s);
62-
return incref(None);
62+
return incref(Py_None);
6363
}
6464

6565
static Box* doc(Box* b, void*) noexcept {
6666
RELEASE_ASSERT(b->cls == capifunc_cls, "");
6767
const char* s = static_cast<BoxedCApiFunction*>(b)->method_def->ml_doc;
6868
if (s)
6969
return boxString(s);
70-
return incref(None);
70+
return incref(Py_None);
7171
}
7272

7373
static void dealloc(Box* _o) noexcept {

src/codegen/ast_interpreter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,9 @@ void ASTInterpreter::doStore(AST_expr* node, STOLEN(Value) value) {
605605
Value ASTInterpreter::getNone() {
606606
RewriterVar* v = NULL;
607607
if (jit) {
608-
v = jit->imm(None)->setType(RefType::BORROWED);
608+
v = jit->imm(Py_None)->setType(RefType::BORROWED);
609609
}
610-
return Value(incref(None), v);
610+
return Value(incref(Py_None), v);
611611
}
612612

613613
Value ASTInterpreter::visit_unaryop(AST_UnaryOp* node) {
@@ -783,7 +783,7 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) {
783783
// TODO: maybe use a different placeholder (=NULL)?
784784
// - new issue with that -- we can no longer distinguish NULL from unset-in-sorted_symbol_table
785785
// Currently we pass None because the LLVM jit will decref this value even though it may not be set.
786-
static Box* const VAL_UNDEFINED = (Box*)None;
786+
static Box* const VAL_UNDEFINED = (Box*)Py_None;
787787

788788
const VRegSet& defined = phis->definedness.getDefinedVregsAtEnd(current_block);
789789
for (int vreg : defined) {
@@ -1915,8 +1915,8 @@ Box* ASTInterpreterJitInterface::landingpadHelper(void* _interpreter) {
19151915
ASTInterpreter* interpreter = (ASTInterpreter*)_interpreter;
19161916
ExcInfo& last_exception = interpreter->last_exception;
19171917
Box* type = last_exception.type;
1918-
Box* value = last_exception.value ? last_exception.value : None;
1919-
Box* traceback = last_exception.traceback ? last_exception.traceback : None;
1918+
Box* value = last_exception.value ? last_exception.value : Py_None;
1919+
Box* traceback = last_exception.traceback ? last_exception.traceback : Py_None;
19201920
Box* rtn = BoxedTuple::create({ type, value, traceback });
19211921
Py_CLEAR(last_exception.type);
19221922
Py_CLEAR(last_exception.value);
@@ -2080,7 +2080,7 @@ Box* astInterpretFunction(FunctionMetadata* md, Box* closure, Box* generator, Bo
20802080

20812081
interpreter.initArguments((BoxedClosure*)closure, (BoxedGenerator*)generator, arg1, arg2, arg3, args);
20822082
Box* v = ASTInterpreter::execute(interpreter);
2083-
return v ? v : incref(None);
2083+
return v ? v : incref(Py_None);
20842084
}
20852085

20862086
Box* astInterpretFunctionEval(FunctionMetadata* md, Box* globals, Box* boxedLocals) {
@@ -2113,7 +2113,7 @@ Box* astInterpretFunctionEval(FunctionMetadata* md, Box* globals, Box* boxedLoca
21132113
interpreter.setGlobals(globals);
21142114

21152115
Box* v = ASTInterpreter::execute(interpreter);
2116-
return v ? v : incref(None);
2116+
return v ? v : incref(Py_None);
21172117
}
21182118

21192119
// caution when changing the function arguments: this function gets called from an assembler wrapper!
@@ -2220,7 +2220,7 @@ extern "C" Box* astInterpretDeoptFromASM(FunctionMetadata* md, AST_expr* after_e
22202220
Py_CLEAR(frame_state.locals);
22212221

22222222
Box* v = ASTInterpreter::execute(interpreter, start_block, starting_statement);
2223-
return v ? v : incref(None);
2223+
return v ? v : incref(Py_None);
22242224
}
22252225

22262226
extern "C" void printExprHelper(Box* obj) {

src/codegen/baseline_jit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ RewriterVar* JitFragmentWriter::emitGetClsAttr(RewriterVar* obj, BoxedString* s)
404404

405405
RewriterVar* JitFragmentWriter::emitGetGlobal(BoxedString* s) {
406406
if (s->s() == "None") {
407-
RewriterVar* r = imm(None)->setType(RefType::BORROWED);
407+
RewriterVar* r = imm(Py_None)->setType(RefType::BORROWED);
408408
return r;
409409
}
410410

src/codegen/compvars.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ class NormalObjectType : public ConcreteCompilerType {
21362136
}
21372137

21382138
CompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override {
2139-
if (cls == None->cls)
2139+
if (cls == Py_None->cls)
21402140
return makeBool(false);
21412141

21422142
static BoxedString* attr = getStaticString("__nonzero__");

src/codegen/irgen/hooks.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Box* SourceInfo::getDocString() {
142142
return boxString(static_cast<AST_Str*>(static_cast<AST_Expr*>(body[0])->value)->str_data);
143143
}
144144

145-
return incref(None);
145+
return incref(Py_None);
146146
}
147147

148148
ScopeInfo* SourceInfo::getScopeInfo() {
@@ -344,7 +344,7 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
344344

345345
UNAVOIDABLE_STAT_TIMER(t0, "us_timer_interpreted_module_toplevel");
346346
Box* r = astInterpretFunction(md, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
347-
assert(r == None);
347+
assert(r == Py_None);
348348
Py_DECREF(r);
349349

350350
// XXX for bjit testing
@@ -359,7 +359,7 @@ Box* evalOrExec(FunctionMetadata* md, Box* globals, Box* boxedLocals) {
359359
assert(globals && (globals->cls == module_cls || globals->cls == dict_cls));
360360

361361
Box* doc_string = md->source->getDocString();
362-
if (doc_string != None) {
362+
if (doc_string != Py_None) {
363363
static BoxedString* doc_box = getStaticString("__doc__");
364364
setGlobal(boxedLocals, doc_box, doc_string);
365365
} else {
@@ -478,10 +478,10 @@ extern "C" int PyEval_MergeCompilerFlags(PyCompilerFlags* cf) noexcept {
478478
}
479479

480480
static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
481-
if (globals == None)
481+
if (globals == Py_None)
482482
globals = NULL;
483483

484-
if (locals == None)
484+
if (locals == Py_None)
485485
locals = NULL;
486486

487487
if (locals == NULL) {
@@ -535,9 +535,9 @@ extern "C" PyObject* PyEval_EvalCode(PyCodeObject* co, PyObject* globals, PyObje
535535

536536
void exec(Box* boxedCode, Box* globals, Box* locals, FutureFlags caller_future_flags) {
537537
if (!globals)
538-
globals = None;
538+
globals = Py_None;
539539
if (!locals)
540-
locals = None;
540+
locals = Py_None;
541541

542542
// this is based on cpythons exec_statement() but (heavily) adopted
543543
Box* v = NULL;
@@ -628,7 +628,7 @@ void exec(Box* boxedCode, Box* globals, Box* locals, FutureFlags caller_future_f
628628
if (!v)
629629
throwCAPIException();
630630

631-
assert(v == None); // not really necessary but I think this should be true
631+
assert(v == Py_None); // not really necessary but I think this should be true
632632
Py_DECREF(v);
633633
}
634634

src/codegen/irgen/irgenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ class IREmitterImpl : public IREmitter {
745745
}
746746

747747
ConcreteCompilerVariable* getNone() override {
748-
llvm::Constant* none = embedRelocatablePtr(None, g.llvm_value_type_ptr, "cNone");
748+
llvm::Constant* none = embedRelocatablePtr(Py_None, g.llvm_value_type_ptr, "cNone");
749749
setType(none, RefType::BORROWED);
750750
return new ConcreteCompilerVariable(typeFromClass(none_cls), none);
751751
}

src/codegen/unwinding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ ExcInfo* getFrameExcInfo() {
750750

751751
if (!copy_from_exc->type) {
752752
// No exceptions found:
753-
*copy_from_exc = ExcInfo(incref(None), incref(None), NULL);
753+
*copy_from_exc = ExcInfo(incref(Py_None), incref(Py_None), NULL);
754754
}
755755

756756
for (auto* ex : to_update) {

0 commit comments

Comments
 (0)