<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bgola &#187; magic number</title>
	<atom:link href="http://blog.brunogola.com.br/tag/magic-number/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.brunogola.com.br</link>
	<description>python, free software, hacking, free culture, bicycle commuting, geocaching</description>
	<lastBuildDate>Wed, 08 Dec 2010 12:49:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PyPy 2.5-features &#8211; Yet another status update</title>
		<link>http://blog.brunogola.com.br/2008/07/pypy-25-features-yet-another-status-update/</link>
		<comments>http://blog.brunogola.com.br/2008/07/pypy-25-features-yet-another-status-update/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 03:27:29 +0000</pubDate>
		<dc:creator>Bruno Gola</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[pypy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[gsoc]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[magic number]]></category>
		<category><![CDATA[opcodes]]></category>
		<category><![CDATA[pyc]]></category>
		<category><![CDATA[pycode]]></category>
		<category><![CDATA[status update]]></category>

		<guid isPermaLink="false">http://blog.brunogola.com.br/?p=44</guid>
		<description><![CDATA[Here comes another GSoC status update Some finished tasks: throw() method on generators close() method&#8230; faking 2.5 behavior for IMPORT_NAME and IMPORT_FROM opcodes changing the default value for magic attribute of PyCode objects changing the magic number that goes in .pyc files compiled by PyPy fixing tests and more tests&#8230; From those changes the only [...]]]></description>
			<content:encoded><![CDATA[<p>Here comes another GSoC status update <img src='http://blog.brunogola.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Some finished tasks:</p>
<ul>
<li>throw() method on generators</li>
<li>close() method&#8230;</li>
<li>faking 2.5 behavior for IMPORT_NAME and IMPORT_FROM opcodes</li>
<li>changing the default value for <em>magic </em> attribute of PyCode objects</li>
<li>changing the magic number that goes in .pyc files compiled by PyPy</li>
<li>fixing tests and more tests&#8230;</li>
</ul>
<p>From those changes the only one I would like to comment is the change of both magic numbers. </p>
<p>First, they have different values and meanings in PyPy. The magic number for .pyc files (defined in <em>pypy/modules/__builtin__/importing.py</em>) is the number that identifies the bytecode &#8220;version&#8221;. It&#8217;s used to know if the interpreter should use the .pyc file or should recompile the .py. PyPy&#8217;s value is different from CPython&#8217;s one. As we are changing some opcodes (as IMPORT_NAME, mentioned before) this number had to be changed. The old value in PyPy was 1024 (or 1024 + 2 or 1024 + 4 or 1024 + 2 + 4, depending on some command line options), the new value is 1034 (or &#8230;.). We are just using the same policy CPython uses to change the value, add 10 to the old value.</p>
<p>Now the PyCode <em>magic</em> attribute. This value is the CPython magic number (the one explained above)., the old default value was the value from CPython 2.4 (62021). Some checks against this value are made through the code to decide if the bytecode should be interpreted one way or another. One example is the IMPORT_NAME opcode. In Python 2.4 IMPORT_NAME did not have the level parameter, this parameter is new in 2.5 because of the <em>absolute import</em> feature. So if the bytecode represented by a PyCode object is 2.4, when we visit a <em>import</em> statement we should not try to pop the level value from the stack (because it&#8217;s not there), but if it is 2.5 we should! So we check the magic value. The problem is, the default value was 2.4 but we changed the opcodes to behave like 2.5, so those checks were not working. The solution was to change the magic default value to 63231 (2.5c2 value I think), so now our bytecode interpreter is (almost?) compatible with 2.5 bytecode. And our compiler is generating 2.5 compatible bytecode as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.brunogola.com.br/2008/07/pypy-25-features-yet-another-status-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

