pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


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

URL: http://github.com/jruby/jruby/pull/9253/files

" href="https://github.githubassets.com/assets/primer-primitives-10bf9dd67e3d70bd.css" /> Correctly initialize Data field accessors by headius · Pull Request #9253 · jruby/jruby · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions core/src/main/java/org/jruby/RubyClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ public static RubyClass newClass(Ruby runtime, RubyClass superClass, String name
return newClass(runtime.getCurrentContext(), superClass, name, allocator, parent, setParent, file, line);
}

@Deprecated
public static RubyClass newClass(ThreadContext context, RubyClass superClass, String name, ObjectAllocator allocator,
RubyModule parent, boolean setParent, String file, int line) {
assert superClass != null;
Expand All @@ -550,7 +551,6 @@ public static RubyClass newClass(ThreadContext context, RubyClass superClass, St
baseName(name);
clazz.makeMetaClass(context, superClass.getMetaClass());
if (setParent) clazz.setParent(parent);
clazz.copyVariableTableManagerForData(context, superClass);
parent.setConstant(context, name, clazz, file, line);
superClass.invokeInherited(context, superClass, clazz);
return clazz;
Expand Down Expand Up @@ -1073,7 +1073,7 @@ private RubyClass initializeCommon(ThreadContext context, RubyClass superClazz,
allocator = superClazz.allocator;
makeMetaClass(context, superClazz.getMetaClass());
superClazz.addSubclass(this);
copyVariableTableManagerForData(context, superClazz);
copyVariableTableManager(superClazz);

marshal = superClazz.marshal;

Expand All @@ -1083,11 +1083,14 @@ private RubyClass initializeCommon(ThreadContext context, RubyClass superClazz,
return this;
}

private void copyVariableTableManagerForData(ThreadContext context, RubyClass superClazz) {
private void copyVariableTableManager(RubyClass superClazz) {
if (superClazz == runtime.getObject()) {
// don't copy variables from Object since it will accumulate random variables
return;
}
VariableTableManager variableTableManager = superClazz.getVariableTableManager();
if (variableTableManager.getRealClass().superClass() == context.runtime.getData()) {
// duplicate data's variable table in subclasses
this.variableTableManager = variableTableManager.duplicateForData(this);
if (!variableTableManager.getVariableAccessorsForRead().isEmpty()) {
this.variableTableManager = variableTableManager.duplicateFor(this);
}
}

Expand Down
27 changes: 13 additions & 14 deletions core/src/main/java/org/jruby/RubyData.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static void initialize(ThreadContext context, IRubyObject self, IRubyObje
String keyString = toSymbol(context, k).idString();
VariableAccessor variableAccessor = variableAccessors.get(keyString);
if (variableAccessor != null) {
selfObj.setInternalVariable(keyString, v);
variableAccessor.set(self, v);
} else {
RubyArray unknownKeywords = unknownKeywordsPtr[0];
if (unknownKeywords == null) {
Expand Down Expand Up @@ -402,13 +402,6 @@ private static RubyClass newDataStruct(ThreadContext context, RubyClass superCla

RubyClass subclass = RubyClass.newClass(runtime, superClass);

VariableTableManager vtm = subclass.getVariableTableManager();
VariableAccessor[] accessors = new VariableAccessor[keySet.size()];
int i = 0;
for (RubySymbol sym : keySet) {
accessors[i++] = vtm.getVariableAccessorForWrite(sym.idString());
}

ObjectAllocator allocator =
runtime.getObjectSpecializer()
.specializeForVariables(
Expand All @@ -417,6 +410,18 @@ private static RubyClass newDataStruct(ThreadContext context, RubyClass superCla

subclass.allocator(allocator);

VariableTableManager vtm = subclass.getVariableTableManager();
VariableAccessor[] accessors = new VariableAccessor[keySet.size()];
int i = 0;
for (RubySymbol sym : keySet) {
VariableAccessor accessor = vtm.getVariableAccessorForWrite(sym.idString());

accessors[i++] = accessor;

// TODO: AttrReader expects to potentially see many variable tables; this could be simplified
subclass.addMethod(context, sym.idString(), new AttrReaderMethod(subclass, Visibility.PUBLIC, accessor));
}

RubyArray members = newArray(context, keySet);
members.freeze(context);
subclass.setInternalVariable(MEMBERS_KEY, members);
Expand All @@ -427,12 +432,6 @@ private static RubyClass newDataStruct(ThreadContext context, RubyClass superCla
dataSClass.undefMethods(context, "define")
.defineMethods(context, DataMethods.class);

for (RubySymbol sym : keySet) {
VariableAccessor accessor = vtm.getVariableAccessorForWrite(sym.idString());
// TODO: AttrReader expects to potentially see many variable tables; this could be simplified
subclass.addMethod(context, sym.idString(), new AttrReaderMethod(subclass, Visibility.PUBLIC, accessor));
}

return subclass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public Object clearVariable(RubyBasicObject object, String name) {
}
}

public VariableTableManager duplicateForData(RubyClass newRealClass) {
public VariableTableManager duplicateFor(RubyClass newRealClass) {
return new VariableTableManager(this, newRealClass);
}

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

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