2009-07-24 08:35:21 +00:00
|
|
|
#ifndef _PYC_MODULE_H
|
|
|
|
#define _PYC_MODULE_H
|
|
|
|
|
2011-10-23 17:48:10 -07:00
|
|
|
#include "pyc_code.h"
|
2009-07-24 08:35:21 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
enum PycMagic {
|
|
|
|
MAGIC_1_0 = 0x00999902,
|
|
|
|
MAGIC_1_1 = 0x00999903, /* Also covers 1.2 */
|
|
|
|
MAGIC_1_3 = 0x0A0D2E89,
|
|
|
|
MAGIC_1_4 = 0x0A0D1704,
|
|
|
|
MAGIC_1_5 = 0x0A0D4E99,
|
|
|
|
MAGIC_1_6 = 0x0A0DC4FC,
|
|
|
|
|
|
|
|
MAGIC_2_0 = 0x0A0DC687,
|
|
|
|
MAGIC_2_1 = 0x0A0DEB2A,
|
|
|
|
MAGIC_2_2 = 0x0A0DED2D,
|
|
|
|
MAGIC_2_3 = 0x0A0DF23B,
|
|
|
|
MAGIC_2_4 = 0x0A0DF26D,
|
|
|
|
MAGIC_2_5 = 0x0A0DF2B3,
|
|
|
|
MAGIC_2_6 = 0x0A0DF2D1,
|
2010-08-31 23:17:38 -07:00
|
|
|
MAGIC_2_7 = 0x0A0DF303,
|
2009-07-24 08:35:21 +00:00
|
|
|
|
|
|
|
MAGIC_3_0 = 0x0A0D0C3A,
|
|
|
|
MAGIC_3_1 = 0x0A0D0C4E,
|
2011-01-06 17:15:48 -08:00
|
|
|
MAGIC_3_2 = 0x0A0D0C6C,
|
2012-06-27 18:03:55 -07:00
|
|
|
MAGIC_3_3 = 0x0A0D0C9E,
|
2014-12-13 10:42:30 -05:00
|
|
|
MAGIC_3_4 = 0x0A0D0CEE,
|
2015-10-01 16:06:09 -07:00
|
|
|
MAGIC_3_5 = 0x0A0D0D16,
|
2016-11-08 16:00:44 -08:00
|
|
|
MAGIC_3_6 = 0x0A0D0D32,
|
2009-07-24 08:35:21 +00:00
|
|
|
};
|
|
|
|
|
2010-09-04 01:20:41 -07:00
|
|
|
#define PYC_VERSION(maj, min) MAGIC_##maj##_##min
|
|
|
|
|
2009-07-24 08:35:21 +00:00
|
|
|
class PycModule {
|
|
|
|
public:
|
2014-01-20 22:21:56 -08:00
|
|
|
PycModule() : m_maj(-1), m_min(-1), m_unicode(false) { }
|
2009-07-24 08:35:21 +00:00
|
|
|
|
|
|
|
void loadFromFile(const char* filename);
|
|
|
|
bool isValid() const { return (m_maj >= 0) && (m_min >= 0); }
|
|
|
|
|
|
|
|
unsigned int majorVer() const { return m_maj; }
|
|
|
|
unsigned int minorVer() const { return m_min; }
|
2012-05-26 13:50:23 -07:00
|
|
|
|
|
|
|
int verCompare(int maj, int min) const
|
|
|
|
{
|
|
|
|
if (m_maj == maj)
|
|
|
|
return m_min - min;
|
|
|
|
return m_maj - maj;
|
|
|
|
}
|
|
|
|
|
2009-07-24 08:35:21 +00:00
|
|
|
bool isUnicode() const { return m_unicode; }
|
|
|
|
|
|
|
|
PycRef<PycCode> code() const { return m_code; }
|
|
|
|
|
|
|
|
void intern(PycRef<PycString> str) { m_interns.push_back(str); }
|
2014-01-21 00:07:34 -08:00
|
|
|
PycRef<PycString> getIntern(int ref) const;
|
|
|
|
|
|
|
|
void refObject(PycRef<PycObject> str) { m_refs.push_back(str); }
|
|
|
|
PycRef<PycObject> getRef(int ref) const;
|
2009-07-24 08:35:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setVersion(unsigned int magic);
|
|
|
|
|
|
|
|
private:
|
|
|
|
short m_maj, m_min;
|
|
|
|
bool m_unicode;
|
|
|
|
|
|
|
|
PycRef<PycCode> m_code;
|
|
|
|
std::list<PycRef<PycString> > m_interns;
|
2014-01-21 00:07:34 -08:00
|
|
|
std::list<PycRef<PycObject> > m_refs;
|
2009-07-24 08:35:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|