9 Commits e63540ea54 ... f87bdab51c

Author SHA1 Message Date
  Michael Buesch f87bdab51c awlsim-win wrapper: Add Cython option 5 years ago
  Michael Buesch f19632dc4a Add no_cython to MANIFEST 5 years ago
  Michael Buesch 1f168fc8c7 Add endianness helpers for Win build 5 years ago
  Michael Buesch ca6f0e7157 cython: Fix patching on Windows 5 years ago
  Michael Buesch 79544d1ce4 Add Windows build script 5 years ago
  Michael Buesch ae34b073d5 coreserver: Avoid usage of posix select on non-posix platform 5 years ago
  Michael Buesch 487c1ff84d cython: Add posix/win annotations 5 years ago
  Michael Buesch 83559f153b win: Copy all html and examples to the frozen archive 5 years ago
  Michael Buesch c6b6ac6b75 Bump version 5 years ago

+ 2 - 0
DEVELOPMENT.md

@@ -19,6 +19,8 @@ In order to support both compiling the Awlsim core with Cython and running the s
 * `#@cy` : Enable (un-comment) this line during Cython patching.
 * `#@cy2` : Enable (un-comment) this line during Cython patching, if compiling for Python 2.
 * `#@cy3` : Enable (un-comment) this line during Cython patching, if compiling for Python 3.
+* `#@cy-posix` : Enable (un-comment) this line during Cython patching, if compiling for a Posix platform.
+* `#@cy-win` : Enable (un-comment) this line during Cython patching, if compiling for a Windows platform.
 * `#@nocy` : Disable (comment) this line during Cython patching.
 * `#@no-cython-patch` : Do not touch this line during cython patching.
 * `#+NoneToNULL` : Transform all `None` keywords in this line into `NULL`.

+ 1 - 0
MANIFEST.in

@@ -1,5 +1,6 @@
 global-include *.pxd.in
 global-include *.pyx.in
+global-include no_cython
 
 graft awlsim/gui/icons/icon-images
 graft debian

+ 11 - 0
awlsim-win.cmd

@@ -1,5 +1,7 @@
 @echo off
 setlocal ENABLEDELAYEDEXPANSION
+set basedir=%~dp0
+set awlsim_base=%basedir%
 
 set PYPROG=awlsim-gui
 for /D %%f in ( "progs\putty\*" ) do set PATH=%%f\putty;!PATH!
@@ -10,6 +12,15 @@ for /D %%f in ( "C:\PYTHON*" ) do set PATH=!PATH!;%%f
 for /D %%f in ( "%USERPROFILE%\AppData\Local\Programs\Python\Python*" ) do set PATH=!PATH!;%%f;%%f\Scripts
 
 
+rem Set Cython paths
+if not exist %awlsim_base%\build goto no_cython
+for /D %%f in ( "%awlsim_base%\build\lib.*-*-3.*" ) do set PYTHONPATH=%%f\;!PYTHONPATH!
+set PYTHONPATH=.;%PYTHONPATH%
+set AWLSIM_CYTHON=1
+echo PYTHONPATH=%PYTHONPATH%
+:no_cython
+
+
 py -h >NUL 2>&1
 if %ERRORLEVEL% EQU 0 goto exec_py
 

+ 4 - 2
awlsim/common/datatypehelpers.pxd.in

@@ -22,7 +22,8 @@
 from awlsim.common.cython_support cimport *
 
 
-cdef extern from "<endian.h>":
+cdef extern from "<endian.h>":		#@cy-posix
+cdef extern from "endian-win.h":	#@cy-win
 	enum: BYTE_ORDER
 	enum: LITTLE_ENDIAN
 	enum: BIG_ENDIAN
@@ -37,7 +38,8 @@ cdef extern from "<endian.h>":
 	uint32_t be32toh(uint32_t)
 	uint32_t le32toh(uint32_t)
 
