Skip to content

Commit

Permalink
add pygcccxml patch for gcc-14
Browse files Browse the repository at this point in the history
  • Loading branch information
carsten-forty2 committed Oct 8, 2024
1 parent c8219f7 commit d1774b1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 7 deletions.
8 changes: 7 additions & 1 deletion core/python/generate_pygimli_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@
import logging

from pygccxml import utils

# patch for >gcc-14
import patch_pygccxml

logger = utils.loggers.cxx_parser
#logger.setLevel(logging.DEBUG)

from pygccxml import declarations
from pygccxml.declarations import access_type_matcher_t

from pyplusplus import code_creators, module_builder, messages, decl_wrappers
from pyplusplus.module_builder import call_policies
from pyplusplus.decl_wrappers.doc_extractor import doc_extractor_i
Expand All @@ -48,6 +53,7 @@

MAIN_NAMESPACE = 'GIMLI'


def samefile(sourcefile, destfile):
"""
"""
Expand Down Expand Up @@ -261,7 +267,7 @@ def generate(defined_symbols, extraIncludes):
indexing_suite_version=2,
xml_generator_config=xml_generator_config
)

logger.info("Reading of c++ sources done.")

mb.classes().always_expose_using_scope = True
Expand Down
66 changes: 66 additions & 0 deletions core/python/patch_pygccxml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import pygccxml

from pygccxml.parser import project_reader_t

# for gcc-14 this is needed
def __patch_relink_declarated_types__(self, leaved_classes, declarated_types):
mangled_leaved_classes = {}
for leaved_class in leaved_classes.values():
mangled_leaved_classes[
self._create_name_key(leaved_class)] = leaved_class

for decl_wrapper_type in declarated_types:
# it is possible, that cache contains reference to dropped class
# We need to clear it
decl_wrapper_type.cache.reset()
if isinstance(
decl_wrapper_type.declaration,
pygccxml.declarations.class_t):
key = self._create_key(decl_wrapper_type.declaration)
if key in leaved_classes:
decl_wrapper_type.declaration = leaved_classes[key]
else:

name = decl_wrapper_type.declaration._name
if name == "":
# Happens with gcc5, castxml + std=c++11
# See issue #45
continue
if name.startswith("__vmi_class_type_info_pseudo"):
continue
if name == "rebind<std::__tree_node" + \
"<std::basic_string<char>, void *> >":
continue

########## patch on
print('+'*80)
print('key',key)
print('_'*80)
print('name', name)
print('-'*80)
continue
########## patch off

msg = []
msg.append(
"Unable to find out actual class definition: '%s'." %
decl_wrapper_type.declaration._name)
msg.append((
"Class definition has been changed from one " +
"compilation to an other."))
msg.append((
"Why did it happen to me? Here is a short list " +
"of reasons: "))
msg.append((
" 1. There are different preprocessor " +
"definitions applied on same file during compilation"))
msg.append(" 2. Bug in pygccxml.")
raise Exception(os.linesep.join(msg))
elif isinstance(
decl_wrapper_type.declaration,
pygccxml.declarations.class_declaration_t):
key = self._create_name_key(decl_wrapper_type.declaration)
if key in mangled_leaved_classes:
decl_wrapper_type.declaration = mangled_leaved_classes[key]

project_reader_t._relink_declarated_types = __patch_relink_declarated_types__
10 changes: 6 additions & 4 deletions core/src/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ template< class ValueType > class DLLEXPORT Vector {
}
/*!
* Return a new vector that based on indices's.
* Throws exception if indices's are out of bound.
* Throws exception if indices's are out of bound.
*/
inline Vector < ValueType > operator () (const SIndexArray & siArray) const {
return get_(siArray);
Expand Down Expand Up @@ -594,7 +594,7 @@ template< class ValueType > class DLLEXPORT Vector {
if (end < 0){
e = max(start, size_ + end);
}

Vector < ValueType > v(e-start);

if (start == e) return v;
Expand Down Expand Up @@ -721,8 +721,10 @@ DEFINE_UNARY_MOD_OPERATOR__(*, MULT)
if (newCapacity != capacity_) {
ValueType * buffer = new ValueType[newCapacity];

std::memcpy(buffer, data_, sizeof(ValueType) * min(capacity_, newCapacity));
if (data_) delete [] data_;
std::memcpy(buffer, data_,
sizeof(ValueType) * min(capacity_, newCapacity));
// std::destroy_at(data_);
if (data_) delete [] data_;
data_ = buffer;
capacity_ = newCapacity;
//std::copy(&tmp[0], &tmp[min(tmp.size(), n)], data_);
Expand Down
4 changes: 2 additions & 2 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ setuptools
numpy>=1.25
matplotlib
pyqt5 #pyqtagg backend
pyplusplus==1.8.4
pygccxml==2.0.0
pyplusplus==1.8.5
pygccxml==2.5.0

# needed to run
matplotlib>=3.7,<3.9
Expand Down

0 comments on commit d1774b1

Please sign in to comment.