@@ -18,6 +18,11 @@ using std::string;
1818
1919#include < libnormaliz/libnormaliz.h>
2020
21+ #ifdef ENFNORMALIZ
22+ using eantic::renf_elem_class;
23+ using eantic::renf_class;
24+ #endif
25+
2126using libnormaliz::Cone;
2227// using libnormaliz::ConeProperty;
2328using libnormaliz::ConeProperties;
@@ -468,11 +473,10 @@ static bool prepare_nf_input(vector< vector< NumberFieldElem > >& out,
468473 if (!current_res) {
469474 return false ;
470475 }
471- current_elem = NumberFieldElem (*nf, current_vector);
476+ current_elem = renf_elem_class (nf-> shared_from_this (), current_vector);
472477 }
473478 if (string_check (current_element)) {
474- current_elem = NumberFieldElem (*nf);
475- current_elem = PyUnicodeToString (current_element);
479+ current_elem =renf_elem_class (nf->shared_from_this (),PyUnicodeToString (current_element));
476480 }
477481 if (PyFloat_Check (current_element)){
478482 throw PyNormalizInputException (" Nonintegral numbers must be given as strings" );
@@ -742,7 +746,7 @@ NmzAutomorphismsToPython(const AutomorphismGroup< Integer >& grp)
742746
743747#ifdef ENFNORMALIZ
744748struct NumberFieldCone {
745- renf_class* nf;
749+ const renf_class* nf;
746750 Cone< renf_elem_class >* cone;
747751};
748752#endif
@@ -791,31 +795,31 @@ static Cone< renf_elem_class >* get_cone_renf(PyObject* cone)
791795 return cone_ptr->cone ;
792796}
793797
794- static renf_class* get_cone_renf_renf (PyObject* cone)
798+ static const renf_class* get_cone_renf_renf (PyObject* cone)
795799{
796800 NumberFieldCone* cone_ptr = reinterpret_cast < NumberFieldCone* >(
797801 PyCapsule_GetPointer (cone, cone_name_renf));
798802 return cone_ptr->nf ;
799803}
800804#endif
801805
802- static PyObject* pack_cone (Cone< mpz_class >* C, void * dummy = nullptr )
806+ static PyObject* pack_cone (Cone< mpz_class >* C, const void * dummy = nullptr )
803807{
804808 return PyCapsule_New (reinterpret_cast < void * >(C), cone_name,
805809 &delete_cone_mpz);
806810}
807811
808- static PyObject* pack_cone (Cone< long long >* C, void * dummy = nullptr )
812+ static PyObject* pack_cone (Cone< long long >* C, const void * dummy = nullptr )
809813{
810814 return PyCapsule_New (reinterpret_cast < void * >(C), cone_name_long,
811815 &delete_cone_long);
812816}
813817
814818#ifdef ENFNORMALIZ
815- static PyObject* pack_cone (Cone< renf_elem_class >* C, void * nf)
819+ static PyObject* pack_cone (Cone< renf_elem_class >* C, const void * nf)
816820{
817821 NumberFieldCone* cone_ptr = new NumberFieldCone ();
818- cone_ptr->nf = reinterpret_cast < renf_class* >(nf);
822+ cone_ptr->nf = reinterpret_cast < const renf_class* >(nf);
819823 cone_ptr->cone = C;
820824 return PyCapsule_New (reinterpret_cast < void * >(cone_ptr), cone_name_renf,
821825 &delete_cone_renf);
@@ -1008,13 +1012,14 @@ static PyObject* _NmzConeIntern_renf(PyObject* kwargs)
10081012 }
10091013
10101014
1011- renf_class* renf;
10121015 // number_field_data contains 3 entries: poly, var, emb
10131016 // All are strings
10141017 string poly = PyUnicodeToString (PySequence_GetItem (number_field_data, 0 ));
10151018 string var = PyUnicodeToString (PySequence_GetItem (number_field_data, 1 ));
10161019 string emb = PyUnicodeToString (PySequence_GetItem (number_field_data, 2 ));
1017- renf = new renf_class (poly.c_str (), var.c_str (), emb.c_str ());
1020+ // std::shared_ptr<const renf_class>* renf = new std::shared_ptr<const renf_class>;
1021+ std::shared_ptr<const renf_class> renf = renf_class::make (poly, var, emb);
1022+ const renf_class* my_renf = renf.get ();
10181023
10191024 map< InputType, vector< vector< renf_elem_class > > > input;
10201025
@@ -1036,7 +1041,7 @@ static PyObject* _NmzConeIntern_renf(PyObject* kwargs)
10361041 continue ;
10371042 vector< vector< renf_elem_class > > Mat;
10381043 try {
1039- prepare_nf_input (Mat, current_value, renf );
1044+ prepare_nf_input (Mat, current_value, my_renf );
10401045 }
10411046 catch (PyNormalizInputException& e) {
10421047 PyErr_SetString (PyNormaliz_cppError,
@@ -1050,9 +1055,9 @@ static PyObject* _NmzConeIntern_renf(PyObject* kwargs)
10501055 }
10511056
10521057 Cone< renf_elem_class >* C = new Cone< renf_elem_class >(input);
1053- C->setRenf (renf );
1054-
1055- PyObject* return_container = pack_cone (C, renf );
1058+ C->setRenf (my_renf );
1059+
1060+ PyObject* return_container = pack_cone (C, my_renf );
10561061
10571062 return return_container;
10581063 FUNC_END
@@ -1320,7 +1325,7 @@ PyObject* _NmzModify(Cone<Integer>* cone, PyObject* args)
13201325}
13211326
13221327#ifdef ENFNORMALIZ
1323- PyObject* _NmzModify_Renf (Cone<renf_elem_class>* cone, renf_class* nf, PyObject* args)
1328+ PyObject* _NmzModify_Renf (Cone<renf_elem_class>* cone, const renf_class* nf, PyObject* args)
13241329{
13251330 string property = PyUnicodeToString ( PyTuple_GetItem (args, 1 ) );
13261331 PyObject* matrix_py = PyTuple_GetItem (args,2 );
@@ -1359,7 +1364,7 @@ PyObject* _NmzModify_Outer(PyObject* self, PyObject* args)
13591364#ifdef ENFNORMALIZ
13601365 else if (is_cone_renf (cone)) {
13611366 Cone< renf_elem_class >* cone_ptr = get_cone_renf (cone);
1362- renf_class* nf = get_cone_renf_renf (cone);
1367+ const renf_class* nf = get_cone_renf_renf (cone);
13631368 return _NmzModify_Renf (cone_ptr, nf, args);
13641369 }
13651370#endif
@@ -1591,7 +1596,7 @@ second is the projection third is the annihilator.
15911596
15921597template < typename Integer >
15931598static PyObject*
1594- _NmzResultImpl (Cone< Integer >* C, PyObject* prop_obj, void * nf = nullptr )
1599+ _NmzResultImpl (Cone< Integer >* C, PyObject* prop_obj, const void * nf = nullptr )
15951600{
15961601
15971602 string prop = PyUnicodeToString (prop_obj);
@@ -1840,7 +1845,7 @@ MatrixHandler = NULL;
18401845 Cone< renf_elem_class >* cone_ptr = get_cone_renf (cone);
18411846 result = _NmzResultImpl (
18421847 cone_ptr, prop,
1843- reinterpret_cast < void * >(get_cone_renf_renf (cone)));
1848+ reinterpret_cast < const void * >(get_cone_renf_renf (cone)));
18441849 }
18451850#endif
18461851
@@ -2420,9 +2425,9 @@ static PyObject* NmzGetRenfInfo(PyObject* self, PyObject* args)
24202425 );
24212426 return NULL ;
24222427 }
2423- renf_class* renf = get_cone_renf_renf (cone_py);
2428+ const renf_class* renf = get_cone_renf_renf (cone_py);
24242429 std::string minpoly_str;
2425- minpoly_str = fmpq_poly_get_str_pretty (renf->get_renf ()->nf ->pol , renf->gen_name .c_str ());
2430+ minpoly_str = fmpq_poly_get_str_pretty (renf->get_renf ()->nf ->pol , renf->gen_name () .c_str ());
24262431 std::string res1 = arb_get_str (renf->get_renf ()->emb , 64 , 0 );
24272432 // long prec = renf->get_renf()->prec;
24282433 return PyTuple_Pack (2 , StringToPyUnicode (minpoly_str), StringToPyUnicode (res1));
0 commit comments