@@ -161,6 +161,17 @@ cpp_object_maker <- function(typeid, pointer){
161161 new( Class , .object_pointer = pointer )
162162}
163163
164+ # called by make_new_object() with the module class that the calling library
165+ # registered for this C++ type, since other libraries' unrelated classes of
166+ # the same name share its typeid; the object is created through that class's
167+ # generator, as new() would look the reference class up by name
168+ cpp_object_maker_by_class <- function (typeid , pointer , class_pointer ){
169+ Class <- .classes_by_pointer [[ externalptr_address(class_pointer ) ]]
170+ if ( is.null( Class ) )
171+ return ( cpp_object_maker( typeid , pointer ) )
172+ Class @ generator $ new( .object_pointer = pointer )
173+ }
174+
164175Module <- function ( module , PACKAGE = methods :: getPackageName(where ), where = topenv(parent.frame()), mustStart = FALSE ) {
165176 if (inherits(module , " DLLInfo" ) && missing(mustStart )) mustStart <- TRUE # #nocov
166177 if (inherits(module , " Module" )) {
@@ -287,6 +298,7 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
287298 # rather than rebuilding it (and all of its method/field objects)
288299 CLASS @ generator <- generators [[ clname ]]
289300 .classes_map [[ CLASS @ typeid ]] <- storage [[ demangled_name ]] <- CLASS
301+ .classes_by_pointer [[ externalptr_address( CLASS @ pointer ) ]] <- CLASS
290302
291303 # exposing enums values as CLASS.VALUE
292304 # (should really be CLASS$value but I don't know how to do it)
0 commit comments