-cdef extern from "<byteswap.h>":
+cdef extern from "<byteswap.h>":	#@cy-posix
+cdef extern from "byteswap-win.h":	#@cy-win
 	uint16_t bswap_16(uint16_t)
 	uint32_t bswap_32(uint32_t)
 

+ 2 - 2
awlsim/common/version.py

@@ -15,9 +15,9 @@ __all__ = [
 
 
 VERSION_MAJOR	= 0
-VERSION_MINOR	= 67
+VERSION_MINOR	= 68
 VERSION_BUGFIX	= 0
-VERSION_EXTRA	= ""
+VERSION_EXTRA	= "-pre"
 
 
 

+ 5 - 5
awlsim/coreserver/server.pxd.in

@@ -1,7 +1,7 @@
 from awlsim.common.cython_support cimport *
 from awlsim.core.main cimport *
 
-from posix.select cimport fd_set
+#from posix.select cimport fd_set	#@cy-posix
 
 
 cdef class AwlSimServer(object):
@@ -24,13 +24,13 @@ cdef class AwlSimServer(object):
 	cdef public _Bool __projectWriteBack
 
 	cdef public object __socket
-	cdef public int __socketFileno
+#	cdef public int __socketFileno	#@cy-posix
 	cdef public object __unixSockPath
 	cdef public dict __sock2client
 	cdef public list __clients
 	cdef public list __selectRlist
-	cdef fd_set __select_fdset
-	cdef int __select_fdset_size
+#	cdef fd_set __select_fdset	#@cy-posix
+#	cdef int __select_fdset_size	#@cy-posix
 
 	cdef public object awlSourceContainer
 	cdef public object fupSourceContainer
@@ -43,4 +43,4 @@ cdef class AwlSimServer(object):
 
 	cdef __handleClientComm(self, client)
 	cdef __handleSocketComm(self, list sockList)
-	cdef __handleCommunication(self)
+#	cdef __handleCommunicationPosix(self) #@cy-posix

+ 71 - 67
awlsim/coreserver/server.py

@@ -53,8 +53,8 @@ import errno
 import time
 import multiprocessing
 
-#from posix.select cimport FD_ZERO, FD_SET, FD_ISSET, select #@cy
-#from posix.time cimport timeval #@cy
+#from posix.select cimport FD_ZERO, FD_SET, FD_ISSET, select #@cy-posix
+#from posix.time cimport timeval #@cy-posix
 
 
 class AwlSimClientInfo(object):
@@ -63,7 +63,7 @@ class AwlSimClientInfo(object):
 	def __init__(self, sock, peerInfoString):
 		# Socket
 		self.socket = sock
-		self.fileno = self.socket.fileno()
+#		self.fileno = self.socket.fileno() #@cy-posix
 		self.transceiver = AwlSimMessageTransceiver(sock, peerInfoString)
 
 		# Broken-flag. Set, if connection breaks.
@@ -243,7 +243,7 @@ class AwlSimServer(object): #+cdef
 		self.__haveAnyMemReadReq = False
 
 		self.__socket = None
-		self.__socketFileno = -1
+#		self.__socketFileno = -1 #@cy-posix
 		self.__unixSockPath = None
 		self.__clients = []
 		self.__sock2client = {}
@@ -396,14 +396,14 @@ class AwlSimServer(object): #+cdef
 		rlist.extend(client.transceiver.sock for client in self.__clients)
 		self.__selectRlist = rlist
 
-#@cy		FD_ZERO(&self.__select_fdset)
-#@cy		FD_SET(self.__socketFileno, &self.__select_fdset)
-#@cy		self.__select_fdset_size = self.__socketFileno
-#@cy		for client in self.__clients:
-#@cy			FD_SET(client.fileno, &self.__select_fdset)
-#@cy			self.__select_fdset_size = max(self.__select_fdset_size,
-#@cy						       client.fileno)
-#@cy		self.__select_fdset_size += 1
+#		FD_ZERO(&self.__select_fdset)						#@cy-posix
+#		FD_SET(self.__socketFileno, &self.__select_fdset)			#@cy-posix
+#		self.__select_fdset_size = self.__socketFileno				#@cy-posix
+#		for client in self.__clients:						#@cy-posix
+#			FD_SET(client.fileno, &self.__select_fdset)			#@cy-posix
+#			self.__select_fdset_size = max(self.__select_fdset_size,	#@cy-posix
+#						       client.fileno)			#@cy-posix
+#		self.__select_fdset_size += 1						#@cy-posix
 
 	def __sendCpuDump(self, constrained=True):
 		dumpText = self.__sim.cpu.dump(withTime=self.__running)
@@ -1031,58 +1031,61 @@ class AwlSimServer(object): #+cdef
 		raise AwlSimError("AwlSimServer: Communication error. "
 				  "'select' failed")
 
-	def __handleCommunication(self, __select=select_mod.select, __Exception=Exception):	#@nocy
-		try:										#@nocy
-			rlist, wlist, xlist = __select(self.__selectRlist,			#@nocy
-						       self.__emptyList,			#@nocy
-						       self.__emptyList, 0.0)			#@nocy
-			if not rlist:								#@nocy
-				return								#@nocy
-		except __Exception:								#@nocy
-			self.__selectException()						#@nocy
-		self.__handleSocketComm(rlist)							#@nocy
-												#@nocy
-		# Check again to receive more data (with a small timeout).			#@nocy
-		while True:									#@nocy
-			try:									#@nocy
-				rlist, wlist, xlist = __select(self.__selectRlist,		#@nocy
-							       self.__emptyList,		#@nocy
-							       self.__emptyList, 0.01)		#@nocy
-				if not rlist:							#@nocy
-					return							#@nocy
-			except __Exception:							#@nocy
-				self.__selectException()					#@nocy
-			self.__handleSocketComm(rlist)						#@nocy
-
-#@cy	cdef __handleCommunication(self):
-#@cy		cdef fd_set rfds
-#@cy		cdef int ret
-#@cy		cdef timeval timeout
-#@cy		cdef list rlist
-#@cy
-#@cy		timeout.tv_sec = 0
-#@cy		timeout.tv_usec = 0
-#@cy		while True:
-#@cy			rfds = self.__select_fdset
-#@cy			ret = select(self.__select_fdset_size,
-#@cy				     &rfds, NULL, NULL,
-#@cy				     &timeout)
-#@cy			if likely(ret == 0):
-#@cy				return
-#@cy			if ret < 0:
-#@cy				self.__selectException()
-#@cy				return
-#@cy			rlist = [ client.socket
-#@cy				for client in self.__clients
-#@cy				if FD_ISSET(client.fileno, &rfds)
-#@cy			]
-#@cy			if FD_ISSET(self.__socketFileno, &rfds):
-#@cy				rlist.append(self.__socket)
-#@cy			self.__handleSocketComm(rlist)
-#@cy
-#@cy			# Check again to receive more data (with a small timeout).
-#@cy			timeout.tv_sec = 0
-#@cy			timeout.tv_usec = 10000
+	def __handleCommunication(self, __select=select_mod.select, __Exception=Exception):
+		try:
+			rlist, wlist, xlist = __select(self.__selectRlist,
+						       self.__emptyList,
+						       self.__emptyList, 0.0)
+			if not rlist:
+				return
+		except __Exception:
+			self.__selectException()
+		self.__handleSocketComm(rlist)
+
+		# Check again to receive more data (with a small timeout).
+		while True:
+			try:
+				rlist, wlist, xlist = __select(self.__selectRlist,
+							       self.__emptyList,
+							       self.__emptyList, 0.01)
+				if not rlist:
+					return
+			except __Exception:
+				self.__selectException()
+			self.__handleSocketComm(rlist)
+
+	# Optimized version of __handleCommunication()
+	# that calls posix select directly.
+#	cdef __handleCommunicationPosix(self):				#@cy-posix
+#		cdef fd_set rfds					#@cy-posix
+#		cdef int ret						#@cy-posix
+#		cdef timeval timeout					#@cy-posix
+#		cdef list rlist						#@cy-posix
+#									#@cy-posix
+#		timeout.tv_sec = 0					#@cy-posix
+#		timeout.tv_usec = 0					#@cy-posix
+#		while True:						#@cy-posix
+#			rfds = self.__select_fdset			#@cy-posix
+#			ret = select(self.__select_fdset_size,		#@cy-posix
+#				     &rfds, NULL, NULL,			#@cy-posix
+#				     &timeout)				#@cy-posix
+#			if likely(ret == 0):				#@cy-posix
+#				return					#@cy-posix
+#			if ret < 0:					#@cy-posix
+#				self.__selectException()		#@cy-posix
+#				return					#@cy-posix
+#			rlist = [ client.socket				#@cy-posix
+#				for client in self.__clients		#@cy-posix
+#				if FD_ISSET(client.fileno, &rfds)	#@cy-posix
+#			]						#@cy-posix
+#			if FD_ISSET(self.__socketFileno, &rfds):	#@cy-posix
+#				rlist.append(self.__socket)		#@cy-posix
+#			self.__handleSocketComm(rlist)			#@cy-posix
+#									#@cy-posix
+#			# Check again to receive more data		#@cy-posix
+#			# (with a small timeout).			#@cy-posix
+#			timeout.tv_sec = 0				#@cy-posix
+#			timeout.tv_usec = 10000				#@cy-posix
 
 	def __handleCommunicationBlocking(self):
 		try:
@@ -1257,7 +1260,8 @@ class AwlSimServer(object): #+cdef
 						sim.runCycle()
 						if self.__haveAnyMemReadReq:
 							self.__handleMemReadReqs()
-						self.__handleCommunication()
+						self.__handleCommunication()		#@cy-win
+#						self.__handleCommunicationPosix()	#@cy-posix
 					continue
 
 			except (AwlSimError, AwlParserError) as e:
@@ -1352,7 +1356,7 @@ class AwlSimServer(object): #+cdef
 				with suppressAllExc:
 					sock.close()
 		self.__socket = sock
-		self.__socketFileno = sock.fileno()
+#		self.__socketFileno = sock.fileno() #@cy-posix
 
 	def __accept(self):
 		"""Accept a client connection.
@@ -1414,7 +1418,7 @@ class AwlSimServer(object): #+cdef
 			with suppressAllExc:
 				self.__socket.close()
 			self.__socket = None
-			self.__socketFileno = -1
+#			self.__socketFileno = -1 #@cy-posix
 		if self.__unixSockPath:
 			with contextlib.suppress(OSError):
 				os.unlink(self.__unixSockPath)

+ 2 - 2
debian/changelog

@@ -1,5 +1,5 @@
-awlsim (0.67.0) UNRELEASED; urgency=low
+awlsim (0.68.0) UNRELEASED; urgency=low
 
-  * Version 0.67.0
+  * Version 0.68.0
 
  -- Michael Buesch <m@bues.ch>  Mon, 01 Feb 2016 00:00:00 +0100

+ 19 - 0
libs/cython_headers/byteswap-win.h

@@ -0,0 +1,19 @@
+#ifndef BYTESWAP_WIN_H_
+#define BYTESWAP_WIN_H_
+
+#include <stdint.h>
+
+static inline uint16_t bswap_16(uint16_t v)
+{
+	return (v << 8) | (v >> 8);
+}
+
+static inline uint32_t bswap_32(uint32_t v)
+{
+	return ((v << 24) & 0xFF000000u) |
+	       ((v << 8)  & 0x00FF0000u) |
+	       ((v >> 8)  & 0x0000FF00u) |
+	       ((v >> 24) & 0x000000FFu);
+}
+
+#endif /* BYTESWAP_WIN_H_ */

+ 0 - 0
libs/cython_headers/endian-win.h


Some files were not shown because too many files changed in this diff