From zeal_goswami at yahoo.com Sun Jan 27 07:35:51 2013 From: zeal_goswami at yahoo.com (abhishek goswami) Date: Sun, 27 Jan 2013 14:35:51 +0800 (SGT) Subject: [capi-sig] Fw: 32 bit to 64 bit migration of C-API(Python) In-Reply-To: <1359265342.72980.YahooMailNeo@web193002.mail.sg3.yahoo.com> References: <1359265342.72980.YahooMailNeo@web193002.mail.sg3.yahoo.com> Message-ID: <1359268551.49315.YahooMailNeo@web193003.mail.sg3.yahoo.com> Hi, I am working in Python-C ApI (Integrated Project). The Project has migrated to 64 bit machine from 32 bit machine. Every thing was working fine in 32 bit machine. But we getting following error in 64 bit machine. " Python int too large to convert to C long". When I start debug the code and found that we are using long variable which has size of 8 bit in C code. If I ?replace long to int32_t variable in C and all long value become garbage and I got index out of error from Python.The reason to become garbage value of long(after int conversion),we are using lot of Place Python api which give the long result and we use in further process like ( write/reading file).I have tried to replace with int but it did not work. I am not sure really this is only reason but it may be one of the reason to get the above error.I have also done google search but not able to get exact reason. After spending 3 days,I am not able to figure out the solution of this issue. Does anyone provide some insight. we are using Python 2.7.2 and Gcc : 4.7.0 Please let me know if I need to provide more info. Your earlier response will help us lot as we need to fix this issue as soon as possible.( it is kind of blockage for us) Thanks Abhishek Goswami Bangalore Phone No -07829580867 Skype : abhishekgoswami1 From mal at egenix.com Mon Jan 28 10:36:52 2013 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 28 Jan 2013 10:36:52 +0100 Subject: [capi-sig] Fw: 32 bit to 64 bit migration of C-API(Python) In-Reply-To: <1359268551.49315.YahooMailNeo@web193003.mail.sg3.yahoo.com> References: <1359265342.72980.YahooMailNeo@web193002.mail.sg3.yahoo.com> <1359268551.49315.YahooMailNeo@web193003.mail.sg3.yahoo.com> Message-ID: <510646B4.1060208@egenix.com> On 27.01.2013 07:35, abhishek goswami wrote: > Hi, > > I am working in Python-C ApI (Integrated Project). The Project has migrated to 64 bit machine from 32 bit machine. Every thing was working fine in 32 bit machine. > But we getting following error in 64 bit machine. > " Python int too large to convert to C long". I suppose you're on Windows. Windows longs are still 32-bit, even on 64-bit platforms, so it's possible that you see overflow errors such as the above when dealing with large integers. You should be getting the same errors on your 32-bit builds, though, so it's probably a good idea to check why you are not seeing them there. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 28 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From zeal_goswami at yahoo.com Mon Jan 28 12:18:57 2013 From: zeal_goswami at yahoo.com (abhishek goswami) Date: Mon, 28 Jan 2013 19:18:57 +0800 (SGT) Subject: [capi-sig] Fw: 32 bit to 64 bit migration of C-API(Python) In-Reply-To: <510646B4.1060208@egenix.com> References: <1359265342.72980.YahooMailNeo@web193002.mail.sg3.yahoo.com> <1359268551.49315.YahooMailNeo@web193003.mail.sg3.yahoo.com> <510646B4.1060208@egenix.com> Message-ID: <1359371937.35085.YahooMailNeo@web193004.mail.sg3.yahoo.com> No,I am on linux machine ? Thanks Abhishek Goswami Bangalore Phone No -07829580867/9962270999 Skype : abhishekgoswami1 ________________________________ From: M.-A. Lemburg To: abhishek goswami Cc: "capi-sig at python.org" Sent: Monday, 28 January 2013 3:06 PM Subject: Re: [capi-sig] Fw: 32 bit to 64 bit migration of C-API(Python) On 27.01.2013 07:35, abhishek goswami wrote: > Hi, > > I am working in Python-C ApI (Integrated Project). The Project has migrated to 64 bit machine from 32 bit machine. Every thing was working fine in 32 bit machine. > But we getting following error in 64 bit machine. > " Python int too large to convert to C long". I suppose you're on Windows. Windows longs are still 32-bit, even on 64-bit platforms, so it's possible that you see overflow errors such as the above when dealing with large integers. You should be getting the same errors on your 32-bit builds, though, so it's probably a good idea to check why you are not seeing them there. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source? (#1, Jan 28 2013) >>> Python Projects, Consulting and Support ...? http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ...? ? ? http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...? ? ? ? http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: ? eGenix.com Software, Skills and Services GmbH? Pastor-Loeh-Str.48 ? ? D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg ? ? ? ? ? Registered at Amtsgericht Duesseldorf: HRB 46611 ? ? ? ? ? ? ? http://www.egenix.com/company/contact/ From hniksic at xemacs.org Mon Jan 28 19:28:14 2013 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 28 Jan 2013 19:28:14 +0100 Subject: [capi-sig] Fw: 32 bit to 64 bit migration of C-API(Python) In-Reply-To: <1359268551.49315.YahooMailNeo@web193003.mail.sg3.yahoo.com> (abhishek goswami's message of "Sun, 27 Jan 2013 14:35:51 +0800 (SGT)") References: <1359265342.72980.YahooMailNeo@web193002.mail.sg3.yahoo.com> <1359268551.49315.YahooMailNeo@web193003.mail.sg3.yahoo.com> Message-ID: <87pq0pi2m9.fsf@xemacs.org> abhishek goswami writes: > I am working in Python-C ApI (Integrated Project). The Project has > migrated to 64 bit machine from 32 bit machine. Every thing was > working fine in 32 bit machine. > But we getting following error in 64 bit machine. > " Python int too large to convert to C long". > > > When I start debug the code and found that we are using long variable > which has size of 8 bit in C code. If I ?replace long to int32_t > variable in C and all long value > become garbage[...] I find it hard to follow your debugging efforts from this point. It is clear that you are getting the error in 64-bit builds. The next thing one would do is try to figure out where the error comes from. After all, the overflow exception is hardly magic, it is raised in exactly one place in Python source code, the PyLong_AsLong function, in the case when the Python integer is too large to fit in a C long. Changing the type from long to int32_t and other things you are trying will not fix the bug. Your problem is the number that is too large to fit in a long in the first place -- find where it's coming from and fix it. For example, you can examine the stack trace and see which Python integer of value outside [2**63, 2**63) is attempted to be converted to long. If your project calls PyLong_AsLong, annotate all calls to that function with prints that show the repr of the value passed. Formats like "%d" are also suspicious. If all else fails, rebuild Python with -g and put a breakpoint on the line of PyLong_AsLong that handles the overflow.